TreeMap

Implements an AVL tree backed treemap. Intended to used as an alternative to D's own associative array. If E set to void, then it works more like a regular tree datastructure (as a tree set), and can be indexed with any type K has an opCmp override. nogcIndexing changes the behavior of opIndex if no match is found. If set to true, indexing returns the default value if no match found, which will need some design consideration. If set to false, indexing throws an exception if no match found. Nodes should have the lesser elements on the left side, but this behavior can somewhat changed with alias less.

struct TreeMap (
K
E
bool nogcIndexing = true
alias less = "a < b"
) {}

Constructors

this
this(R src)

Creates a treeset from a preexisting range.

Members

Aliases

remove
alias remove = removeByElem
Undocumented in source.

Functions

has
bool has(K key)

Returns true if the treemap has the key.

has
bool has(K key)

Returns true if the treemap has the key.

has
bool has(T key)

Returns true if the element exists within the set, false otherwise.

hasRange
size_t hasRange(R range)

Returns the amount of elements found in the set.

opApply
int opApply(int delegate(ref E) dg)

Implements a simple left-to-right tree traversal.

opApply
int opApply(int delegate(K, ref E) dg)

Implements a simple left-to-right tree traversal.

opApply
int opApply(int delegate(K) dg)

Implements a simple left-to-right tree traversal by depth.

opApplyReverse
int opApplyReverse(int delegate(ref E) dg)

Implements a simple right-to-left tree traversal.

opApplyReverse
int opApplyReverse(int delegate(K, ref E) dg)

Implements a simple right-to-left tree traversal.

opApplyReverse
int opApplyReverse(int delegate(K) dg)

Implements a simple right-to-left tree traversal.

opBinary
TreeMap!(K, E, nogcIndexing, less) opBinary(R rhs)

Set operators. Enables math operations on sets, like unions and intersections. Could work on ranges in general as long as they implement some basic functions, like iteration.

opBinaryRight
auto opBinaryRight(K key)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinaryRight
auto opBinaryRight(K key)
Undocumented in source. Be warned that the author may not have intended to support it.
opBinaryRight
auto opBinaryRight(T key)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
E opIndex(K key)

@nogc capable indexing. Returns the found element if match found. Returns E.init if match not found.

opIndex
E opIndex(K key)

Indexing function that relies on the GC, and throws if no match found Can be indexed with any type of value as long as K.opCmp supports it. Returns the found element if match found.

opIndex
K opIndex(T key)

@nogc capable indexing. Can be indexed with any type of value as long as K.opCmp supports it and alias less hasn't been changed. Returns the found element if match found. Returns E.init if match not found.

opIndex
K opIndex(T key)

Indexing function that relies on the GC, and throws if no match found Can be indexed with any type of value as long as K.opCmp supports it and alias less hasn't been changed. Returns the found element if match found.

opIndexAssign
auto opIndexAssign(E elem, K key)

Assigns a value to the given key. If key found, the value will be overwritten without node insertion. If key isn't found, a new node will be inserted.

opOpAssign
TreeMap!(K, E, nogcIndexing, less) opOpAssign(K value)

Set operators.

opOpAssign
TreeMap!(K, E, nogcIndexing, less) opOpAssign(R range)

Set operators.

ptrOf
E* ptrOf(K key)

Returns the pointer of the element, or null if key not found.

put
K put(K key)

Puts an element into the treeset

rebalance
void rebalance()

Rebalances the tree.

remove
E remove(K key)

Removes an item by key. Returns the removed item if found, or E.init if not.

removeByElem
K removeByElem(K key)

Removes an item by key. Returns the removed item if found, or K.init if not.

toString
string toString()

Returns the string representation of the tree.

Properties

arrayOf
K[] arrayOf [@property getter]

Returns an array representation of the set.

length
size_t length [@property getter]

Returns the number of currently held elements within the tree.

Static functions

makeFuncTM
string makeFuncTM()

Generates an opApply and opApplyReverse pair for a TreeMap with the supplied attributes

makeFuncTS
string makeFuncTS()

Generates an opApply and opApplyReverse pair for a TreeMap with the supplied attributes

Meta