/// <summary> /// Creates a dictionary that stores IDs of ConnectedNodeGroups contained within each ConnectedNodeGroup. /// </summary> /// <param name="connectedGroups">List of ConnectedNodeGroups, sorted in order of area size, descending.</param> /// <returns></returns> public static SortedDictionary <int, HashSet <int> > StoreNestedGroups(SortedList <int, ConnectedNodeGroup> connectedGroups) { if (connectedGroups is null) { throw new ArgumentNullException(nameof(connectedGroups)); } var idsContainedInGroup = new SortedDictionary <int, HashSet <int> >(); for (int i = 0; i < connectedGroups.Count; i++) { ConnectedNodeGroup thisGroup = connectedGroups[i]; idsContainedInGroup.Add(thisGroup.id, new HashSet <int>()); for (int j = 0; j < connectedGroups.Count; j++) { ConnectedNodeGroup otherGroup = connectedGroups[j]; if (i != j && thisGroup.IsOtherGroupInThisGroup(otherGroup)) { idsContainedInGroup[thisGroup.id].Add(otherGroup.id); } } } return(_SimplifyNestedGroups(idsContainedInGroup)); }