|
#define | _SYS_TREE_H_ |
|
#define | SPLAY_HEAD(name, type) |
|
#define | SPLAY_INITIALIZER(root) { NULL } |
|
#define | SPLAY_INIT(root) |
|
#define | SPLAY_ENTRY(type) |
|
#define | SPLAY_LEFT(elm, field) (elm)->field.spe_left |
|
#define | SPLAY_RIGHT(elm, field) (elm)->field.spe_right |
|
#define | SPLAY_ROOT(head) (head)->sph_root |
|
#define | SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) |
|
#define | SPLAY_ROTATE_RIGHT(head, tmp, field) |
|
#define | SPLAY_ROTATE_LEFT(head, tmp, field) |
|
#define | SPLAY_LINKLEFT(head, tmp, field) |
|
#define | SPLAY_LINKRIGHT(head, tmp, field) |
|
#define | SPLAY_ASSEMBLE(head, node, left, right, field) |
|
#define | SPLAY_PROTOTYPE(name, type, field, cmp) |
|
#define | SPLAY_GENERATE(name, type, field, cmp) |
|
#define | SPLAY_NEGINF -1 |
|
#define | SPLAY_INF 1 |
|
#define | SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) |
|
#define | SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) |
|
#define | SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) |
|
#define | SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) |
|
#define | SPLAY_MIN(name, x) |
|
#define | SPLAY_MAX(name, x) |
|
#define | SPLAY_FOREACH(x, name, head) |
|
#define | RB_HEAD(name, type) |
|
#define | RB_INITIALIZER(root) { NULL } |
|
#define | RB_INIT(root) |
|
#define | RB_BLACK 0 |
|
#define | RB_RED 1 |
|
#define | RB_ENTRY(type) |
|
#define | RB_LEFT(elm, field) (elm)->field.rbe_left |
|
#define | RB_RIGHT(elm, field) (elm)->field.rbe_right |
|
#define | RB_PARENT(elm, field) (elm)->field.rbe_parent |
|
#define | RB_COLOR(elm, field) (elm)->field.rbe_color |
|
#define | RB_ROOT(head) (head)->rbh_root |
|
#define | RB_EMPTY(head) (RB_ROOT(head) == NULL) |
|
#define | RB_SET(elm, parent, field) |
|
#define | RB_SET_BLACKRED(black, red, field) |
|
#define | RB_AUGMENT(x) do {} while (0) |
|
#define | RB_ROTATE_LEFT(head, elm, tmp, field) |
|
#define | RB_ROTATE_RIGHT(head, elm, tmp, field) |
|
#define | RB_PROTOTYPE(name, type, field, cmp) RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) |
|
#define | RB_PROTOTYPE_STATIC(name, type, field, cmp) RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) |
|
#define | RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) |
|
#define | RB_GENERATE(name, type, field, cmp) RB_GENERATE_INTERNAL(name, type, field, cmp,) |
|
#define | RB_GENERATE_STATIC(name, type, field, cmp) RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) |
|
#define | RB_GENERATE_INTERNAL(name, type, field, cmp, attr) |
|
#define | RB_NEGINF -1 |
|
#define | RB_INF 1 |
|
#define | RB_INSERT(name, x, y) name##_RB_INSERT(x, y) |
|
#define | RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) |
|
#define | RB_FIND(name, x, y) name##_RB_FIND(x, y) |
|
#define | RB_NFIND(name, x, y) name##_RB_NFIND(x, y) |
|
#define | RB_NEXT(name, x, y) name##_RB_NEXT(y) |
|
#define | RB_PREV(name, x, y) name##_RB_PREV(y) |
|
#define | RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) |
|
#define | RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) |
|
#define | RB_FOREACH(x, name, head) |
|
#define | RB_FOREACH_SAFE(x, name, head, y) |
|
#define | RB_FOREACH_REVERSE(x, name, head) |
|
#define | RB_FOREACH_REVERSE_SAFE(x, name, head, y) |
|
- Author
- Niels Provos
- Date
- 2002
- Copyright
- 2-clause BSD License
This file defines data structures for different types of trees: splay trees and red-black trees.
A splay tree is a self-organizing data structure. Every operation on the tree causes a splay to happen. The splay moves the requested node to the root of the tree and partly rebalances it.
This has the benefit that request locality causes faster lookups as the requested nodes move to the top of the tree. On the other hand, every lookup causes memory writes.
The Balance Theorem bounds the total access time for m operations and n inserts on an initially empty tree as O((m + n)lg n). The amortized cost for a sequence of m accesses to a splay tree is O(lg n);
A red-black tree is a binary search tree with the node color as an extra attribute. It fulfills a set of conditions:
- every search path from the root to a leaf consists of the same number of black nodes,
- each red node (except for the root) has a black parent,
- each leaf node is black.
Every operation on a red-black tree is bounded as O(lg n). The maximum height of a red-black tree is 2lg (n+1).