conworlds

annotate src/vr/rbtree.h @ 7:bd8202d6d28d

some progress...
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Aug 2014 16:55:16 +0300
parents
children
rev   line source
nuclear@7 1 /*
nuclear@7 2 rbtree - simple balanced binary search tree (red-black tree) library.
nuclear@7 3 Copyright (C) 2011-2014 John Tsiombikas <nuclear@member.fsf.org>
nuclear@7 4
nuclear@7 5 rbtree is free software, feel free to use, modify, and redistribute it, under
nuclear@7 6 the terms of the 3-clause BSD license. See COPYING for details.
nuclear@7 7 */
nuclear@7 8 #ifndef RBTREE_H_
nuclear@7 9 #define RBTREE_H_
nuclear@7 10
nuclear@7 11 struct rbtree;
nuclear@7 12
nuclear@7 13
nuclear@7 14 struct rbnode {
nuclear@7 15 void *key, *data;
nuclear@7 16 int red;
nuclear@7 17 struct rbnode *left, *right;
nuclear@7 18 struct rbnode *next; /* for iterator stack */
nuclear@7 19 };
nuclear@7 20
nuclear@7 21
nuclear@7 22 typedef void *(*rb_alloc_func_t)(size_t);
nuclear@7 23 typedef void (*rb_free_func_t)(void*);
nuclear@7 24
nuclear@7 25 typedef int (*rb_cmp_func_t)(const void*, const void*);
nuclear@7 26 typedef void (*rb_del_func_t)(struct rbnode*, void*);
nuclear@7 27
nuclear@7 28 #define RB_KEY_ADDR (rb_cmp_func_t)(0)
nuclear@7 29 #define RB_KEY_INT (rb_cmp_func_t)(1)
nuclear@7 30 #define RB_KEY_STRING (rb_cmp_func_t)(3)
nuclear@7 31
nuclear@7 32
nuclear@7 33 #ifdef __cplusplus
nuclear@7 34 extern "C" {
nuclear@7 35 #endif
nuclear@7 36
nuclear@7 37 struct rbtree *rb_create(rb_cmp_func_t cmp_func);
nuclear@7 38 void rb_free(struct rbtree *rb);
nuclear@7 39
nuclear@7 40 int rb_init(struct rbtree *rb, rb_cmp_func_t cmp_func);
nuclear@7 41 void rb_destroy(struct rbtree *rb);
nuclear@7 42
nuclear@7 43 void rb_set_allocator(struct rbtree *rb, rb_alloc_func_t alloc, rb_free_func_t free);
nuclear@7 44 void rb_set_compare_func(struct rbtree *rb, rb_cmp_func_t func);
nuclear@7 45 void rb_set_delete_func(struct rbtree *rb, rb_del_func_t func, void *cls);
nuclear@7 46 /* TODO add user deep copy function */
nuclear@7 47
nuclear@7 48 void rb_clear(struct rbtree *rb);
nuclear@7 49 int rb_copy(struct rbtree *dest, struct rbtree *src);
nuclear@7 50
nuclear@7 51 int rb_size(struct rbtree *rb);
nuclear@7 52
nuclear@7 53 int rb_insert(struct rbtree *rb, void *key, void *data);
nuclear@7 54 int rb_inserti(struct rbtree *rb, int key, void *data);
nuclear@7 55
nuclear@7 56 int rb_delete(struct rbtree *rb, void *key);
nuclear@7 57 int rb_deletei(struct rbtree *rb, int key);
nuclear@7 58
nuclear@7 59 void *rb_find(struct rbtree *rb, void *key);
nuclear@7 60 void *rb_findi(struct rbtree *rb, int key);
nuclear@7 61
nuclear@7 62 void rb_foreach(struct rbtree *rb, void (*func)(struct rbnode*, void*), void *cls);
nuclear@7 63
nuclear@7 64 struct rbnode *rb_root(struct rbtree *rb);
nuclear@7 65
nuclear@7 66 void rb_begin(struct rbtree *rb);
nuclear@7 67 struct rbnode *rb_next(struct rbtree *rb);
nuclear@7 68
nuclear@7 69 void *rb_node_key(struct rbnode *node);
nuclear@7 70 int rb_node_keyi(struct rbnode *node);
nuclear@7 71 void *rb_node_data(struct rbnode *node);
nuclear@7 72
nuclear@7 73 #ifdef __cplusplus
nuclear@7 74 }
nuclear@7 75 #endif
nuclear@7 76
nuclear@7 77
nuclear@7 78 #endif /* RBTREE_H_ */