rbtree

changeset 15:1b77b72688fe tip

- fixed bug in rb_init making it ignore comparison functions other than the builtin - fixed rb_find and rb_findi return type, which should be struct rbnode*, not void*
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Nov 2014 11:00:27 +0200
parents 1b8a3a6088b6
children
files src/rbtree.c src/rbtree.h
diffstat 2 files changed, 8 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/src/rbtree.c	Sun Nov 02 10:56:08 2014 +0200
     1.2 +++ b/src/rbtree.c	Sun Nov 02 11:00:27 2014 +0200
     1.3 @@ -62,12 +62,14 @@
     1.4  {
     1.5  	memset(rb, 0, sizeof *rb);
     1.6  
     1.7 -	if(cmp_func == RB_KEY_INT) {
     1.8 +	if(!cmp_func) {
     1.9 +		rb->cmp = cmpaddr;
    1.10 +	} else if(cmp_func == RB_KEY_INT) {
    1.11  		rb->cmp = cmpint;
    1.12  	} else if(cmp_func == RB_KEY_STRING) {
    1.13  		rb->cmp = (rb_cmp_func_t)strcmp;
    1.14  	} else {
    1.15 -		rb->cmp = cmpaddr;
    1.16 +		rb->cmp = cmp_func;
    1.17  	}
    1.18  
    1.19  	rb->alloc = malloc;
    1.20 @@ -154,7 +156,7 @@
    1.21  }
    1.22  
    1.23  
    1.24 -void *rb_find(struct rbtree *rb, void *key)
    1.25 +struct rbnode *rb_find(struct rbtree *rb, void *key)
    1.26  {
    1.27  	struct rbnode *node = rb->root;
    1.28  
    1.29 @@ -168,7 +170,7 @@
    1.30  	return 0;
    1.31  }
    1.32  
    1.33 -void *rb_findi(struct rbtree *rb, int key)
    1.34 +struct rbnode *rb_findi(struct rbtree *rb, int key)
    1.35  {
    1.36  	return rb_find(rb, INT2PTR(key));
    1.37  }
     2.1 --- a/src/rbtree.h	Sun Nov 02 10:56:08 2014 +0200
     2.2 +++ b/src/rbtree.h	Sun Nov 02 11:00:27 2014 +0200
     2.3 @@ -56,8 +56,8 @@
     2.4  int rb_delete(struct rbtree *rb, void *key);
     2.5  int rb_deletei(struct rbtree *rb, int key);
     2.6  
     2.7 -void *rb_find(struct rbtree *rb, void *key);
     2.8 -void *rb_findi(struct rbtree *rb, int key);
     2.9 +struct rbnode *rb_find(struct rbtree *rb, void *key);
    2.10 +struct rbnode *rb_findi(struct rbtree *rb, int key);
    2.11  
    2.12  void rb_foreach(struct rbtree *rb, void (*func)(struct rbnode*, void*), void *cls);
    2.13