Beispiel #1
0
 private void PreOrder(SickTreeNode <TItem, TDecision> node, ref List <TItem> result)
 {
     if (node.HasValue)
     {
         result.Add(node.Item);
     }
     if (node.Children.Count != 0)
     {
         foreach (var v in node.Children.Values)
         {
             PreOrder(v, ref result);
         }
     }
 }
Beispiel #2
0
        public void AddPath(TItem item, TDecision[] path, bool overrideExisting = false)
        {
            if (path.Length == 0)
            {
                Root.Item = item;
                return;
            }

            var curr = Root;

            int i;

            for (i = 0; i < path.Length - 1; i++)
            {
                if (curr.Children.ContainsKey(path[i]))
                {
                    curr = curr.Children[path[i]];
                }
                else
                {
                    var temp = new SickTreeNode <TItem, TDecision>();
                    curr.Children.Add(path[i], temp);
                    curr = temp;
                }
            }

            if (curr.Children.ContainsKey(path[i]))
            {
                if (overrideExisting)
                {
                    curr.Children[path[i]].Item = item;
                }
                else
                {
                    throw new ArgumentException("path already exists");
                }
            }
            else
            {
                curr.Children.Add(path[i], new SickTreeNode <TItem, TDecision>(item));
            }
        }
Beispiel #3
0
 public SickTree()
 {
     Root           = new SickTreeNode <TItem, TDecision>();
     CurrTraversion = Traversion.PreOrder;
 }