diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2018-11-07 12:19:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2018-11-07 12:20:17 +0000 |
commit | a64a253794ac64cb40befee54db53bde17dd0d49 (patch) | |
tree | c1024acc5f6e508814b944d99f112259bb28b1be /libnetdata/avl/avl.c | |
parent | New upstream version 1.10.0+dfsg (diff) | |
download | netdata-upstream/1.11.0+dfsg.tar.xz netdata-upstream/1.11.0+dfsg.zip |
New upstream version 1.11.0+dfsgupstream/1.11.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | libnetdata/avl/avl.c (renamed from src/avl.c) | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/src/avl.c b/libnetdata/avl/avl.c index a2c6911e7..c44bef307 100644 --- a/src/avl.c +++ b/libnetdata/avl/avl.c @@ -1,4 +1,6 @@ -#include "common.h" +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "../libnetdata.h" /* ------------------------------------------------------------------------- */ /* @@ -10,7 +12,6 @@ * libavl - library for manipulation of binary trees. * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software * Foundation, Inc. - * GNU Lesser General Public License */ @@ -44,7 +45,7 @@ avl *avl_insert(avl_tree *tree, avl *item) { avl *p, *q; /* Iterator, and parent. */ avl *n; /* Newly inserted node. */ avl *w; /* New root of rebalanced subtree. */ - int dir; /* Direction to descend. */ + unsigned char dir; /* Direction to descend. */ unsigned char da[AVL_MAX_HEIGHT]; /* Cached comparison results. */ int k = 0; /* Number of cached results. */ @@ -61,7 +62,7 @@ avl *avl_insert(avl_tree *tree, avl *item) { if (p->avl_balance != 0) z = q, y = p, k = 0; - da[k++] = dir = (cmp > 0); + da[k++] = dir = (unsigned char)(cmp > 0); } n = q->avl_link[dir] = item; @@ -149,7 +150,7 @@ avl *avl_remove(avl_tree *tree, avl *item) { k = 0; p = (avl *) &tree->root; for(cmp = -1; cmp != 0; cmp = tree->compar(item, p)) { - int dir = (cmp > 0); + unsigned char dir = (unsigned char)(cmp > 0); pa[k] = p; da[k++] = dir; @@ -283,7 +284,7 @@ avl *avl_remove(avl_tree *tree, avl *item) { // --------------------------- // traversing -int avl_walker(avl *node, int (*callback)(void *entry, void *data), void *data) { +int avl_walker(avl *node, int (*callback)(void * /*entry*/, void * /*data*/), void *data) { int total = 0, ret = 0; if(node->avl_link[0]) { @@ -305,9 +306,9 @@ int avl_walker(avl *node, int (*callback)(void *entry, void *data), void *data) return total; } -int avl_traverse(avl_tree *t, int (*callback)(void *entry, void *data), void *data) { - if(t->root) - return avl_walker(t->root, callback, data); +int avl_traverse(avl_tree *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) { + if(tree->root) + return avl_walker(tree->root, callback, data); else return 0; } @@ -348,16 +349,16 @@ void avl_unlock(avl_tree_lock *t) { // --------------------------- // operations with locking -void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b)) { - avl_init(&t->avl_tree, compar); +void avl_init_lock(avl_tree_lock *tree, int (*compar)(void * /*a*/, void * /*b*/)) { + avl_init(&tree->avl_tree, compar); #ifndef AVL_WITHOUT_PTHREADS int lock; #ifdef AVL_LOCK_WITH_MUTEX - lock = netdata_mutex_init(&t->mutex, NULL); + lock = netdata_mutex_init(&tree->mutex, NULL); #else - lock = netdata_rwlock_init(&t->rwlock); + lock = netdata_rwlock_init(&tree->rwlock); #endif if(lock != 0) @@ -366,38 +367,38 @@ void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b)) { #endif /* AVL_WITHOUT_PTHREADS */ } -avl *avl_search_lock(avl_tree_lock *t, avl *a) { - avl_read_lock(t); - avl *ret = avl_search(&t->avl_tree, a); - avl_unlock(t); +avl *avl_search_lock(avl_tree_lock *tree, avl *item) { + avl_read_lock(tree); + avl *ret = avl_search(&tree->avl_tree, item); + avl_unlock(tree); return ret; } -avl * avl_remove_lock(avl_tree_lock *t, avl *a) { - avl_write_lock(t); - avl *ret = avl_remove(&t->avl_tree, a); - avl_unlock(t); +avl * avl_remove_lock(avl_tree_lock *tree, avl *item) { + avl_write_lock(tree); + avl *ret = avl_remove(&tree->avl_tree, item); + avl_unlock(tree); return ret; } -avl *avl_insert_lock(avl_tree_lock *t, avl *a) { - avl_write_lock(t); - avl * ret = avl_insert(&t->avl_tree, a); - avl_unlock(t); +avl *avl_insert_lock(avl_tree_lock *tree, avl *item) { + avl_write_lock(tree); + avl * ret = avl_insert(&tree->avl_tree, item); + avl_unlock(tree); return ret; } -int avl_traverse_lock(avl_tree_lock *t, int (*callback)(void *entry, void *data), void *data) { +int avl_traverse_lock(avl_tree_lock *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) { int ret; - avl_read_lock(t); - ret = avl_traverse(&t->avl_tree, callback, data); - avl_unlock(t); + avl_read_lock(tree); + ret = avl_traverse(&tree->avl_tree, callback, data); + avl_unlock(tree); return ret; } -void avl_init(avl_tree *t, int (*compar)(void *a, void *b)) { - t->root = NULL; - t->compar = compar; +void avl_init(avl_tree *tree, int (*compar)(void * /*a*/, void * /*b*/)) { + tree->root = NULL; + tree->compar = compar; } -// ------------------
\ No newline at end of file +// ------------------ |