Esempio n. 1
0
        internal RelationshipDirection(string name, InnerEnum innerEnum, Org.Neo4j.Graphdb.Direction @internal)
        {
            this.Internal = @internal;

            nameValue      = name;
            ordinalValue   = nextOrdinal++;
            innerEnumValue = innerEnum;
        }
Esempio n. 2
0
        private static int CalculateTotalDegree(NodeCursor nodeCursor, Direction direction, int[] relTypes, CursorFactory cursors)
        {
            int degree = 0;

            foreach (int relType in relTypes)
            {
                degree += NodeGetDegree(nodeCursor, cursors, direction, relType);
            }

            return(degree);
        }
Esempio n. 3
0
        public override double?GetCost(Relationship relationship, Direction direction)
        {
            object costProp = relationship.GetProperty(_costPropertyName);

            if (costProp is Number)
            {
                return((( Number )costProp).doubleValue());
            }
            else
            {
                return(double.Parse(costProp.ToString()));
            }
        }
Esempio n. 4
0
        public static RelationshipSelectionCursor ConnectingRelationships(Read read, CursorFactory cursors, NodeCursor nodeCursor, long fromNode, Direction direction, long toNode, int[] relTypes)
        {
            //Check from
            int fromDegree = CalculateTotalDegreeIfDense(read, fromNode, nodeCursor, direction, relTypes, cursors);

            if (fromDegree == 0)
            {
                return(Org.Neo4j.@internal.Kernel.Api.helpers.RelationshipSelectionCursor_EMPTY);
            }
            bool fromNodeIsDense = fromDegree != NOT_DENSE_DEGREE;

            //Check to
            read.SingleNode(toNode, nodeCursor);
            if (!nodeCursor.Next())
            {
                return(Org.Neo4j.@internal.Kernel.Api.helpers.RelationshipSelectionCursor_EMPTY);
            }
            bool toNodeIsDense = nodeCursor.Dense;

            //Both are dense, start with the one with the lesser degree
            if (fromNodeIsDense && toNodeIsDense)
            {
                //Note that we have already position the cursor at toNode
                int       toDegree = CalculateTotalDegree(nodeCursor, direction, relTypes, cursors);
                long      startNode;
                long      endNode;
                Direction relDirection;
                if (fromDegree < toDegree)
                {
                    startNode    = fromNode;
                    endNode      = toNode;
                    relDirection = direction;
                }
                else
                {
                    startNode    = toNode;
                    endNode      = fromNode;
                    relDirection = direction.reverse();
                }

                return(ConnectingRelationshipsIterator(CompiledCursorUtils.NodeGetRelationships(read, cursors, nodeCursor, startNode, relDirection, relTypes), endNode));
            }
            else if (fromNodeIsDense)
            {
                return(ConnectingRelationshipsIterator(CompiledCursorUtils.NodeGetRelationships(read, cursors, nodeCursor, toNode, direction.reverse(), relTypes), fromNode));
            }
            else
            {               //either only toNode is dense or none of them, just go with what we got
                return(ConnectingRelationshipsIterator(CompiledCursorUtils.NodeGetRelationships(read, cursors, nodeCursor, fromNode, direction, relTypes), toNode));
            }
        }
 protected internal override SingleSourceShortestPath <int> GetSingleSourceAlgorithm(Node startNode, Direction direction, params RelationshipType[] relTypes)
 {
     return(new SingleSourceShortestPathBFS(startNode, direction, relTypes));
 }
Esempio n. 6
0
 public override double?GetCost(Relationship relationship, Direction direction)
 {
     return((( Number )relationship.GetProperty(_costPropertyName, _defaultCost)).doubleValue());
 }
 protected internal override SingleSourceShortestPath <int> GetSingleSourceAlgorithm(Node startNode, Direction direction, params RelationshipType[] relTypes)
 {
     return(new SingleSourceShortestPathDijkstra <int>(0, startNode, (relationship, direction1) => 1, new IntegerAdder(), int?.compareTo, direction, relTypes));
 }
Esempio n. 8
0
 public static RelationshipSelectionCursor NodeGetRelationships(Read read, CursorFactory cursors, NodeCursor node, long nodeId, Direction direction)
 {
     return(NodeGetRelationships(read, cursors, node, nodeId, direction, null));
 }
Esempio n. 9
0
        public static RelationshipSelectionCursor NodeGetRelationships(Read read, CursorFactory cursors, NodeCursor node, long nodeId, Direction direction, int[] types)
        {
            read.SingleNode(nodeId, node);
            if (!node.Next())
            {
                return(Org.Neo4j.@internal.Kernel.Api.helpers.RelationshipSelectionCursor_EMPTY);
            }
            switch (direction.innerEnumValue)
            {
            case Direction.InnerEnum.OUTGOING:
                return(RelationshipSelections.outgoingCursor(cursors, node, types));

            case Direction.InnerEnum.INCOMING:
                return(RelationshipSelections.incomingCursor(cursors, node, types));

            case Direction.InnerEnum.BOTH:
                return(RelationshipSelections.allCursor(cursors, node, types));

            default:
                throw new System.InvalidOperationException("Unknown direction " + direction);
            }
        }
Esempio n. 10
0
 private static int CalculateTotalDegreeIfDense(Read read, long node, NodeCursor nodeCursor, Direction direction, int[] relTypes, CursorFactory cursors)
 {
     read.SingleNode(node, nodeCursor);
     if (!nodeCursor.Next())
     {
         return(0);
     }
     if (!nodeCursor.Dense)
     {
         return(NOT_DENSE_DEGREE);
     }
     return(CalculateTotalDegree(nodeCursor, direction, relTypes, cursors));
 }
Esempio n. 11
0
        private static int NodeGetDegree(NodeCursor nodeCursor, CursorFactory cursors, Direction direction, int type)
        {
            switch (direction.innerEnumValue)
            {
            case Direction.InnerEnum.OUTGOING:
                return(countOutgoing(nodeCursor, cursors, type));

            case Direction.InnerEnum.INCOMING:
                return(countIncoming(nodeCursor, cursors, type));

            case Direction.InnerEnum.BOTH:
                return(countAll(nodeCursor, cursors, type));

            default:
                throw new System.InvalidOperationException("Unknown direction " + direction);
            }
        }
Esempio n. 12
0
        internal static int NodeGetDegreeIfDense(Read read, long node, NodeCursor nodeCursor, CursorFactory cursors, Direction direction, int type)
        {
            read.SingleNode(node, nodeCursor);
            if (!nodeCursor.Next())
            {
                return(0);
            }
            if (!nodeCursor.Dense)
            {
                return(NOT_DENSE_DEGREE);
            }

            return(NodeGetDegree(nodeCursor, cursors, direction, type));
        }