Smrf.NodeXL.ExcelTemplate.GroupEdgeSorter.SortFilteredEdgesByGroup C# (CSharp) Method

SortFilteredEdgesByGroup() private static method

private static SortFilteredEdgesByGroup ( IGraph oGraph, Int32 iMaximumGroups, IEnumerable oFilteredEdges ) : List
oGraph IGraph
iMaximumGroups System.Int32
oFilteredEdges IEnumerable
return List
    SortFilteredEdgesByGroup
    (
        IGraph oGraph,
        Int32 iMaximumGroups,
        IEnumerable<IEdge> oFilteredEdges
    )
    {
        Debug.Assert(oGraph != null);
        Debug.Assert(iMaximumGroups > 0);
        Debug.Assert(oFilteredEdges != null);

        List<GroupEdgeInfo> oGroupEdgeInfos = new List<GroupEdgeInfo>();

        // Get the graph's groups.

        GroupInfo [] aoGroups;

        if ( GroupUtil.TryGetGroups(oGraph, out aoGroups) )
        {
            // For each top group, we need a collection of the edges whose
            // first vertex is in the group.

            // This LinkedList will contain the graph's filtered edges, sorted
            // by their first vertex.  A null entry is inserted between each
            // set of edges.

            LinkedList<IEdge> oSortedEdges;

            // The key is a vertex, and the value is the first entry in
            // oSortedEdges for the vertex.

            Dictionary< IVertex, LinkedListNode<IEdge> > oFirstNodes;

            SortEdgesByVertex1(oFilteredEdges, out oSortedEdges,
                out oFirstNodes);

            List<IEdge> oEdgesInGroup = new List<IEdge>();

            // Sort the groups by descending vertex count.

            foreach ( ExcelTemplateGroupInfo oGroupInfo in
                ExcelTemplateGroupUtil.GetTopGroups(aoGroups, iMaximumGroups) )
            {
                oEdgesInGroup.Clear();

                foreach (IVertex oVertex in oGroupInfo.Vertices)
                {
                    // Loop through the edges that have oVertex as their first
                    // vertex.

                    LinkedListNode<IEdge> oNodeForVertex;

                    if ( oFirstNodes.TryGetValue(oVertex, out oNodeForVertex) )
                    {
                        while (oNodeForVertex.Value != null)
                        {
                            oEdgesInGroup.Add(oNodeForVertex.Value);
                            oNodeForVertex = oNodeForVertex.Next;
                        }
                    }
                }

                oGroupEdgeInfos.Add( new GroupEdgeInfo(
                    oEdgesInGroup.ToArray(), oGroupInfo) );
            }
        }

        return (oGroupEdgeInfos);
    }