csRedBlackTree< K > Class Template Reference
[Containers]
A red-black-tree.
More...
#include <csutil/redblacktree.h>
Classes | |
class | ConstIterator |
Const iterator for tree. More... | |
class | ConstReverseIterator |
Const reverse iterator for tree. More... | |
class | Iterator |
Const iterator for tree. More... | |
struct | Node |
A node in the tree. More... | |
Public Member Functions | |
bool | Contains (const K &key) const |
Check whether a key is in the tree. | |
csRedBlackTree (size_t allocatorBlockSize=4096) | |
Construct a new tree. | |
bool | Delete (const K &key) |
Delete a key. | |
void | DeleteAll () |
Delete all keys. | |
bool | DeleteExact (const K *key) |
Delete a specific instance of a key. | |
void | Empty () |
Delete all the keys. (Idiomatic alias for DeleteAll().). | |
bool | In (const K &key) const |
Check whether a key is in the tree. | |
const K * | Insert (const K &key) |
Insert a key. | |
bool | IsEmpty () const |
Returns whether this tree has no nodes. | |
template<typename K2 > | |
const K & | Find (const K2 &other, const K &fallback) const |
Locate key that is equal to other. | |
template<typename K2 > | |
const K * | Find (const K2 &other) const |
Locate key that is equal to other. | |
template<typename K2 > | |
const K & | FindSmallestGreaterEqual (const K2 &other, const K &fallback) const |
Locate smallest key greater or equal to other. | |
template<typename K2 > | |
const K * | FindSmallestGreaterEqual (const K2 &other) const |
Locate smallest key greater or equal to other. | |
template<typename CB > | |
void | TraverseInOrder (CB &callback) const |
Traverse tree. | |
Protected Member Functions | |
void | DeleteFixup (Node *node, Node *nilParent) |
Fix up the RB tree after a deletion. | |
void | DeleteNode (Node *node) |
Delete a node from the tree. | |
void | InsertFixup (Node *node) |
Fix up the RB tree after an insert. | |
bool | IsBlack (Node *node) const |
Check whether a node is black. Note that 0 nodes are by definition black. | |
bool | IsRed (Node *node) const |
Check whether a node is red. | |
Node * | LocateNode (Node *node, const K &key) const |
Find the node for a key. | |
Node * | LocateNodeExact (Node *node, const K *key) const |
Find the node which has a given instance of a key. | |
void | RecursiveCopy (Node *&to, Node *parent, const Node *from) |
Duplicate a subtree. | |
Node * | RecursiveInsert (Node *parent, Node *&node, const K &key) |
Locate the place where a new node needs to be inserted. | |
template<typename CB > | |
void | RecursiveTraverseInOrder (Node *node, CB &callback) const |
Traverse tree. | |
void | RotateLeft (Node *pivot) |
Left-rotate subtree around 'pivot'. | |
void | RotateRight (Node *pivot) |
Right-rotate subtree around 'pivot'. | |
template<typename K2 > | |
K & | Find (const K2 &other, K &fallback) |
Locate key that is equal to 'other'. | |
template<typename K2 > | |
K * | Find (const K2 &other) |
Locate key that is equal to 'other'. | |
template<typename K2 > | |
K & | RecursiveFind (Node *node, const K2 &other, K &fallback) |
Locate key that is equal to 'other'. | |
template<typename K2 > | |
const K & | RecursiveFind (Node *node, const K2 &other, const K &fallback) const |
Locate key that is equal to 'other'. | |
template<typename K2 > | |
K * | RecursiveFind (Node *node, const K2 &other) |
Locate key that is equal to 'other'. | |
template<typename K2 > | |
const K * | RecursiveFind (Node *node, const K2 &other) const |
Locate key that is equal to 'other'. | |
template<typename K2 > | |
const K & | RecursiveFindSGE (Node *node, const K2 &other, const K &fallback) const |
Locate key that is equal to 'other'. | |
template<typename K2 > | |
const K * | RecursiveFindSGE (Node *node, const K2 &other) const |
Locate key that is equal to 'other'. | |
Static Protected Member Functions | |
static Node * | Predecessor (const Node *node) |
Return largest node with a key smaller than 'node's. | |
static Node * | Successor (const Node *node) |
Return smallest node with a key greater than 'node's. | |
class | ConstIterator |
Delete the 'next' element pointed at by the iterator. | |
class | ConstReverseIterator |
Delete the 'next' element pointed at by the iterator. | |
class | Iterator |
Delete the 'next' element pointed at by the iterator. | |
void | Delete (Iterator &it) |
Delete the 'next' element pointed at by the iterator. | |
Iterator | GetIterator () |
Get an iterator for iterating over the entire tree. | |
ConstIterator | GetIterator () const |
Get an iterator for iterating over the entire tree. | |
ConstReverseIterator | GetReverseIterator () |
Get an iterator for iterating over the entire tree. |
Detailed Description
template<typename K>
class csRedBlackTree< K >
A red-black-tree.
- Remarks:
- Does not allow duplicate keys.
Uses csComparator<> for key comparisons.
Only stores keys. If you need a key-value-map, look at csRedBlackTreeMap.
Definition at line 48 of file redblacktree.h.
Constructor & Destructor Documentation
csRedBlackTree< K >::csRedBlackTree | ( | size_t | allocatorBlockSize = 4096 |
) | [inline] |
Construct a new tree.
- Parameters:
-
allocatorBlockSize Block size in bytes used by the internal block allocator for nodes.
Definition at line 530 of file redblacktree.h.
Member Function Documentation
bool csRedBlackTree< K >::Contains | ( | const K & | key | ) | const [inline] |
Check whether a key is in the tree.
- Remarks:
- This is rigidly equivalent to Contains(key), but may be considered more idiomatic by some.
Definition at line 584 of file redblacktree.h.
void csRedBlackTree< K >::Delete | ( | Iterator & | it | ) | [inline] |
Delete the 'next' element pointed at by the iterator.
- Remarks:
- Will repoint the iterator to the following element.
Definition at line 767 of file redblacktree.h.
bool csRedBlackTree< K >::Delete | ( | const K & | key | ) | [inline] |
Delete a key.
- Returns:
- Whether the deletion was successful. Fails if the key is not in the tree.
Definition at line 555 of file redblacktree.h.
void csRedBlackTree< K >::DeleteAll | ( | ) | [inline] |
Delete all keys.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 616 of file redblacktree.h.
bool csRedBlackTree< K >::DeleteExact | ( | const K * | key | ) | [inline] |
Delete a specific instance of a key.
- Returns:
- Whether the deletion was successful. Fails if the key is not in the tree.
Definition at line 567 of file redblacktree.h.
void csRedBlackTree< K >::DeleteFixup | ( | Node * | node, | |
Node * | nilParent | |||
) | [inline, protected] |
void csRedBlackTree< K >::DeleteNode | ( | Node * | node | ) | [inline, protected] |
void csRedBlackTree< K >::Empty | ( | ) | [inline] |
Delete all the keys. (Idiomatic alias for DeleteAll().).
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 622 of file redblacktree.h.
const K& csRedBlackTree< K >::Find | ( | const K2 & | other, | |
const K & | fallback | |||
) | const [inline] |
const K* csRedBlackTree< K >::Find | ( | const K2 & | other | ) | const [inline] |
K& csRedBlackTree< K >::Find | ( | const K2 & | other, | |
K & | fallback | |||
) | [inline, protected] |
K* csRedBlackTree< K >::Find | ( | const K2 & | other | ) | [inline, protected] |
const K& csRedBlackTree< K >::FindSmallestGreaterEqual | ( | const K2 & | other, | |
const K & | fallback | |||
) | const [inline] |
const K* csRedBlackTree< K >::FindSmallestGreaterEqual | ( | const K2 & | other | ) | const [inline] |
Iterator csRedBlackTree< K >::GetIterator | ( | ) | [inline] |
Get an iterator for iterating over the entire tree.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 758 of file redblacktree.h.
ConstIterator csRedBlackTree< K >::GetIterator | ( | ) | const [inline] |
Get an iterator for iterating over the entire tree.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 703 of file redblacktree.h.
ConstReverseIterator csRedBlackTree< K >::GetReverseIterator | ( | ) | [inline] |
Get an iterator for iterating over the entire tree.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 711 of file redblacktree.h.
bool csRedBlackTree< K >::In | ( | const K & | key | ) | const [inline] |
const K* csRedBlackTree< K >::Insert | ( | const K & | key | ) | [inline] |
Insert a key.
- Returns:
- A pointer to the copy of the key stored in the tree, or 0 if the key already exists.
Definition at line 543 of file redblacktree.h.
void csRedBlackTree< K >::InsertFixup | ( | Node * | node | ) | [inline, protected] |
bool csRedBlackTree< K >::IsBlack | ( | Node * | node | ) | const [inline, protected] |
Check whether a node is black. Note that 0 nodes are by definition black.
Definition at line 144 of file redblacktree.h.
bool csRedBlackTree< K >::IsEmpty | ( | ) | const [inline] |
Returns whether this tree has no nodes.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 624 of file redblacktree.h.
bool csRedBlackTree< K >::IsRed | ( | Node * | node | ) | const [inline, protected] |
Node* csRedBlackTree< K >::LocateNode | ( | Node * | node, | |
const K & | key | |||
) | const [inline, protected] |
Node* csRedBlackTree< K >::LocateNodeExact | ( | Node * | node, | |
const K * | key | |||
) | const [inline, protected] |
static Node* csRedBlackTree< K >::Predecessor | ( | const Node * | node | ) | [inline, static, protected] |
void csRedBlackTree< K >::RecursiveCopy | ( | Node *& | to, | |
Node * | parent, | |||
const Node * | from | |||
) | [inline, protected] |
K& csRedBlackTree< K >::RecursiveFind | ( | Node * | node, | |
const K2 & | other, | |||
K & | fallback | |||
) | [inline, protected] |
const K& csRedBlackTree< K >::RecursiveFind | ( | Node * | node, | |
const K2 & | other, | |||
const K & | fallback | |||
) | const [inline, protected] |
K* csRedBlackTree< K >::RecursiveFind | ( | Node * | node, | |
const K2 & | other | |||
) | [inline, protected] |
const K* csRedBlackTree< K >::RecursiveFind | ( | Node * | node, | |
const K2 & | other | |||
) | const [inline, protected] |
const K& csRedBlackTree< K >::RecursiveFindSGE | ( | Node * | node, | |
const K2 & | other, | |||
const K & | fallback | |||
) | const [inline, protected] |
const K* csRedBlackTree< K >::RecursiveFindSGE | ( | Node * | node, | |
const K2 & | other | |||
) | const [inline, protected] |
Node* csRedBlackTree< K >::RecursiveInsert | ( | Node * | parent, | |
Node *& | node, | |||
const K & | key | |||
) | [inline, protected] |
Locate the place where a new node needs to be inserted.
Definition at line 83 of file redblacktree.h.
void csRedBlackTree< K >::RecursiveTraverseInOrder | ( | Node * | node, | |
CB & | callback | |||
) | const [inline, protected] |
void csRedBlackTree< K >::RotateLeft | ( | Node * | pivot | ) | [inline, protected] |
void csRedBlackTree< K >::RotateRight | ( | Node * | pivot | ) | [inline, protected] |
static Node* csRedBlackTree< K >::Successor | ( | const Node * | node | ) | [inline, static, protected] |
Return smallest node with a key greater than 'node's.
Definition at line 359 of file redblacktree.h.
void csRedBlackTree< K >::TraverseInOrder | ( | CB & | callback | ) | const [inline] |
Traverse tree.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 629 of file redblacktree.h.
Friends And Related Function Documentation
friend class ConstIterator [friend] |
Delete the 'next' element pointed at by the iterator.
- Remarks:
- Will repoint the iterator to the following element.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 666 of file redblacktree.h.
friend class ConstReverseIterator [friend] |
Delete the 'next' element pointed at by the iterator.
- Remarks:
- Will repoint the iterator to the following element.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 698 of file redblacktree.h.
friend class Iterator [friend] |
Delete the 'next' element pointed at by the iterator.
- Remarks:
- Will repoint the iterator to the following element.
Reimplemented in csRedBlackTreeMap< K, T >.
Definition at line 753 of file redblacktree.h.
The documentation for this class was generated from the following file:
- csutil/redblacktree.h
Generated for Crystal Space 1.4.0 by doxygen 1.5.8