/// <summary> /// Adds the specified list. /// </summary> /// <param name="list">The list.</param> public void Add(SortedTreeNodeSortedList list) { foreach (KeyValuePair <int, SortedTreeNode> kvp in list) { Add(kvp.Key, kvp.Value); } }
/// <summary> /// Initializes a new instance of the <see cref="SortedTree{SortedTreeNodeSortedList}"/> class. /// </summary> /// <param name="list">The list.</param> public SortedTreeNodeSortedList(SortedTreeNodeSortedList list) : base(list.Count) { foreach (KeyValuePair <int, SortedTreeNode> kvp in list) { Add(kvp.Key, kvp.Value); } }
internal void ParentCleanup() { SortedTreeNodeSortedList myparentclonnedlist = (SortedTreeNodeSortedList)((ICloneable)ParentNodes).Clone(); foreach (KeyValuePair <int, SortedTreeNode> kvpnode in myparentclonnedlist) { if (MyParentTree.GetNode(kvpnode.Value.Value) == null) { //oznacza to ze dany node ma na swojej liscie tego parenta a drzewo juz nie ma, nalezy wiec go usunac: ParentNodes.Remove(kvpnode.Key); } } foreach (KeyValuePair <int, SortedTreeNode> kvpnode in mChildNodes) { kvpnode.Value.ParentCleanup(); } }
/// <summary> /// Removes the value. /// </summary> /// <param name="ValueToBeRemoved">The value to be removed.</param> /// <param name="Shallow">if set to <c>true</c> [shallow] removal is done (all children are moved to root if they are not connected to any others elements).</param> public void RemoveValue(T ValueToBeRemoved, bool Shallow) { SortedTreeNode NodeToBeRemoved = GetNode(ValueToBeRemoved); SortedTreeNode node; if (NodeToBeRemoved == null) { throw new SortedTreeNodeException("the value cannot be found on the tree"); } if (Shallow) { //because it is not allowed to change the collection and make foreach on it: SortedTreeNodeSortedList childnodes = NodeToBeRemoved.GetChildNodes(); node = childnodes.GetFirstNodeFromThisCollection(); while ((node = childnodes.GetFirstNodeFromThisCollection()) != null) { RemoveConnectionBetweeenParentAndChildAndMoveElementToRoots(NodeToBeRemoved.Value, node.Value); childnodes = NodeToBeRemoved.GetChildNodes(); } } //removal of connection above node that is removed SortedTreeNodeSortedList parentnodes = NodeToBeRemoved.ParentNodes; node = parentnodes.GetFirstNodeFromThisCollection(); while ((node = parentnodes.GetFirstNodeFromThisCollection()) != null) { RemoveConnectionBetweeenParentAndChildAndMoveElementToRoots(node.Value, NodeToBeRemoved.Value); parentnodes = NodeToBeRemoved.ParentNodes; } foreach (KeyValuePair <int, SortedTreeNode> kvpnode in parentnodes) { RemoveConnectionBetweeenParentAndChildAndMoveElementToRoots(kvpnode.Value.Value, NodeToBeRemoved.Value); } RemoveSortedNodeFromRoots(NodeToBeRemoved); ParentCleanup(); }