use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class StorageLayerLabelTest method should_return_all_nodes_with_label.
@Test
public void should_return_all_nodes_with_label() throws Exception {
// GIVEN
Node node1 = createLabeledNode(db, map("name", "First", "age", 1L), label1);
Node node2 = createLabeledNode(db, map("type", "Node", "count", 10), label1, label2);
int labelId1 = disk.labelGetForName(label1.name());
int labelId2 = disk.labelGetForName(label2.name());
// WHEN
PrimitiveLongIterator nodesForLabel1 = disk.nodesGetForLabel(state.getStoreStatement(), labelId1);
PrimitiveLongIterator nodesForLabel2 = disk.nodesGetForLabel(state.getStoreStatement(), labelId2);
// THEN
assertEquals(asSet(node1.getId(), node2.getId()), PrimitiveLongCollections.toSet(nodesForLabel1));
assertEquals(asSet(node2.getId()), PrimitiveLongCollections.toSet(nodesForLabel2));
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class LabelScanViewNodeStoreScanTest method iterateOverLabeledNodeIds.
@Test
public void iterateOverLabeledNodeIds() throws Exception {
PrimitiveLongIterator labeledNodes = PrimitiveLongCollections.iterator(1, 2, 4, 8);
when(nodeStore.getHighId()).thenReturn(15L);
when(labelScanReader.nodesWithAnyOfLabels(1, 2)).thenReturn(labeledNodes);
int[] labelIds = new int[] { 1, 2 };
LabelScanViewNodeStoreScan<Exception> storeScan = getLabelScanViewStoreScan(labelIds);
PrimitiveLongResourceIterator idIterator = storeScan.getNodeIdIterator();
List<Long> visitedNodeIds = PrimitiveLongCollections.asList(idIterator);
assertThat(visitedNodeIds, Matchers.hasSize(4));
assertThat(visitedNodeIds, Matchers.hasItems(1L, 2L, 4L, 8L));
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class FullTxData method internalQuery.
private Collection<EntityId> internalQuery(Query query, QueryContext contextOrNull) {
if (this.directory == null) {
return Collections.emptySet();
}
try {
Sort sorting = contextOrNull != null ? contextOrNull.getSorting() : null;
boolean prioritizeCorrectness = contextOrNull == null || !contextOrNull.getTradeCorrectnessForSpeed();
IndexSearcher theSearcher = searcher(prioritizeCorrectness);
query = includeOrphans(query);
DocValuesCollector docValuesCollector = new DocValuesCollector(prioritizeCorrectness);
theSearcher.search(query, docValuesCollector);
Collection<EntityId> result = new ArrayList<>();
PrimitiveLongIterator valuesIterator = docValuesCollector.getSortedValuesIterator(KEY_DOC_ID, sorting);
while (valuesIterator.hasNext()) {
result.add(new EntityId.IdData(valuesIterator.next()));
}
return result;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class RecordIdIteratorTest method assertIds.
private void assertIds(RecordIdIterator ids, long[]... expectedIds) {
for (long[] expectedArray : expectedIds) {
PrimitiveLongIterator iterator = ids.nextBatch();
assertNotNull(iterator);
for (long expectedId : expectedArray) {
assertEquals(expectedId, iterator.next());
}
assertFalse(iterator.hasNext());
}
assertNull(ids.nextBatch());
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j-apoc-procedures by neo4j-contrib.
the class PregelTest method runPageRank.
@Test
public void runPageRank() throws Exception {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.pagecache_memory, "100M").newGraphDatabase();
int nodeCount = 100_001;
int[] degrees = new int[nodeCount];
createRankTestData(db, nodeCount, degrees);
long start = System.currentTimeMillis();
Pregel pregel = new Pregel(db, guard).withBatchSize(10000);
PrimitiveLongIterator nodes;
try (Transaction tx = db.beginTx()) {
ReadOperations reads = pregel.statement().readOperations();
nodes = reads.nodesGetAll();
tx.success();
}
float[] ranks = pregel.runProgram2(nodes, new Pregel.AllExpander(), new PageRankProgram(nodeCount, degrees, new float[nodeCount], new LinkedList<>()));
long time = System.currentTimeMillis() - start;
Arrays.sort(ranks);
// System.err.println("PageRank Program ran for "+nodeCount+" nodes in "+time+" ms. 10 hightest Ranks "+Arrays.toString(Arrays.copyOfRange(ranks,ranks.length-10,ranks.length)));
db.shutdown();
}
Aggregations