kern

view src/rbtree.h @ 68:0a205396e1a0

- added a generic red-black tree data structure - added a VM map as an red-black tree of vm_pages in the process structure - constructed the vm map of the memory passed by the kernel initially to the first process.
author John Tsiombikas <nuclear@mutantstargoat.com>
date Mon, 10 Oct 2011 04:16:01 +0300
parents
children b45e2d5f0ae1
line source
1 #ifndef RBTREE_H_
2 #define RBTREE_H_
4 struct rbtree;
5 struct rbnode;
8 typedef void *(*rb_alloc_func_t)(size_t);
9 typedef void (*rb_free_func_t)(void*);
11 typedef int (*rb_cmp_func_t)(void*, void*);
12 typedef void (*rb_del_func_t)(struct rbnode*, void*);
15 struct rbtree {
16 struct rbnode *root;
18 rb_alloc_func_t alloc;
19 rb_free_func_t free;
21 rb_cmp_func_t cmp;
22 rb_del_func_t del;
23 void *del_cls;
25 struct rbnode *rstack, *iter;
26 };
29 struct rbnode {
30 void *key, *data;
31 int red;
32 struct rbnode *left, *right;
33 struct rbnode *next; /* for iterator stack */
34 };
36 #define RB_KEY_ADDR (rb_cmp_func_t)(0)
37 #define RB_KEY_INT (rb_cmp_func_t)(1)
38 #define RB_KEY_STRING (rb_cmp_func_t)(3)
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
45 struct rbtree *rb_create(rb_cmp_func_t cmp_func);
46 void rb_free(struct rbtree *rb);
48 int rb_init(struct rbtree *rb, rb_cmp_func_t cmp_func);
49 void rb_destroy(struct rbtree *rb);
51 void rb_set_allocator(struct rbtree *rb, rb_alloc_func_t alloc, rb_free_func_t free);
52 void rb_set_compare_func(struct rbtree *rb, rb_cmp_func_t func);
53 void rb_set_delete_func(struct rbtree *rb, rb_del_func_t func, void *cls);
55 int rb_size(struct rbtree *rb);
57 int rb_insert(struct rbtree *rb, void *key, void *data);
58 int rb_inserti(struct rbtree *rb, int key, void *data);
60 int rb_delete(struct rbtree *rb, void *key);
61 int rb_deletei(struct rbtree *rb, int key);
63 void *rb_find(struct rbtree *rb, void *key);
64 void *rb_findi(struct rbtree *rb, int key);
66 void rb_foreach(struct rbtree *rb, void (*func)(struct rbnode*, void*), void *cls);
68 struct rbnode *rb_root(struct rbtree *rb);
70 void rb_begin(struct rbtree *rb);
71 struct rbnode *rb_next(struct rbtree *rb);
73 void *rb_node_key(struct rbnode *node);
74 int rb_node_keyi(struct rbnode *node);
75 void *rb_node_data(struct rbnode *node);
77 #ifdef __cplusplus
78 }
79 #endif
82 #endif /* RBTREE_H_ */