Esempio n. 1
0
            internal static RBUIntNode LowerNode(RBTree tree, uint key)
            {
                RBUIntNode lowParent = null;
                RBUIntNode current   = (RBUIntNode)tree.root;

                while (current != null)
                {
                    if (key < current.key)
                    {
                        current = (RBUIntNode)current.left;
                    }
                    else if (key > current.key)
                    {
                        lowParent = current;
                        current   = (RBUIntNode)current.right;
                    }
                    else
                    {
                        break;
                    }
                }
                // we finished walk on a node with key equal to ours
                if (current != null && current.left != null)
                {
                    return((RBUIntNode)current.left.LastNode());
                }
                return(lowParent);
            }
Esempio n. 2
0
        private void SplitIfTooLarge(XFastTrie <RBTree> .LeafNode separator)
        {
            if (separator.value.Count <= upperLimit)
            {
                return;
            }
            RBTree newTree = SplitNew(ref separator.value);

            cluster.Add(((RBUIntNode)newTree.LastNode()).key, newTree);
        }
Esempio n. 3
0
 private bool MergeSplit(ref RBTree higher, ref RBTree lower)
 {
     RBTree.Node[] array = new RBTree.Node[higher.Count + lower.Count];
     lower.CopySorted(array, 0);
     higher.CopySorted(array, lower.Count);
     if (array.Length > upperLimit)
     {
         lower  = RBUtils.FromSortedList(array, 0, array.Length >> 1);
         higher = RBUtils.FromSortedList(array, (array.Length >> 1) + 1, array.Length - 1);
         return(true);
     }
     else
     {
         higher = RBUtils.FromSortedList(array, 0, array.Length - 1);
         return(false);
     }
 }
Esempio n. 4
0
            internal static RBTree FromSortedList(RBTree.Node[] list, int start, int stop)
            {
                RBTree tree   = new RBTree(new RBUIntNodeHelper());
                int    length = stop - start + 1;

                if (start == stop)
                {
                    return(tree);
                }
                int maxDepth = BitHacks.Power2MSB(BitHacks.RoundToPower((uint)(length + 1))) - 1;

                tree.root         = list[start + (length >> 1)];
                tree.root.IsBlack = true;
                tree.root.Size    = (uint)length;
                RBInsertChildren(tree.root, true, 1, maxDepth, list, start, start + (length >> 1) - 1);
                RBInsertChildren(tree.root, false, 1, maxDepth, list, start + (length >> 1) + 1, stop);
                return(tree);
            }
Esempio n. 5
0
        private void AddChecked(uint key, T value, bool overwrite)
        {
            var separator = Separator(key);

            if (separator == null)
            {
                // add first element
                RBTree newTree = new RBTree(Node.Helper);
                newTree.root = new RBUIntNode(key, value)
                {
                    IsBlack = true
                };
                cluster.Add(BitHacks.MaxValue(cluster.width), newTree);
                return;
            }
            RBUIntNode newNode  = new RBUIntNode(key, value);
            RBUIntNode interned = (RBUIntNode)separator.value.Intern(key, newNode);

            if (interned != newNode)
            {
                if (overwrite)
                {
                    interned.value = value;
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            else
            {
                count++;
                version++;
            }
            SplitIfTooLarge(separator);
        }
Esempio n. 6
0
 public static RBTree.Node FirstNode(this RBTree tree)
 {
     return(FirstNode(tree.root));
 }
Esempio n. 7
0
 public static RBTree.Node[] ToSortedArray(this RBTree tree)
 {
     RBTree.Node[] array = new RBTree.Node[tree.Count];
     CopySorted(tree, array, 0);
     return(array);
 }
Esempio n. 8
0
 public static void CopySorted(this RBTree tree, RBTree.Node[] array, int offset)
 {
     InOrderAdd(tree.root, array, offset);
 }
Esempio n. 9
0
 public static RBTree.Node LastNode(this RBTree tree)
 {
     return(LastNode(tree.root));
 }
Esempio n. 10
0
 // removes new RBTree from the old tree
 internal static RBTree SplitNew(ref RBTree tree)
 {
     RBTree.Node[] nodes = tree.ToSortedArray();
     tree = RBUtils.FromSortedList(nodes, (nodes.Length >> 1), nodes.Length - 1);
     return(RBUtils.FromSortedList(nodes, 0, (nodes.Length >> 1) - 1));
 }
Esempio n. 11
0
 public Node(uint key, T value)
 {
     tree = new RBTree(Helper);
     tree.Intern(key, new RBUIntNode(key, value));
 }
Esempio n. 12
0
 public void Dispose()
 {
     tree     = null;
     pennants = null;
 }
Esempio n. 13
0
 internal NodeEnumerator(RBTree tree, Stack <Node> init_pennants)
     : this(tree)
 {
     this.init_pennants = init_pennants;
 }
Esempio n. 14
0
 internal NodeEnumerator(RBTree tree)
     : this()
 {
     this.tree = tree;
     version   = tree.version;
 }