Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
 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);
         }
     }
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 public CompSetTree()
 {
     _root             = new CompSetNode(0, null, null, this);
     _idToCompSetNodes = new Dictionary <int, List <CompSetNode> >();
 }