libgoatvr

annotate src/rbtree.h @ 25:bb85be761b50

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