rayzor

diff src/rbtree.h @ 16:4d87b0aafbb0

forgot to add the redblack tree
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 13 Apr 2014 09:54:51 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/rbtree.h	Sun Apr 13 09:54:51 2014 +0300
     1.3 @@ -0,0 +1,71 @@
     1.4 +#ifndef RBTREE_H_
     1.5 +#define RBTREE_H_
     1.6 +
     1.7 +struct rbtree;
     1.8 +
     1.9 +
    1.10 +struct rbnode {
    1.11 +	void *key, *data;
    1.12 +	int red;
    1.13 +	struct rbnode *left, *right;
    1.14 +	struct rbnode *next;	/* for iterator stack */
    1.15 +};
    1.16 +
    1.17 +
    1.18 +typedef void *(*rb_alloc_func_t)(size_t);
    1.19 +typedef void (*rb_free_func_t)(void*);
    1.20 +
    1.21 +typedef int (*rb_cmp_func_t)(const void*, const void*);
    1.22 +typedef void (*rb_del_func_t)(struct rbnode*, void*);
    1.23 +
    1.24 +#define RB_KEY_ADDR		(rb_cmp_func_t)(0)
    1.25 +#define RB_KEY_INT		(rb_cmp_func_t)(1)
    1.26 +#define RB_KEY_STRING	(rb_cmp_func_t)(3)
    1.27 +
    1.28 +
    1.29 +#ifdef __cplusplus
    1.30 +extern "C" {
    1.31 +#endif
    1.32 +
    1.33 +struct rbtree *rb_create(rb_cmp_func_t cmp_func);
    1.34 +void rb_free(struct rbtree *rb);
    1.35 +
    1.36 +int rb_init(struct rbtree *rb, rb_cmp_func_t cmp_func);
    1.37 +void rb_destroy(struct rbtree *rb);
    1.38 +
    1.39 +void rb_set_allocator(struct rbtree *rb, rb_alloc_func_t alloc, rb_free_func_t free);
    1.40 +void rb_set_compare_func(struct rbtree *rb, rb_cmp_func_t func);
    1.41 +void rb_set_delete_func(struct rbtree *rb, rb_del_func_t func, void *cls);
    1.42 +/* TODO add user deep copy function */
    1.43 +
    1.44 +void rb_clear(struct rbtree *rb);
    1.45 +int rb_copy(struct rbtree *dest, struct rbtree *src);
    1.46 +
    1.47 +int rb_size(struct rbtree *rb);
    1.48 +
    1.49 +int rb_insert(struct rbtree *rb, void *key, void *data);
    1.50 +int rb_inserti(struct rbtree *rb, int key, void *data);
    1.51 +
    1.52 +int rb_delete(struct rbtree *rb, void *key);
    1.53 +int rb_deletei(struct rbtree *rb, int key);
    1.54 +
    1.55 +struct rbnode *rb_find(struct rbtree *rb, void *key);
    1.56 +struct rbnode *rb_findi(struct rbtree *rb, int key);
    1.57 +
    1.58 +void rb_foreach(struct rbtree *rb, void (*func)(struct rbnode*, void*), void *cls);
    1.59 +
    1.60 +struct rbnode *rb_root(struct rbtree *rb);
    1.61 +
    1.62 +void rb_begin(struct rbtree *rb);
    1.63 +struct rbnode *rb_next(struct rbtree *rb);
    1.64 +
    1.65 +void *rb_node_key(struct rbnode *node);
    1.66 +int rb_node_keyi(struct rbnode *node);
    1.67 +void *rb_node_data(struct rbnode *node);
    1.68 +
    1.69 +#ifdef __cplusplus
    1.70 +}
    1.71 +#endif
    1.72 +
    1.73 +
    1.74 +#endif	/* RBTREE_H_ */