Пример #1
0
 /// <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);
         }
     }
 }
Пример #2
0
 /// <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);
         }
     }
 }
Пример #3
0
 /// <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);
         }
     }
 }
Пример #4
0
        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;
            }
        }
Пример #5
0
        private static void SetupAllDense(RelationshipDenseSelection denseSelection, CursorFactory cursors, NodeCursor node, int[] types)
        {
            RelationshipGroupCursor     groupCursor     = cursors.AllocateRelationshipGroupCursor();
            RelationshipTraversalCursor traversalCursor = cursors.AllocateRelationshipTraversalCursor();

            try
            {
                node.Relationships(groupCursor);
                denseSelection.All(groupCursor, traversalCursor, types);
            }
            catch (Exception t)
            {
                groupCursor.close();
                traversalCursor.close();
                throw t;
            }
        }