Search in sources :

Example 21 with PrimitiveLongSet

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()))));
}
Also used : CCVar(apoc.algo.wcc.CCVar) Primitive(org.neo4j.collection.primitive.Primitive) java.util(java.util) Log(org.neo4j.logging.Log) Context(org.neo4j.procedure.Context) Description(org.neo4j.procedure.Description) Collectors(java.util.stream.Collectors) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Stream(java.util.stream.Stream) org.neo4j.graphdb(org.neo4j.graphdb) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) CCResult(apoc.result.CCResult) Procedure(org.neo4j.procedure.Procedure) CCVar(apoc.algo.wcc.CCVar) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) CCResult(apoc.result.CCResult) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 22 with PrimitiveLongSet

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;
}
Also used : PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet)

Example 23 with PrimitiveLongSet

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));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 24 with PrimitiveLongSet

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));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 25 with PrimitiveLongSet

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;
    }
}
Also used : PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) PageCursor(org.neo4j.io.pagecache.PageCursor)

Aggregations

PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)36 Test (org.junit.Test)27 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)5 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)5 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 Statement (org.neo4j.kernel.api.Statement)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 IOException (java.io.IOException)3 CCVar (apoc.algo.wcc.CCVar)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CCResult (apoc.result.CCResult)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringReader (java.io.StringReader)1 java.util (java.util)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1