tinywebd

annotate libtinyweb/src/rbtree.h @ 10:0dd50a23f3dd

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