summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d72bf69)
raw | patch | inline | side by side (parent: d72bf69)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 25 Nov 2006 10:21:19 +0000 (11:21 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 25 Nov 2006 10:21:19 +0000 (11:21 +0100) |
The idea behind this is, that the calling routing may not have a pointer to
it's location, and possibly can't deallocate the memory.
it's location, and possibly can't deallocate the memory.
src/utils_avltree.c | patch | blob | history | |
src/utils_avltree.h | patch | blob | history |
diff --git a/src/utils_avltree.c b/src/utils_avltree.c
index 3665760bca88b1f5f1b2f871f1ebb64d0863a862..275cb9b37acb6c651d55cbb301797c3e22723a07 100644 (file)
--- a/src/utils_avltree.c
+++ b/src/utils_avltree.c
free (n);
}
-static avl_node_t *search (avl_tree_t *t, void *key)
+static avl_node_t *search (avl_tree_t *t, const void *key)
{
avl_node_t *n;
int cmp;
return (r);
}
-static void *_remove (avl_tree_t *t, avl_node_t *n)
+static int _remove (avl_tree_t *t, avl_node_t *n)
{
- void *ret;
-
assert ((t != NULL) && (n != NULL));
- ret = n->value;
-
if ((n->left == NULL) && (n->right == NULL))
{
/* Deleting a leave is easy */
_remove (t, r);
}
- return (ret);
+ return (0);
} /* void *_remove */
/*
return (0);
} /* int avl_insert */
-void *avl_remove (avl_tree_t *t, void *key)
+int avl_remove (avl_tree_t *t, void *key, void **rkey, void **rvalue)
{
avl_node_t *n;
n = search (t, key);
if (n == NULL)
- return (NULL);
+ return (-1);
+
+ if (rkey != NULL)
+ *rkey = n->key;
+ if (rvalue != NULL)
+ *rvalue = n->value;
return (_remove (t, n));
} /* void *avl_remove */
-void *avl_get (avl_tree_t *t, void *key)
+int avl_get (avl_tree_t *t, const void *key, void **value)
{
avl_node_t *n;
+ assert (value != NULL);
+
n = search (t, key);
if (n == NULL)
- return (NULL);
+ return (-1);
- return (n->value);
+ *value = n->value;
+
+ return (0);
}
avl_iterator_t *avl_get_iterator (avl_tree_t *t)
diff --git a/src/utils_avltree.h b/src/utils_avltree.h
index 5ffa696e54052eb68e2c233b7dcbbe7b75abc337..7875e0b2674802df844901e1b5f42fed644ab437 100644 (file)
--- a/src/utils_avltree.h
+++ b/src/utils_avltree.h
struct avl_iterator_s;
typedef struct avl_iterator_s avl_iterator_t;
+struct avl_keyval_s
+{
+ void *key;
+ void *value;
+};
+
avl_tree_t *avl_create (int (*compare) (const void *, const void *));
void avl_destroy (avl_tree_t *t);
int avl_insert (avl_tree_t *t, void *key, void *value);
-void *avl_remove (avl_tree_t *t, void *key);
+int avl_remove (avl_tree_t *t, void *key, void **rkey, void **rvalue);
-void *avl_get (avl_tree_t *t, void *key);
+int avl_get (avl_tree_t *t, const void *key, void **value);
avl_iterator_t *avl_get_iterator (avl_tree_t *t);
void *avl_iterator_next (avl_iterator_t *iter);