containers.ttree
T-Tree.
License
-
Declaration
structTTree(T, Allocator = Mallocator, bool allowDuplicates = false, alias less = "a < b", bool supportGC = shouldAddGCRange!T, size_t cacheLineSize = 64);Implements a binary search tree with multiple items per tree node.
Discussion
T-tree Nodes are (by default) sized to fit within a 64-byte cache line. The number of items stored per node can be read from the
nodeCapacityfield. Each node has 0, 1, or 2 children. Each node has between 1 andnodeCapacityitems, or it hasnodeCapacityitems and 0 or more children.Parameters
Tthe element type
Allocatorthe allocator to use. Defaults to
Mallocator.allowDuplicatesif
true, duplicate values will be allowed in the treelessthe comparitor function to use
supportGCtrueif the container should support holding references to GC-allocated memory.cacheLineSizeNodes will be sized to fit within this number of bytes.
See Also
-
Declaration
this();No default construction if an allocator must be provided.
-
Declaration
this(Allocatorallocator);Use
to allocate and free nodes in the tree.allocator -
Declaration
voidclear();Removes all elements from the tree.
-
Declaration
voidopOpAssign(string op)(Tvalue) if (op == "~");tree ~= item operator overload.
-
Declaration
@safe size_tinsert(Tvalue, booloverwrite= false);
size_tinsert(R)(Rr, booloverwrite= false) if (isInputRange!R && is(ElementType!R == T));
size_tinsert(T[]values, booloverwrite= false);
aliasinsertAnywhere= insert;
aliasput= insert;Inserts the given
value(s) into the tree.Discussion
This is not a stable
insert. You will get strange results if youinsertinto a tree while iterating over it.Parameters
Tvaluethe
valuetoinsertbooloverwriteif
truethe givenwill replace the first item in the tree that is equivalent (That is greater-than and less-than are bothvaluefalse) to. This is useful in cases where opCmp and opEquals forvalueTtype have different meanings. For example, if the element type is a circle that has a position and a color, the circle could implementopCmpto sort by color, and callingwithinsertset tooverwritetruewould allow you to update the position of the circle with a certain color in the tree.Return Value
the number of
valuesadded. -
Declaration
boolremove(Tvalue, void delegate(T)cleanup= null);Removes a single
valuefrom the tree, or does nothing.Discussion
If
allowDuplicatesistrueonly a single element that is equivalent to the givenwill be removed. Which of these elements is removed is not defined.valueParameters
Tvaluea
valueequal to the one to be removedvoid delegate(T)cleanupa function that should be run on the removed item
Retuns:
trueif anyvaluewas removed -
Declaration
const @nogc @safe boolcontains(Tvalue);Return Value
trueif the tree conains This page contains documentation for the EMSI containers library. Use the package index on the left to explore the documentation. the givenvalue -
Declaration
const pure nothrow @nogc @property @safe size_tlength();Return Value
the number of elements in the tree.
-
Declaration
const pure nothrow @nogc @property @safe boolempty();Return Value
trueif the tree isempty. -
Declaration
inout @nogc @trusted autoopSlice(this This)();Return Value
a range over the tree. Do not insert into the tree while iterating because you may iterate over the same value multiple times or skip some values entirely.
-
Declaration
inout @trusted autolowerBound(this This)(inout Tvalue);Return Value
a range of elements which are less than
value. -
Declaration
inout @trusted autoequalRange(this This)(inout Tvalue);Return Value
a range of elements which are equivalent (though not necessarily equal) to
value. -
Declaration
inout @trusted autoupperBound(this This)(inout Tvalue);Return Value
a range of elements which are greater than
value. -
Declaration
inout pure @property @trusted inout(T)front(this This)();Return Value
the first element in the tree.
-
Declaration
inout pure @property @trusted inout(T)back(this This)();Return Value
the last element in the tree.
-
Declaration
structRange(ThisT);Tree range
-
Declaration
const @nogc @property ETfront();
const pure nothrow @nogc @property @safe boolempty();
voidpopFront();Standard range operations
-
-