rev |
line source |
nuclear@16
|
1 #ifndef RBTREE_H_
|
nuclear@16
|
2 #define RBTREE_H_
|
nuclear@16
|
3
|
nuclear@16
|
4 struct rbtree;
|
nuclear@16
|
5
|
nuclear@16
|
6
|
nuclear@16
|
7 struct rbnode {
|
nuclear@16
|
8 void *key, *data;
|
nuclear@16
|
9 int red;
|
nuclear@16
|
10 struct rbnode *left, *right;
|
nuclear@16
|
11 struct rbnode *next; /* for iterator stack */
|
nuclear@16
|
12 };
|
nuclear@16
|
13
|
nuclear@16
|
14
|
nuclear@16
|
15 typedef void *(*rb_alloc_func_t)(size_t);
|
nuclear@16
|
16 typedef void (*rb_free_func_t)(void*);
|
nuclear@16
|
17
|
nuclear@16
|
18 typedef int (*rb_cmp_func_t)(const void*, const void*);
|
nuclear@16
|
19 typedef void (*rb_del_func_t)(struct rbnode*, void*);
|
nuclear@16
|
20
|
nuclear@16
|
21 #define RB_KEY_ADDR (rb_cmp_func_t)(0)
|
nuclear@16
|
22 #define RB_KEY_INT (rb_cmp_func_t)(1)
|
nuclear@16
|
23 #define RB_KEY_STRING (rb_cmp_func_t)(3)
|
nuclear@16
|
24
|
nuclear@16
|
25
|
nuclear@16
|
26 #ifdef __cplusplus
|
nuclear@16
|
27 extern "C" {
|
nuclear@16
|
28 #endif
|
nuclear@16
|
29
|
nuclear@16
|
30 struct rbtree *rb_create(rb_cmp_func_t cmp_func);
|
nuclear@16
|
31 void rb_free(struct rbtree *rb);
|
nuclear@16
|
32
|
nuclear@16
|
33 int rb_init(struct rbtree *rb, rb_cmp_func_t cmp_func);
|
nuclear@16
|
34 void rb_destroy(struct rbtree *rb);
|
nuclear@16
|
35
|
nuclear@16
|
36 void rb_set_allocator(struct rbtree *rb, rb_alloc_func_t alloc, rb_free_func_t free);
|
nuclear@16
|
37 void rb_set_compare_func(struct rbtree *rb, rb_cmp_func_t func);
|
nuclear@16
|
38 void rb_set_delete_func(struct rbtree *rb, rb_del_func_t func, void *cls);
|
nuclear@16
|
39 /* TODO add user deep copy function */
|
nuclear@16
|
40
|
nuclear@16
|
41 void rb_clear(struct rbtree *rb);
|
nuclear@16
|
42 int rb_copy(struct rbtree *dest, struct rbtree *src);
|
nuclear@16
|
43
|
nuclear@16
|
44 int rb_size(struct rbtree *rb);
|
nuclear@16
|
45
|
nuclear@16
|
46 int rb_insert(struct rbtree *rb, void *key, void *data);
|
nuclear@16
|
47 int rb_inserti(struct rbtree *rb, int key, void *data);
|
nuclear@16
|
48
|
nuclear@16
|
49 int rb_delete(struct rbtree *rb, void *key);
|
nuclear@16
|
50 int rb_deletei(struct rbtree *rb, int key);
|
nuclear@16
|
51
|
nuclear@16
|
52 struct rbnode *rb_find(struct rbtree *rb, void *key);
|
nuclear@16
|
53 struct rbnode *rb_findi(struct rbtree *rb, int key);
|
nuclear@16
|
54
|
nuclear@16
|
55 void rb_foreach(struct rbtree *rb, void (*func)(struct rbnode*, void*), void *cls);
|
nuclear@16
|
56
|
nuclear@16
|
57 struct rbnode *rb_root(struct rbtree *rb);
|
nuclear@16
|
58
|
nuclear@16
|
59 void rb_begin(struct rbtree *rb);
|
nuclear@16
|
60 struct rbnode *rb_next(struct rbtree *rb);
|
nuclear@16
|
61
|
nuclear@16
|
62 void *rb_node_key(struct rbnode *node);
|
nuclear@16
|
63 int rb_node_keyi(struct rbnode *node);
|
nuclear@16
|
64 void *rb_node_data(struct rbnode *node);
|
nuclear@16
|
65
|
nuclear@16
|
66 #ifdef __cplusplus
|
nuclear@16
|
67 }
|
nuclear@16
|
68 #endif
|
nuclear@16
|
69
|
nuclear@16
|
70
|
nuclear@16
|
71 #endif /* RBTREE_H_ */
|