copyright 2010- Andrei Alexandrescu. All rights reserved by the respective holders.
License
(See accompanying file LICENSE_1_0.txt or copy at boost.org/LICENSE_1_0.txt).
This module implements a red-black tree container.
This module is a submodule of std.container.
Source: std/container/rbtree.d
copyright 2010- Andrei Alexandrescu. All rights reserved by the respective holders.
(See accompanying file LICENSE_1_0.txt or copy at boost.org/LICENSE_1_0.txt).
private Node _leftprivate Node _rightprivate Node _parentV valueThe value held by this nodeColor colorThe color of the node.Node left(return scope Node newNode) @property @trustedSet the left child. Also updates the new child's parent node. This does not update the previous child.Node right(return scope Node newNode) @property @trustedSet the right child. Also updates the new child's parent node. This does not update the previous child.Node rotateR()Rotate right. This performs the following operations: - The left child becomes the parent of this node. - This node becomes the new parent's right child. - The old right child of the new parent be...Node rotateL()Rotate left. This performs the following operations: - The right child becomes the parent of this node. - This node becomes the new parent's left child. - The old left child of the new parent beco...void setColor(Node end)Set the color of the node after it is inserted. This performs an update to the whole tree, possibly rotating nodes to keep the Red-Black properties correct. This is an O(lg(n)) operation, where n...ColorEnumeration determining what color the node is. Null nodes are assumed to be black.Implementation of a red-black tree container.
All inserts, removes, searches, and any function in general has complexity of lg(n).
To use a different comparison than "a < b", pass a different operator string that can be used by binaryFun, or pass in a function, delegate, functor, or any type where less(a, b) results in a bool value.
Note that less should produce a strict ordering. That is, for two unequal elements a and b, less(a, b) == !less(b, a). less(a, a) should always equal false.
Care should also be taken to not modify elements in the tree (e.g. via front / back, which return by ref) in a way which would affect the order defined by the less predicate.
If allowDuplicates is set to true, then inserting the same element more than once continues to add more elements. If it is false, duplicate elements are ignored on insertion. If duplicates are allowed, then new elements are inserted after all existing duplicate elements.
void _setup()bool _add(return scope Elem n)bool empty() @property constCheck if any elements exist in the container. Returns `false` if at least one element exists.RedBlackTree dup() @propertyDuplicate this container. The resulting container contains a shallow copy of the elements.bool opBinaryRight(string op)(Elem e) if (op == "in") const`in` operator. Check to see if the given element exists in the container.bool opEquals(Object rhs)Compares two trees for equality.size_t toHash() nothrow @safeGenerates a hash for the tree. Note that with a custom comparison function it may not hold that if two rbtrees are equal, the hashes of the trees will be equal.void clear()Removes all elements from the container.size_t stableInsert(Stuff)(Stuff stuff) if (isImplicitlyConvertible!(Stuff, Elem))Insert a single element in the container. Note that this does not invalidate any ranges currently iterating the container.size_t stableInsert(Stuff)(scope Stuff stuff) if (isInputRange!Stuff &&
isImplicitlyConvertible!(ElementType!Stuff, Elem))Insert a range of elements in the container. Note that this does not invalidate any ranges currently iterating the container.Elem removeAny()Remove an element from the container and return its value.void removeFront()Remove the front element from the container.void removeBack()Remove the back element from the container.size_t removeKey(U...)(U elems) if (allSatisfy!(isImplicitlyConvertibleToElem, U))Removes elements from the container that are equal to the given values according to the less comparator. One element is removed for each value given which is in the container. If `allowDuplicates` ...size_t removeKey(Stuff)(Stuff stuff) if (isInputRange!Stuff &&
isImplicitlyConvertible!(ElementType!Stuff, Elem) &&
!isDynamicArray!Stuff)DittoRange upperBound(Elem e)Get a range from the container with all elements that are > e according to the less comparatorRange lowerBound(Elem e)Get a range from the container with all elements that are < e according to the less comparatorauto equalRange(this This)(Elem e)Get a range from the container with all elements that are == e according to the less comparatorthis(Elem[] elems...)Constructor. Pass in an array of elements, or individual elements to initialize the tree with.this(Stuff stuff)Constructor. Pass in a range of elements to initialize the tree with.this()isImplicitlyConvertibleToElem(U)auto redBlackTree(E)(E[] elems...)Convenience function for creating a `RedBlackTree!E` from a list of values.auto redBlackTree(alias less, E)(E[] elems...) if (is(typeof(binaryFun!less(E.init, E.init))))Dittoauto redBlackTree(alias less, bool allowDuplicates, E)(E[] elems...) if (is(typeof(binaryFun!less(E.init, E.init))))Dittoauto redBlackTree(bool allowDuplicates, Stuff)(Stuff range) if (isInputRange!Stuff && !isArray!(Stuff))Dittoauto redBlackTree(alias less, Stuff)(Stuff range) if ( is(typeof(binaryFun!less((ElementType!Stuff).init, (ElementType!Stuff).init)))
&& isInputRange!Stuff && !isArray!(Stuff))Dittoauto redBlackTree(alias less, bool allowDuplicates, Stuff)(Stuff range) if ( is(typeof(binaryFun!less((ElementType!Stuff).init, (ElementType!Stuff).init)))
&& isInputRange!Stuff && !isArray!(Stuff))Ditto