use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j-apoc-procedures by neo4j-contrib.
the class WeaklyConnectedComponents method wcc.
@Deprecated
@Procedure("apoc.algo.wcc")
@Description("CALL apoc.algo.wcc() YIELD number of weakly connected components")
public Stream<CCResult> wcc() {
List<List<CCVar>> results = new LinkedList<List<CCVar>>();
ResourceIterator<Node> nodes = db.getAllNodes().iterator();
PrimitiveLongSet allNodes = Primitive.longSet(0);
while (nodes.hasNext()) {
Node node = nodes.next();
if (node.getDegree() == 0) {
List<CCVar> result = new LinkedList<CCVar>();
result.add(new CCVar(node.getId() + "", node.getLabels().iterator().next().name()));
results.add(result);
} else {
allNodes.add(node.getId());
}
}
nodes.close();
PrimitiveLongIterator it = allNodes.iterator();
while (it.hasNext()) {
try {
long n = it.next();
List<CCVar> result = new LinkedList<CCVar>();
PrimitiveLongIterator reachableIDs = go(db.getNodeById(n), Direction.BOTH, result).iterator();
while (reachableIDs.hasNext()) {
long id = (long) reachableIDs.next();
allNodes.remove(id);
}
results.add(result);
} catch (NoSuchElementException e) {
break;
}
it = allNodes.iterator();
}
allNodes.close();
return results.stream().map((x) -> new CCResult(x.stream().map((z) -> new Long(z.getId())).collect(Collectors.toList()), x.stream().collect(Collectors.groupingBy(CCVar::getType)).entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().size()))));
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class CommandPrimer method writeMulti.
private Action writeMulti() {
int count = rng.nextInt(5) + 1;
PrimitiveLongSet recordIds = Primitive.longSet();
Action action = null;
for (int i = 0; i < count; i++) {
action = buildWriteAction(action, recordIds);
}
return action;
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class IndexingAcceptanceTest method shouldConsiderNodesChangedInSameTxInIndexPrefixSearch.
@Test
public void shouldConsiderNodesChangedInSameTxInIndexPrefixSearch() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
// GIVEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
createNodes(db, LABEL1, "name", "Mattias");
PrimitiveLongSet toChangeToMatch = createNodes(db, LABEL1, "name", "Mats");
PrimitiveLongSet toChangeToNotMatch = createNodes(db, LABEL1, "name", "Karlsson");
PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl");
String prefix = "Karl";
// WHEN
PrimitiveLongSet found = Primitive.longSet();
try (Transaction tx = db.beginTx()) {
PrimitiveLongIterator toMatching = toChangeToMatch.iterator();
while (toMatching.hasNext()) {
long id = toMatching.next();
db.getNodeById(id).setProperty("name", prefix + "X" + id);
expected.add(id);
}
PrimitiveLongIterator toNotMatching = toChangeToNotMatch.iterator();
while (toNotMatching.hasNext()) {
long id = toNotMatching.next();
db.getNodeById(id).setProperty("name", "X" + id);
expected.remove(id);
}
Statement statement = getStatement((GraphDatabaseAPI) db);
ReadOperations readOperations = statement.readOperations();
NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
int propertyKeyId = descriptor.schema().getPropertyId();
found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, prefix)));
}
// THEN
assertThat(found, equalTo(expected));
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class IndexingAcceptanceTest method shouldIncludeNodesCreatedInSameTxInIndexSeekByPrefix.
@Test
public void shouldIncludeNodesCreatedInSameTxInIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
// GIVEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
createNodes(db, LABEL1, "name", "Mattias", "Mats");
PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Carl", "Carlsson");
// WHEN
PrimitiveLongSet found = Primitive.longSet();
try (Transaction tx = db.beginTx()) {
expected.add(createNode(db, map("name", "Carlchen"), LABEL1).getId());
createNode(db, map("name", "Karla"), LABEL1);
Statement statement = getStatement((GraphDatabaseAPI) db);
ReadOperations readOperations = statement.readOperations();
NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
int propertyKeyId = descriptor.schema().getPropertyId();
found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, "Carl")));
}
// THEN
assertThat(found, equalTo(expected));
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class GBPTree method consistencyCheck.
// Utility method
boolean consistencyCheck() throws IOException {
try (PageCursor cursor = pagedFile.io(0L, /*ignored*/
PagedFile.PF_SHARED_READ_LOCK)) {
long unstableGeneration = unstableGeneration(generation);
ConsistencyChecker<KEY> consistencyChecker = new ConsistencyChecker<>(bTreeNode, layout, stableGeneration(generation), unstableGeneration);
long rootGeneration = root.goTo(cursor);
boolean check = consistencyChecker.check(cursor, rootGeneration);
root.goTo(cursor);
PrimitiveLongSet freelistIds = Primitive.longSet();
freeList.visitFreelistPageIds(freelistIds::add);
freeList.visitUnacquiredIds(freelistIds::add, unstableGeneration);
boolean checkSpace = consistencyChecker.checkSpace(cursor, freeList.lastId(), freelistIds.iterator());
return check & checkSpace;
}
}
Aggregations