private static void CategorizeNodesByLabels( TreeComparer <TNode> comparer, TNode root, int labelCount, out List <TNode>[] nodes, out int totalCount) { nodes = new List <TNode> [labelCount]; var count = 0; // It is important that we add the nodes in depth-first prefix order. // This order ensures that a node of a certain kind can have a parent of the same kind // and we can still use tied-to-parent for that kind. That's because the parent will always // be processed earlier than the child due to depth-first prefix ordering. foreach (var node in comparer.GetDescendants(root)) { var label = comparer.GetLabel(node); if (label < 0 || label >= labelCount) { throw new InvalidOperationException(string.Format(WorkspacesResources.Label_for_node_0_is_invalid_it_must_be_within_bracket_0_1, node, labelCount)); } var list = nodes[label]; if (list == null) { nodes[label] = list = new List <TNode>(); } list.Add(node); count++; } totalCount = count; }
private void CategorizeNodesByLabels( TNode root, int labelCount, out List <TNode>[] nodes, out int totalCount) { nodes = new List <TNode> [labelCount]; int count = 0; foreach (TNode node in comparer.GetDescendants(root)) { int label = comparer.GetLabel(node); if (label < 0 || label >= labelCount) { throw new InvalidOperationException(string.Format("Label for node '{0}' is invalid, it must be within [0, {1}).".NeedsLocalization(), node, labelCount)); } var list = nodes[label]; if (list == null) { nodes[label] = list = new List <TNode>(); } list.Add(node); count++; } totalCount = count; }
private void CategorizeNodesByLabels( TNode root, int labelCount, out List <TNode>[] nodes, out int totalCount) { nodes = new List <TNode> [labelCount]; int count = 0; // It is important that we add the nodes in depth-first prefix order. // This order ensures that a node of a certain kind can have a parent of the same kind // and we can still use tied-to-parent for that kind. That's because the parent will always // be processed earlier than the child due to depth-first prefix ordering. foreach (TNode node in comparer.GetDescendants(root)) { int label = comparer.GetLabel(node); if (label < 0 || label >= labelCount) { throw new InvalidOperationException(string.Format("Label for node '{0}' is invalid, it must be within [0, {1}).".NeedsLocalization(), node, labelCount)); } var list = nodes[label]; if (list == null) { nodes[label] = list = new List <TNode>(); } list.Add(node); count++; } totalCount = count; }