Analyzer.ConnectedComponentCalculator.SortStronglyConnectedComponents C# (CSharp) Method

SortStronglyConnectedComponents() protected method

protected SortStronglyConnectedComponents ( List oStronglyConnectedComponents, IGraph oGraph, System.Boolean bSortAscending ) : void
oStronglyConnectedComponents List
oGraph IGraph
bSortAscending System.Boolean
return void
        SortStronglyConnectedComponents
        (
            List<LinkedList<IVertex>> oStronglyConnectedComponents,
            IGraph oGraph,
            Boolean bSortAscending
        )
        {
            Debug.Assert(oStronglyConnectedComponents != null);
            Debug.Assert(oGraph != null);

            // The key is a strongly connected component and the value is the
            // smallest vertex layout sort order within the component.

            Dictionary<LinkedList<IVertex>, Single>
                oSmallestSortableLayoutAndZOrder = null;

            if (oGraph.ContainsKey(
                ReservedMetadataKeys.SortableLayoutAndZOrderSet))
            {
                // The vertex layout sort orders have been set on the vertices.
                // Populate the dictionary.

                oSmallestSortableLayoutAndZOrder =
                    new Dictionary<LinkedList<IVertex>, Single>();

                foreach (LinkedList<IVertex> oStronglyConnectedComponent in
                    oStronglyConnectedComponents)
                {
                    oSmallestSortableLayoutAndZOrder.Add(
                        oStronglyConnectedComponent,
                        GetSmallestSortableLayoutAndZOrder(
                            oStronglyConnectedComponent)
                        );
                }
            }

            oStronglyConnectedComponents.Sort(
                delegate
                (
                    LinkedList<IVertex> oStronglyConnectedComponent1,
                    LinkedList<IVertex> oStronglyConnectedComponent2
                )
                {
                    // Sort the components first by increasing vertex count.

                    Int32 iCompareTo =
                        oStronglyConnectedComponent1.Count.CompareTo(
                            oStronglyConnectedComponent2.Count);

                    if (!bSortAscending)
                    {
                        iCompareTo *= -1;
                    }

                    if (iCompareTo == 0 &&
                        oSmallestSortableLayoutAndZOrder != null)
                    {
                        // Sub-sort components with the same vertex count by the
                        // smallest layout and z-order within the component.

                        iCompareTo = oSmallestSortableLayoutAndZOrder[
                            oStronglyConnectedComponent1].CompareTo(
                                oSmallestSortableLayoutAndZOrder[
                                    oStronglyConnectedComponent2]);
                    }

                    return (iCompareTo);
                }
                );
        }