kern
view src/rbtree.h @ 96:07fe6a614185
filesystem
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 15 Dec 2011 04:39:00 +0200 |
parents | b45e2d5f0ae1 |
children |
line source
1 #ifndef RBTREE_H_
2 #define RBTREE_H_
4 #include <stdlib.h> /* for size_t */
6 struct rbtree;
7 struct rbnode;
10 typedef void *(*rb_alloc_func_t)(size_t);
11 typedef void (*rb_free_func_t)(void*);
13 typedef int (*rb_cmp_func_t)(void*, void*);
14 typedef void (*rb_del_func_t)(struct rbnode*, void*);
17 struct rbtree {
18 struct rbnode *root;
20 rb_alloc_func_t alloc;
21 rb_free_func_t free;
23 rb_cmp_func_t cmp;
24 rb_del_func_t del;
25 void *del_cls;
27 struct rbnode *rstack, *iter;
28 };
31 struct rbnode {
32 void *key, *data;
33 int red;
34 struct rbnode *left, *right;
35 struct rbnode *next; /* for iterator stack */
36 };
38 #define RB_KEY_ADDR (rb_cmp_func_t)(0)
39 #define RB_KEY_INT (rb_cmp_func_t)(1)
40 #define RB_KEY_STRING (rb_cmp_func_t)(3)
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
47 struct rbtree *rb_create(rb_cmp_func_t cmp_func);
48 void rb_free(struct rbtree *rb);
50 int rb_init(struct rbtree *rb, rb_cmp_func_t cmp_func);
51 void rb_destroy(struct rbtree *rb);
53 void rb_clear(struct rbtree *tree);
54 int rb_copy(struct rbtree *dest, struct rbtree *src);
56 void rb_set_allocator(struct rbtree *rb, rb_alloc_func_t alloc, rb_free_func_t free);
57 void rb_set_compare_func(struct rbtree *rb, rb_cmp_func_t func);
58 void rb_set_delete_func(struct rbtree *rb, rb_del_func_t func, void *cls);
60 int rb_size(struct rbtree *rb);
62 int rb_insert(struct rbtree *rb, void *key, void *data);
63 int rb_inserti(struct rbtree *rb, int key, void *data);
65 int rb_delete(struct rbtree *rb, void *key);
66 int rb_deletei(struct rbtree *rb, int key);
68 void *rb_find(struct rbtree *rb, void *key);
69 void *rb_findi(struct rbtree *rb, int key);
71 void rb_foreach(struct rbtree *rb, void (*func)(struct rbnode*, void*), void *cls);
73 struct rbnode *rb_root(struct rbtree *rb);
75 void rb_begin(struct rbtree *rb);
76 struct rbnode *rb_next(struct rbtree *rb);
78 void *rb_node_key(struct rbnode *node);
79 int rb_node_keyi(struct rbnode *node);
80 void *rb_node_data(struct rbnode *node);
83 void rb_dbg_print_tree(struct rbtree *tree);
85 #ifdef __cplusplus
86 }
87 #endif
90 #endif /* RBTREE_H_ */