use of org.neo4j.index.internal.gbptree.Seeker in project neo4j by neo4j.
the class GenericNativeIndexAccessor method newAllEntriesValueReader.
@Override
public IndexEntriesReader[] newAllEntriesValueReader(int partitions, CursorContext cursorContext) {
GenericKey lowest = layout.newKey();
lowest.initialize(Long.MIN_VALUE);
lowest.initValuesAsLowest();
GenericKey highest = layout.newKey();
highest.initialize(Long.MAX_VALUE);
highest.initValuesAsHighest();
try {
Collection<Seeker<GenericKey, NativeIndexValue>> seekers = tree.partitionedSeek(lowest, highest, partitions, cursorContext);
Collection<IndexEntriesReader> readers = new ArrayList<>();
for (Seeker<GenericKey, NativeIndexValue> seeker : seekers) {
readers.add(new IndexEntriesReader() {
@Override
public long next() {
return seeker.key().getEntityId();
}
@Override
public boolean hasNext() {
try {
return seeker.next();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
@Override
public Value[] values() {
return seeker.key().asValues();
}
@Override
public void close() {
try {
seeker.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
}
return readers.toArray(IndexEntriesReader[]::new);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.neo4j.index.internal.gbptree.Seeker in project neo4j by neo4j.
the class CombinedPartSeekerTest method shouldCombineAllParts.
@Test
void shouldCombineAllParts() throws IOException {
// given
SimpleLongLayout layout = longLayout().withFixedSize(true).build();
List<Seeker<MutableLong, MutableLong>> parts = new ArrayList<>();
int partCount = random.nextInt(1, 20);
List<Pair<MutableLong, MutableLong>> expectedAllData = new ArrayList<>();
int maxKey = random.nextInt(100, 10_000);
for (int i = 0; i < partCount; i++) {
int dataSize = random.nextInt(0, 100);
List<Pair<MutableLong, MutableLong>> partData = new ArrayList<>(dataSize);
for (int j = 0; j < dataSize; j++) {
long key = random.nextLong(maxKey);
partData.add(Pair.of(new MutableLong(key), new MutableLong(key * 2)));
}
partData.sort(HIT_COMPARATOR);
parts.add(new SimpleSeeker(partData));
expectedAllData.addAll(partData);
}
expectedAllData.sort(HIT_COMPARATOR);
// when
CombinedPartSeeker<MutableLong, MutableLong> combinedSeeker = new CombinedPartSeeker<>(layout, parts);
// then
for (Pair<MutableLong, MutableLong> expectedHit : expectedAllData) {
assertTrue(combinedSeeker.next());
assertEquals(expectedHit.getKey().longValue(), combinedSeeker.key().longValue());
assertEquals(expectedHit.getValue().longValue(), combinedSeeker.value().longValue());
}
assertFalse(combinedSeeker.next());
// And just ensure it will return false again after that
assertFalse(combinedSeeker.next());
}
Aggregations