]> arthur.barton.de Git - netdata.git/blobdiff - src/avl.h
Separate vm.stats.vm.v_pgfaults module
[netdata.git] / src / avl.h
index 17c3c5ea752194338cd0d0dde3f043d7691a9210..d30be0dd85cc7e5d5918b610da9f8446b08dd623 100644 (file)
--- a/src/avl.h
+++ b/src/avl.h
@@ -32,18 +32,18 @@ typedef struct avl {
 
 /* An AVL tree */
 typedef struct avl_tree {
-       avl *root;
-       int (*compar)(void *a, void *b);
+    avl *root;
+    int (*compar)(void *a, void *b);
 } avl_tree;
 
 typedef struct avl_tree_lock {
-       avl_tree avl_tree;
+    avl_tree avl_tree;
 
 #ifndef AVL_WITHOUT_PTHREADS
 #ifdef AVL_LOCK_WITH_MUTEX
-       pthread_mutex_t mutex;
+    pthread_mutex_t mutex;
 #else /* AVL_LOCK_WITH_MUTEX */
-       pthread_rwlock_t rwlock;
+    pthread_rwlock_t rwlock;
 #endif /* AVL_LOCK_WITH_MUTEX */
 #endif /* AVL_WITHOUT_PTHREADS */
 } avl_tree_lock;
@@ -51,23 +51,25 @@ typedef struct avl_tree_lock {
 /* Public methods */
 
 /* Insert element a into the AVL tree t
- * returns 1 if the depth of the tree has grown
- * Warning: do not insert elements already present
+ * returns the added element a, or a pointer the
+ * element that is equal to a (as returned by t->compar())
+ * a is linked directly to the tree, so it has to
+ * be properly allocated by the caller.
  */
-avl *avl_insert_lock(avl_tree_lock *t, avl *a);
-avl *avl_insert(avl_tree *t, avl *a);
+avl *avl_insert_lock(avl_tree_lock *t, avl *a) NEVERNULL WARNUNUSED;
+avl *avl_insert(avl_tree *t, avl *a) NEVERNULL WARNUNUSED;
 
 /* Remove an element a from the AVL tree t
- * returns -1 if the depth of the tree has shrunk
- * Warning: if the element is not present in the tree,
- *          returns 0 as if it had been removed succesfully.
+ * returns a pointer to the removed element
+ * or NULL if an element equal to a is not found
+ * (equal as returned by t->compar())
  */
-avl *avl_remove_lock(avl_tree_lock *t, avl *a);
-avl *avl_remove(avl_tree *t, avl *a);
+avl *avl_remove_lock(avl_tree_lock *t, avl *a) WARNUNUSED;
+avl *avl_remove(avl_tree *t, avl *a) WARNUNUSED;
 
-/* Iterate through elements in t equal to a
- * for each element calls iter(a) until it returns 0
- * returns the last value returned by iterator or 0 if there were no calls
+/* Find the element into the tree that equal to a
+ * (equal as returned by t->compar())
+ * returns NULL is no element is equal to a
  */
 avl *avl_search_lock(avl_tree_lock *t, avl *a);
 avl *avl_search(avl_tree *t, avl *a);
@@ -77,4 +79,8 @@ avl *avl_search(avl_tree *t, avl *a);
 void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b));
 void avl_init(avl_tree *t, int (*compar)(void *a, void *b));
 
+
+int avl_traverse_lock(avl_tree_lock *t, int (*callback)(void *entry, void *data), void *data);
+int avl_traverse(avl_tree *t, int (*callback)(void *entry, void *data), void *data);
+
 #endif /* avl.h */