private void AddChild(List <int> compSet) { var curentId = compSet[0]; if (Childs.ContainsKey(curentId)) { var child = Childs[curentId]; compSet.RemoveAt(0); if ((compSet.Count == 0) && (child.Childs.Count >= 0)) //it is sub set or equal - remove super sets (childs) { child.Childs.Clear(); return; } if ((child.Childs.Count == 0) && (compSet.Count > 0)) // it is super set - ignore { return; } Childs[curentId].AddChild(compSet); } else { compSet.RemoveAt(0); var newChild = new CompSetNode(curentId, compSet, this, _tree); _tree.AddChildToAllCompSetDictionary(newChild); Childs.Add(curentId, newChild); } }
public void AddChildToAllCompSetDictionary(CompSetNode newChild) { var newChildId = newChild.Id; if (!_idToCompSetNodes.ContainsKey(newChildId)) { var compSetNodes = new List <CompSetNode>(); _idToCompSetNodes.Add(newChildId, compSetNodes); } _idToCompSetNodes[newChildId].Add(newChild); }
public CompSetNode(int id, List <int> childs, CompSetNode parent, CompSetTree tree) { this._parent = parent; this.Childs = new Dictionary <int, CompSetNode>(); this.Id = id; this._tree = tree; if ((childs != null) && (childs.Count > 0)) { AddChild(childs); } }
public void RemoveSuperSetsIfExist(List <int> set) { if (set.Count == 0) { RemoveSuperSet(); } else { int curentId = set[0]; if (Childs.ContainsKey(curentId)) { CompSetNode child = Childs[curentId]; set.RemoveAt(0); child.RemoveSuperSetsIfExist(set); } } }
public bool IsContainSubSetOf(List <int> set) { int curentId = set[0]; if (Childs.ContainsKey(curentId)) { CompSetNode child = Childs[curentId]; set.RemoveAt(0); if (child.Childs.Count == 0) // this branch is sub set(or equal) of the new set { return(true); } if (set.Count == 0) // no more elementes in new set - not subset in this branch { return(false); } return(child.IsContainSubSetOf(set)); } return(false); }
public CompSetTree() { _root = new CompSetNode(0, null, null, this); _idToCompSetNodes = new Dictionary <int, List <CompSetNode> >(); }