TestGetVertexIDPair6() { // Undirected graph, useDirectedness = false. IGraph oUndirectedGraph = new Graph(GraphDirectedness.Undirected); IVertexCollection oUndirectedVertices = oUndirectedGraph.Vertices; IVertex oUndirectedVertexA = oUndirectedVertices.Add(); IVertex oUndirectedVertexB = oUndirectedVertices.Add(); IVertex oUndirectedVertexC = oUndirectedVertices.Add(); IVertex oUndirectedVertexD = oUndirectedVertices.Add(); IEdgeCollection oEdges = oUndirectedGraph.Edges; IEdge oEdge1 = oEdges.Add(oUndirectedVertexA, oUndirectedVertexB, false); IEdge oEdge2 = oEdges.Add(oUndirectedVertexA, oUndirectedVertexB, false); IEdge oEdge3 = oEdges.Add(oUndirectedVertexB, oUndirectedVertexA, false); IEdge oEdge4 = oEdges.Add(oUndirectedVertexA, oUndirectedVertexC, false); Int64 i64VertexIDPair1 = EdgeUtil.GetVertexIDPair(oEdge1, false); Int64 i64VertexIDPair2 = EdgeUtil.GetVertexIDPair(oEdge2, false); Int64 i64VertexIDPair3 = EdgeUtil.GetVertexIDPair(oEdge3, false); Int64 i64VertexIDPair4 = EdgeUtil.GetVertexIDPair(oEdge4, false); // Make sure that the left-shift worked. Assert.IsTrue(i64VertexIDPair1 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair2 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair3 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair4 > Int32.MaxValue); Assert.AreEqual(i64VertexIDPair1, i64VertexIDPair2); Assert.AreEqual(i64VertexIDPair1, i64VertexIDPair3); Assert.AreNotEqual(i64VertexIDPair1, i64VertexIDPair4); Assert.AreEqual(i64VertexIDPair2, i64VertexIDPair3); Assert.AreNotEqual(i64VertexIDPair2, i64VertexIDPair4); Assert.AreNotEqual(i64VertexIDPair3, i64VertexIDPair4); }
TestGetVertexIDPair() { // Directed graph. IGraph oDirectedGraph = new Graph(GraphDirectedness.Directed); IVertexCollection oDirectedVertices = oDirectedGraph.Vertices; IVertex oDirectedVertexA = oDirectedVertices.Add(); IVertex oDirectedVertexB = oDirectedVertices.Add(); IVertex oDirectedVertexC = oDirectedVertices.Add(); IVertex oDirectedVertexD = oDirectedVertices.Add(); IEdgeCollection oEdges = oDirectedGraph.Edges; IEdge oEdge1 = oEdges.Add(oDirectedVertexA, oDirectedVertexB, true); IEdge oEdge2 = oEdges.Add(oDirectedVertexA, oDirectedVertexB, true); IEdge oEdge3 = oEdges.Add(oDirectedVertexB, oDirectedVertexA, true); IEdge oEdge4 = oEdges.Add(oDirectedVertexA, oDirectedVertexC, true); Int64 i64VertexIDPair1 = EdgeUtil.GetVertexIDPair(oEdge1); Int64 i64VertexIDPair2 = EdgeUtil.GetVertexIDPair(oEdge2); Int64 i64VertexIDPair3 = EdgeUtil.GetVertexIDPair(oEdge3); Int64 i64VertexIDPair4 = EdgeUtil.GetVertexIDPair(oEdge4); // Make sure that the left-shift worked. Assert.IsTrue(i64VertexIDPair1 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair2 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair3 > Int32.MaxValue); Assert.IsTrue(i64VertexIDPair4 > Int32.MaxValue); Assert.AreEqual(i64VertexIDPair1, i64VertexIDPair2); Assert.AreNotEqual(i64VertexIDPair1, i64VertexIDPair3); Assert.AreNotEqual(i64VertexIDPair1, i64VertexIDPair4); Assert.AreNotEqual(i64VertexIDPair2, i64VertexIDPair3); Assert.AreNotEqual(i64VertexIDPair2, i64VertexIDPair4); Assert.AreNotEqual(i64VertexIDPair3, i64VertexIDPair4); }
CountEdges() { AssertValid(); if (m_bEdgesCounted) { return; } m_iUniqueEdges = 0; m_iEdgesWithDuplicates = 0; IEdgeCollection oEdges = m_oGraph.Edges; Boolean bGraphIsDirected = (m_oGraph.Directedness == GraphDirectedness.Directed); // Create a dictionary of vertex ID pairs. The key is the vertex ID // pair and the value is true if the edge has duplicates or false if it // doesn't. Dictionary <Int64, Boolean> oVertexIDPairs = new Dictionary <Int64, Boolean>(oEdges.Count); foreach (IEdge oEdge in oEdges) { Int64 i64VertexIDPair = EdgeUtil.GetVertexIDPair(oEdge); Boolean bEdgeHasDuplicate; if (oVertexIDPairs.TryGetValue(i64VertexIDPair, out bEdgeHasDuplicate)) { if (!bEdgeHasDuplicate) { // This is the edge's first duplicate. m_iUniqueEdges--; m_iEdgesWithDuplicates++; oVertexIDPairs[i64VertexIDPair] = true; } m_iEdgesWithDuplicates++; } else { m_iUniqueEdges++; oVertexIDPairs.Add(i64VertexIDPair, false); } } m_iTotalEdgesAfterMergingDuplicatesNoSelfLoops = 0; foreach (Int64 i64VertexIDPair in oVertexIDPairs.Keys) { Int32 iVertexID1 = (Int32)(i64VertexIDPair >> 32); Int32 iVertexID2 = (Int32)i64VertexIDPair; if (iVertexID1 != iVertexID2) { m_iTotalEdgesAfterMergingDuplicatesNoSelfLoops++; } } m_bEdgesCounted = true; AssertValid(); }