Search in sources :

Example 1 with Hit

use of org.neo4j.index.internal.gbptree.Hit in project neo4j by neo4j.

the class NativeLabelScanReader method nodesWithLabel.

@Override
public PrimitiveLongIterator nodesWithLabel(int labelId) {
    RawCursor<Hit<LabelScanKey, LabelScanValue>, IOException> cursor;
    try {
        ensureOpenCursorsClosed();
        cursor = seekerForLabel(labelId);
        openCursors.offer(cursor);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return new LabelScanValueIterator(cursor);
}
Also used : Hit(org.neo4j.index.internal.gbptree.Hit) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 2 with Hit

use of org.neo4j.index.internal.gbptree.Hit in project neo4j by neo4j.

the class NativeLabelScanReader method iteratorsForLabels.

private List<PrimitiveLongIterator> iteratorsForLabels(int[] labelIds) {
    List<PrimitiveLongIterator> iterators = new ArrayList<>();
    try {
        ensureOpenCursorsClosed();
        for (int labelId : labelIds) {
            RawCursor<Hit<LabelScanKey, LabelScanValue>, IOException> cursor = seekerForLabel(labelId);
            openCursors.offer(cursor);
            iterators.add(new LabelScanValueIterator(cursor));
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return iterators;
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Hit(org.neo4j.index.internal.gbptree.Hit) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 3 with Hit

use of org.neo4j.index.internal.gbptree.Hit in project neo4j by neo4j.

the class NativeLabelScanReaderTest method shouldFindMultipleNodesInEachRange.

@SuppressWarnings("unchecked")
@Test
public void shouldFindMultipleNodesInEachRange() throws Exception {
    // GIVEN
    GBPTree<LabelScanKey, LabelScanValue> index = mock(GBPTree.class);
    RawCursor<Hit<LabelScanKey, LabelScanValue>, IOException> cursor = mock(RawCursor.class);
    when(cursor.next()).thenReturn(true, true, true, false);
    when(cursor.get()).thenReturn(// range, bits
    hit(0, 0b1000_1000__1100_0010L), hit(1, 0b0000_0010__0000_1000L), hit(3, 0b0010_0000__1010_0001L), null);
    when(index.seek(any(LabelScanKey.class), any(LabelScanKey.class))).thenReturn(cursor);
    try (NativeLabelScanReader reader = new NativeLabelScanReader(index)) {
        // WHEN
        PrimitiveLongIterator iterator = reader.nodesWithLabel(LABEL_ID);
        // THEN
        assertArrayEquals(new long[] { // base 0*64 = 0
        1, 6, 7, 11, 15, // base 1*64 = 64
        64 + 3, 64 + 9, // base 3*64 = 192
        192 + 0, 192 + 5, 192 + 7, 192 + 13 }, asArray(iterator));
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Hit(org.neo4j.index.internal.gbptree.Hit) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)3 Hit (org.neo4j.index.internal.gbptree.Hit)3 UncheckedIOException (java.io.UncheckedIOException)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1