-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test lucene FixedBitSet - Experiment #4384
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.opentripplanner.transit.raptor.util; | ||
|
||
import org.apache.lucene.search.DocIdSetIterator; | ||
import org.apache.lucene.util.BitSet; | ||
import org.opentripplanner.transit.raptor.api.transit.IntIterator; | ||
|
||
/** | ||
* TODO TGR | ||
*/ | ||
public final class LuceneBitSetIterator implements IntIterator { | ||
|
||
private final BitSet set; | ||
private int nextIndex; | ||
|
||
public LuceneBitSetIterator(BitSet set) { | ||
this.set = set; | ||
this.nextIndex = set.nextSetBit(nextIndex); | ||
} | ||
|
||
@Override | ||
public int next() { | ||
int index = nextIndex; | ||
nextIndex = | ||
index == set.length() - 1 ? DocIdSetIterator.NO_MORE_DOCS : set.nextSetBit(index + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check the performance with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to be better than
|
||
return index; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return nextIndex != DocIdSetIterator.NO_MORE_DOCS; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.opentripplanner.transit.raptor.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.apache.lucene.util.BitSet; | ||
import org.apache.lucene.util.FixedBitSet; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class LuceneBitSetIteratorTest { | ||
|
||
@Test | ||
public void test() { | ||
LuceneBitSetIterator it; | ||
BitSet set = new FixedBitSet(6); | ||
|
||
// Empty set does not have any elements | ||
it = new LuceneBitSetIterator(set); | ||
assertFalse(it.hasNext()); | ||
|
||
set.set(2); | ||
it = new LuceneBitSetIterator(set); | ||
assertTrue(it.hasNext()); | ||
assertEquals(2, it.next()); | ||
assertFalse(it.hasNext()); | ||
|
||
// set: [0, 2, 5], 2 is added above | ||
set.set(0); | ||
set.set(5); | ||
it = new LuceneBitSetIterator(set); | ||
assertTrue(it.hasNext()); | ||
assertEquals(0, it.next()); | ||
assertTrue(it.hasNext()); | ||
assertEquals(2, it.next()); | ||
assertTrue(it.hasNext()); | ||
assertEquals(5, it.next()); | ||
assertFalse(it.hasNext()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is slow, but should not have a huge impact. We can look for the first bit set or keep a flag in the BestTimes to improve this.