| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef RBTREE_H |
| #define RBTREE_H |
|
|
| |
| |
| |
| |
| |
| |
| |
| typedef struct RBTNode |
| { |
| char color; |
| struct RBTNode *left; |
| struct RBTNode *right; |
| struct RBTNode *parent; |
| } RBTNode; |
|
|
| |
| typedef struct RBTree RBTree; |
|
|
| |
| typedef enum RBTOrderControl |
| { |
| LeftRightWalk, |
| RightLeftWalk |
| } RBTOrderControl; |
|
|
| |
| |
| |
| |
| |
| typedef struct RBTreeIterator RBTreeIterator; |
|
|
| struct RBTreeIterator |
| { |
| RBTree *rbt; |
| RBTNode *(*iterate) (RBTreeIterator *iter); |
| RBTNode *last_visited; |
| bool is_over; |
| }; |
|
|
| |
| typedef int (*rbt_comparator) (const RBTNode *a, const RBTNode *b, void *arg); |
| typedef void (*rbt_combiner) (RBTNode *existing, const RBTNode *newdata, void *arg); |
| typedef RBTNode *(*rbt_allocfunc) (void *arg); |
| typedef void (*rbt_freefunc) (RBTNode *x, void *arg); |
|
|
| extern RBTree *rbt_create(Size node_size, |
| rbt_comparator comparator, |
| rbt_combiner combiner, |
| rbt_allocfunc allocfunc, |
| rbt_freefunc freefunc, |
| void *arg); |
|
|
| extern RBTNode *rbt_find(RBTree *rbt, const RBTNode *data); |
| extern RBTNode *rbt_find_great(RBTree *rbt, const RBTNode *data, bool equal_match); |
| extern RBTNode *rbt_find_less(RBTree *rbt, const RBTNode *data, bool equal_match); |
| extern RBTNode *rbt_leftmost(RBTree *rbt); |
|
|
| extern RBTNode *rbt_insert(RBTree *rbt, const RBTNode *data, bool *isNew); |
| extern void rbt_delete(RBTree *rbt, RBTNode *node); |
|
|
| extern void rbt_begin_iterate(RBTree *rbt, RBTOrderControl ctrl, |
| RBTreeIterator *iter); |
| extern RBTNode *rbt_iterate(RBTreeIterator *iter); |
|
|
| #endif |
|
|