/// <summary> /// Counts the number of incoming relationships from node where the cursor is positioned. /// <para> /// NOTE: The number of incoming relationships also includes eventual loops. /// /// </para> /// </summary> /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param> /// <param name="cursors"> a factory for cursors </param> /// <returns> the number of incoming - including loops - relationships from the node </returns> public static int CountIncoming(NodeCursor nodeCursor, CursorFactory cursors) { if (nodeCursor.Dense) { using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor()) { nodeCursor.Relationships(group); int count = 0; while (group.next()) { count += group.IncomingCount() + group.LoopCount(); } return(count); } } else { using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor()) { int count = 0; nodeCursor.AllRelationships(traversal); while (traversal.next()) { if (traversal.TargetNodeReference() == nodeCursor.NodeReference()) { count++; } } return(count); } } }
/// <summary> /// Counts the number of outgoing relationships of the given type from node where the cursor is positioned. /// <para> /// NOTE: The number of outgoing relationships also includes eventual loops. /// /// </para> /// </summary> /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param> /// <param name="cursors"> a factory for cursors </param> /// <param name="type"> the type of the relationship we're counting </param> /// <returns> the number of outgoing - including loops - relationships from the node with the given type </returns> public static int CountOutgoing(NodeCursor nodeCursor, CursorFactory cursors, int type) { if (nodeCursor.Dense) { using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor()) { nodeCursor.Relationships(group); while (group.next()) { if (group.Type() == type) { return(group.OutgoingCount() + group.LoopCount()); } } return(0); } } else { using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor()) { int count = 0; nodeCursor.AllRelationships(traversal); while (traversal.next()) { if (traversal.SourceNodeReference() == nodeCursor.NodeReference() && traversal.Type() == type) { count++; } } return(count); } } }
/// <summary> /// Counts all the relationships of the given type from node where the cursor is positioned. /// </summary> /// <param name="nodeCursor"> a cursor positioned at the node whose relationships we're counting </param> /// <param name="cursors"> a factory for cursors </param> /// <param name="type"> the type of the relationship we're counting </param> /// <returns> the number relationships from the node with the given type </returns> public static int CountAll(NodeCursor nodeCursor, CursorFactory cursors, int type) { if (nodeCursor.Dense) { using (RelationshipGroupCursor group = cursors.AllocateRelationshipGroupCursor()) { nodeCursor.Relationships(group); int count = 0; while (group.next()) { if (group.Type() == type) { return(group.TotalCount()); } } return(count); } } else { using (RelationshipTraversalCursor traversal = cursors.AllocateRelationshipTraversalCursor()) { int count = 0; nodeCursor.AllRelationships(traversal); while (traversal.next()) { if (traversal.Type() == type) { count++; } } return(count); } } }
private static void SetupAllSparse(RelationshipSparseSelection sparseSelection, CursorFactory cursors, NodeCursor node, int[] types) { RelationshipTraversalCursor traversalCursor = cursors.AllocateRelationshipTraversalCursor(); try { node.AllRelationships(traversalCursor); sparseSelection.All(traversalCursor, types); } catch (Exception t) { traversalCursor.close(); throw t; } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void traverseWithoutGroups(RelationshipTestSupport.StartNode start, boolean detached) throws org.neo4j.internal.kernel.api.exceptions.KernelException private void TraverseWithoutGroups(RelationshipTestSupport.StartNode start, bool detached) { // given using (NodeCursor node = cursors.allocateNodeCursor(), RelationshipTraversalCursor relationship = cursors.allocateRelationshipTraversalCursor()) { // when read.singleNode(start.Id, node); assertTrue("access node", node.Next()); if (detached) { read.relationships(start.Id, node.AllRelationshipsReference(), relationship); } else { node.AllRelationships(relationship); } IDictionary <string, int> counts = count(tx, relationship); // then assertCounts(start.ExpectedCounts(), counts); } }