summaryrefslogtreecommitdiffstats
path: root/src/avl.c
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2017-01-24 15:21:09 +0000
committerLennart Weller <lhw@ring0.de>2017-01-24 15:21:09 +0000
commit3ed3b02ed96ddab1c084811f3579b3a2aec83e04 (patch)
tree7a61ab288ae47800c4f11be5677d6ad8288dcd98 /src/avl.c
parentNew upstream version 1.4.0+dfsg (diff)
downloadnetdata-3ed3b02ed96ddab1c084811f3579b3a2aec83e04.tar.xz
netdata-3ed3b02ed96ddab1c084811f3579b3a2aec83e04.zip
New upstream version 1.5.0+dfsgupstream/1.5.0+dfsg
Diffstat (limited to '')
-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)) {