summaryrefslogtreecommitdiffstats
path: root/src/avl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/avl.c')
-rw-r--r--src/avl.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/avl.c b/src/avl.c
index 324afeeb..1ec1b8ad 100644
--- a/src/avl.c
+++ b/src/avl.c
@@ -283,18 +283,30 @@ avl *avl_remove(avl_tree *tree, avl *item) {
// ---------------------------
// traversing
-void avl_walker(avl *node, void (*callback)(void *)) {
- if(node->avl_link[0])
- avl_walker(node->avl_link[0], callback);
+int avl_walker(avl *node, int (*callback)(void *entry, void *data), void *data) {
+ int total = 0, ret = 0;
- callback(node);
+ if(node->avl_link[0]) {
+ ret = avl_walker(node->avl_link[0], callback, data);
+ if(ret < 0) return ret;
+ total += ret;
+ }
+
+ ret = callback(node, data);
+ if(ret < 0) return ret;
+ total += ret;
- if(node->avl_link[1])
- avl_walker(node->avl_link[1], callback);
+ if(node->avl_link[1]) {
+ ret = avl_walker(node->avl_link[1], callback, data);
+ if (ret < 0) return ret;
+ total += ret;
+ }
+
+ return total;
}
-void avl_traverse(avl_tree *t, void (*callback)(void *)) {
- avl_walker(t->root, callback);
+int avl_traverse(avl_tree *t, int (*callback)(void *entry, void *data), void *data) {
+ return avl_walker(t->root, callback, data);
}
// ---------------------------
@@ -372,10 +384,12 @@ avl *avl_insert_lock(avl_tree_lock *t, avl *a) {
return ret;
}
-void avl_traverse_lock(avl_tree_lock *t, void (*callback)(void *)) {
+int avl_traverse_lock(avl_tree_lock *t, int (*callback)(void *entry, void *data), void *data) {
+ int ret;
avl_read_lock(t);
- avl_traverse(&t->avl_tree, callback);
+ ret = avl_traverse(&t->avl_tree, callback, data);
avl_unlock(t);
+ return ret;
}
void avl_init(avl_tree *t, int (*compar)(void *a, void *b)) {