コード例 #1
0
        //Basic graph functions:

        //combines hashes of two nodes for purposes of retrieving edge from nodeToEdge dict
        protected long CombineHashes(GraphNode obj1, GraphNode obj2)
        {
            long code1 = (long)obj2.GetHashCode(), code2 = (long)obj1.GetHashCode(), swap;

            if (code1 > code2)
            {
                swap  = code1;
                code1 = code2;
                code2 = swap;
            }
            long hash = 17;

            hash = hash * 31 + code1;
            hash = hash * 31 + code2;
            return(hash);
        }
コード例 #2
0
        //Creates an edge in the graph between the two given nodes, if they exist in the graph
        public virtual void CreateEdge(GraphNode node1, GraphNode node2)
        {
            if (!nodes.Contains(node1) || !nodes.Contains(node2))
            {
                throw new InvalidOperationException("Cannot add an edge if one or more of the nodes arent in the graph.");
            }

            GraphEdge newEdge = new GraphEdge(node1, node2);

            edges.Add(newEdge);

            try {
                nodeToEdgeDict.Add(CombineHashes(node1, node2), newEdge);
            }
            catch (ArgumentException)  {
                Debug.Log("hash collision: " + node1.GetHashCode().ToString() + " " + node2.GetHashCode().ToString()
                          + " " + CombineHashes(node1, node2).ToString());
                Debug.Log(nodeToEdgeDict[CombineHashes(node1, node2)].ToString());
                return;
            }
        }
コード例 #3
0
        //Creates an edge in the graph between the two given nodes, if they exist in the graph
        public virtual void CreateEdge(GraphNode node1, GraphNode node2) {
            if (!nodes.Contains(node1) || !nodes.Contains(node2)) {
                throw new InvalidOperationException("Cannot add an edge if one or more of the nodes arent in the graph.");
            }

            GraphEdge newEdge = new GraphEdge(node1, node2);
            edges.Add(newEdge);

            try {
                nodeToEdgeDict.Add(CombineHashes(node1, node2), newEdge);
            }
            catch(ArgumentException)  {
                Debug.Log("hash collision: " + node1.GetHashCode().ToString() + " " + node2.GetHashCode().ToString() 
                    + " " + CombineHashes(node1, node2).ToString());
                Debug.Log(nodeToEdgeDict[CombineHashes(node1, node2)].ToString());
                return;
            }

        }
コード例 #4
0
        //Basic graph functions:

        //combines hashes of two nodes for purposes of retrieving edge from nodeToEdge dict
        protected long CombineHashes(GraphNode obj1, GraphNode obj2) {
            long code1 = (long)obj2.GetHashCode(), code2 = (long)obj1.GetHashCode(), swap;
            if (code1 > code2) {
                swap = code1;
                code1 = code2;
                code2 = swap;
            }
            long hash = 17;
            hash = hash * 31 + code1;
            hash = hash * 31 + code2;
            return hash;
        }