Analyzer.EdgeReciprocationCalculator.TryCalculateGraphMetrics C# (CSharp) Method

TryCalculateGraphMetrics() public method

public TryCalculateGraphMetrics ( IGraph graph, BackgroundWorker backgroundWorker, Boolean>.Dictionary &graphMetrics ) : System.Boolean
graph IGraph
backgroundWorker System.ComponentModel.BackgroundWorker
graphMetrics Boolean>.Dictionary
return System.Boolean
        public Boolean TryCalculateGraphMetrics
            (IGraph graph, BackgroundWorker backgroundWorker, out Dictionary<Int32, Boolean> graphMetrics)
        {
            Debug.Assert(graph != null);

            IEdgeCollection oEdges = graph.Edges;

            // The key is an IEdge.ID and the value is a Boolean that indicates
            // whether the edge is reciprocated.

            Dictionary<Int32, Boolean> oReciprocationFlags =
                new Dictionary<Int32, Boolean>(oEdges.Count);

            graphMetrics = oReciprocationFlags;

            // The key is the combined IDs of the edge's vertices.

            HashSet<Int64> oVertexIDPairs = new HashSet<Int64>();

            if (graph.Directedness == GraphDirectedness.Directed)
            {
                foreach (IEdge oEdge in oEdges)
                {
                    oVertexIDPairs.Add(GetDictionaryKey(
                        oEdge.Vertex1, oEdge.Vertex2));
                }

                if (!ReportProgressAndCheckCancellationPending(
                    1, 2, backgroundWorker))
                {
                    return (false);
                }

                foreach (IEdge oEdge in oEdges)
                {
                    Boolean bEdgeIsReciprocated = false;

                    if (!oEdge.IsSelfLoop)
                    {
                        Int64 i64ReversedVerticesKey = GetDictionaryKey(
                            oEdge.Vertex2, oEdge.Vertex1);

                        bEdgeIsReciprocated =
                            oVertexIDPairs.Contains(i64ReversedVerticesKey);
                    }

                    oReciprocationFlags.Add(oEdge.ID, bEdgeIsReciprocated);
                }
            }

            return (true);
        }