예제 #1
0
 public void Add(IPatriciaTreeItem item)
 {
     if (item == null)
     {
         throw new ArgumentNullException(nameof(item));
     }
     this._items.Add(item);
     this.AddNode(this._root, item);
 }
예제 #2
0
 protected Node(int index, string key, int bit, IPatriciaTreeItem data)
 {
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     if (0 > bit)
     {
         throw new ArgumentOutOfRangeException(nameof(bit));
     }
     this._index = index;
     this._key   = key;
     this._bit   = bit;
     this._item  = data;
 }
예제 #3
0
 private void AddNode(PatriciaTree.Node node, IPatriciaTreeItem item)
 {
     if (node == null)
     {
         this._root = (PatriciaTree.Node) new PatriciaTree.Leaf(this._nodes.Count, item);
         this._nodes.Add((PatriciaTree.INode) this._root);
     }
     else
     {
         int start = node.Parent == null ? 0 : node.Parent.Bit;
         if (node is PatriciaTree.BranchNode)
         {
             int bit = PatriciaTree.BitHelper.CompareBit(node.Key, item.Key, start, node.Bit);
             if (0 <= bit)
             {
                 PatriciaTree.Leaf leaf = new PatriciaTree.Leaf(this._nodes.Count, item);
                 this._nodes.Add((PatriciaTree.INode)leaf);
                 this.Branch(node, (PatriciaTree.Node)leaf, bit);
             }
             else
             {
                 this.AddNode(PatriciaTree.BitHelper.GetBit(item.Key, node.Bit) ? node.Right : node.Left, item);
             }
         }
         else
         {
             if (!(node is PatriciaTree.Leaf))
             {
                 throw new Exception("invalid node type.");
             }
             int bit = PatriciaTree.BitHelper.CompareBit(node.Key, item.Key, start);
             if (0 >= bit)
             {
                 throw new ArgumentException(nameof(item));
             }
             PatriciaTree.Leaf leaf = new PatriciaTree.Leaf(this._nodes.Count, item);
             this._nodes.Add((PatriciaTree.INode)leaf);
             this.Branch(node, (PatriciaTree.Node)leaf, bit);
         }
     }
 }
예제 #4
0
 public bool Remove(IPatriciaTreeItem item)
 {
     return(this.Remove(item.Key));
 }
예제 #5
0
 public Leaf(int index, IPatriciaTreeItem item)
     : base(index, item.Key, PatriciaTree.BitHelper.GetBitCount(item.Key), item)
 {
 }