use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j-apoc-procedures by neo4j-contrib.
the class PageRankArrayStorageParallelSPI method compute.
@Override
public void compute(int iterations, RelationshipType... relationshipTypes) {
stats.iterations = iterations;
long start = System.currentTimeMillis();
final int[] src = new int[nodeCount];
dst = new AtomicIntegerArray(nodeCount);
final int[] degrees = computeDegrees(ctx(this.db));
stats.readNodeMillis = System.currentTimeMillis() - start;
stats.nodes = nodeCount;
start = System.currentTimeMillis();
final ReadOperations ops = ctx(this.db).get().readOperations();
final IntPredicate isValidRelationshipType = relationshipTypeArrayToIntPredicate(ops, relationshipTypes);
final RelationshipVisitor<RuntimeException> visitor = isValidRelationshipType == null ? (relId, relTypeId, startNode, endNode) -> dst.addAndGet((int) endNode, src[(int) startNode]) : (relId, relTypeId, startNode, endNode) -> {
if (isValidRelationshipType.test(relTypeId)) {
dst.addAndGet((int) endNode, src[(int) startNode]);
}
};
PrimitiveLongIterator rels = ops.relationshipsGetAll();
List<BatchRunnable> runners = prepareOperations(rels, relCount, db, (readOps, id) -> readOps.relationshipVisit(id, visitor), guard);
stats.readRelationshipMillis = System.currentTimeMillis() - start;
stats.relationships = relCount;
start = System.currentTimeMillis();
for (int iteration = 0; iteration < iterations; iteration++) {
startIteration(src, dst, degrees);
// PrimitiveLongIterator rels = ops.relationshipsGetAll();
// runOperations( pool, rels, relCount, ctx, (readOps, id) -> readOps.relationshipVisit( id, visitor ) );
runOperations(pool, runners);
}
stats.computeMillis = System.currentTimeMillis() - start;
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j-apoc-procedures by neo4j-contrib.
the class CoreGraphAlgorithms method loadRels.
private void loadRels(ReadOperations ops, int labelId, int relTypeId) throws EntityNotFoundException {
int allRelCount = (int) ops.relationshipsGetCount();
this.relCount = (int) ops.countsForRelationshipWithoutTxState(labelId, relTypeId, ANY_LABEL);
this.rels = new int[relCount];
float percentage = (float) relCount / (float) allRelCount;
// if (percentage > 0.5) {
// this.relCount = loadRels(ops, ops.relationshipsGetAll(), relCount, relTypeId,rels);
// }
// else {
PrimitiveLongIterator nodeIds = labelId == -1 ? ops.nodesGetAll() : ops.nodesGetForLabel(labelId);
this.relCount = loadNodeRels(ops, nodeIds, relTypeId, rels);
// }
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator 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.PrimitiveLongIterator in project neo4j by neo4j.
the class StateHandlingStatementOperations method indexQuery.
@Override
public PrimitiveLongIterator indexQuery(KernelStatement state, NewIndexDescriptor index, IndexQuery... predicates) throws IndexNotFoundKernelException, IndexNotApplicableKernelException {
StorageStatement storeStatement = state.getStoreStatement();
IndexReader reader = storeStatement.getIndexReader(index);
PrimitiveLongIterator committed = reader.query(predicates);
PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches(this, state, committed, predicates);
IndexQuery firstPredicate = predicates[0];
switch(firstPredicate.type()) {
case exact:
IndexQuery.ExactPredicate[] exactPreds = assertOnlyExactPredicates(predicates);
return filterIndexStateChangesForSeek(state, exactMatches, index, OrderedPropertyValues.of(exactPreds));
case stringSuffix:
case stringContains:
case exists:
return filterIndexStateChangesForScan(state, exactMatches, index);
case rangeNumeric:
{
assertSinglePredicate(predicates);
IndexQuery.NumberRangePredicate numPred = (IndexQuery.NumberRangePredicate) firstPredicate;
return filterIndexStateChangesForRangeSeekByNumber(state, index, numPred.from(), numPred.fromInclusive(), numPred.to(), numPred.toInclusive(), exactMatches);
}
case rangeString:
{
assertSinglePredicate(predicates);
IndexQuery.StringRangePredicate strPred = (IndexQuery.StringRangePredicate) firstPredicate;
return filterIndexStateChangesForRangeSeekByString(state, index, strPred.from(), strPred.fromInclusive(), strPred.to(), strPred.toInclusive(), committed);
}
case stringPrefix:
{
assertSinglePredicate(predicates);
IndexQuery.StringPrefixPredicate strPred = (IndexQuery.StringPrefixPredicate) firstPredicate;
return filterIndexStateChangesForRangeSeekByPrefix(state, index, strPred.prefix(), committed);
}
default:
throw new UnsupportedOperationException("Query not supported: " + Arrays.toString(predicates));
}
}
use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.
the class StateHandlingStatementOperations method nodeGetFromUniqueIndexSeek.
@Override
public long nodeGetFromUniqueIndexSeek(KernelStatement state, NewIndexDescriptor index, IndexQuery.ExactPredicate... query) throws IndexNotFoundKernelException, IndexBrokenKernelException, IndexNotApplicableKernelException {
IndexReader reader = state.getStoreStatement().getFreshIndexReader(index);
/* Here we have an intricate scenario where we need to return the PrimitiveLongIterator
* since subsequent filtering will happen outside, but at the same time have the ability to
* close the IndexReader when done iterating over the lookup result. This is because we get
* a fresh reader that isn't associated with the current transaction and hence will not be
* automatically closed. */
PrimitiveLongResourceIterator committed = resourceIterator(reader.query(query), reader);
PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches(this, state, committed, query);
PrimitiveLongIterator changesFiltered = filterIndexStateChangesForSeek(state, exactMatches, index, OrderedPropertyValues.of(query));
return single(resourceIterator(changesFiltered, committed), NO_SUCH_NODE);
}
Aggregations