list_compat.h: remove list_add_head()
[project/libubox.git] / avl.c
diff --git a/avl.c b/avl.c
index fa23b03..545fd2a 100644 (file)
--- a/avl.c
+++ b/avl.c
 #include "avl.h"
 #include "list.h"
 
-#define list_merge(_head, _list) list_merge(_list, _head)
-#define list_is_last(_head, _list) list_is_last(_list, _head)
-#define list_is_first(_head, _list) list_is_first(_list, _head)
-
 /**
  * internal type save inline function to calculate the maximum of
  * to integers without macro implementation.
@@ -94,7 +90,7 @@ static void avl_remove(struct avl_tree *tree, struct avl_node *node);
 void
 avl_init(struct avl_tree *tree, avl_tree_comp comp, bool allow_dups, void *ptr)
 {
-  list_init_head(&tree->list_head);
+  INIT_LIST_HEAD(&tree->list_head);
   tree->root = NULL;
   tree->count = 0;
   tree->comp = comp;
@@ -103,32 +99,6 @@ avl_init(struct avl_tree *tree, avl_tree_comp comp, bool allow_dups, void *ptr)
 }
 
 /**
- * Internal function to support returning the element from a avl tree query
- * @param tree pointer to avl tree
- * @param key pointer to key
- * @param offset offset of node inside the embedded struct
- * @param mode mode of lookup operation (less equal, equal or greater equal)
- * @param pointer to elemen, NULL if no fitting one was found
- */
-void *
-__avl_find_element(const struct avl_tree *tree, const void *key, size_t offset, enum avl_find_mode mode) {
-  void *node = NULL;
-
-  switch (mode) {
-    case AVL_FIND_EQUAL:
-      node = avl_find(tree, key);
-      break;
-    case AVL_FIND_LESSEQUAL:
-      node = avl_find_lessequal(tree, key);
-      break;
-    case AVL_FIND_GREATEREQUAL:
-      node = avl_find_greaterequal(tree, key);
-      break;
-  }
-  return node == NULL ? NULL : (((char *)node) - offset);
-}
-
-/**
  * Finds a node in an avl-tree with a certain key
  * @param tree pointer to avl-tree
  * @param key pointer to key
@@ -169,7 +139,7 @@ avl_find_lessequal(const struct avl_tree *tree, const void *key) {
 
   /* go left as long as key<node.key */
   while (diff < 0) {
-    if (list_is_first(&tree->list_head, &node->list)) {
+    if (list_is_first(&node->list, &tree->list_head)) {
       return NULL;
     }
 
@@ -181,7 +151,7 @@ avl_find_lessequal(const struct avl_tree *tree, const void *key) {
   next = node;
   while (diff >= 0) {
     node = next;
-    if (list_is_last(&tree->list_head, &node->list)) {
+    if (list_is_last(&node->list, &tree->list_head)) {
       break;
     }
 
@@ -211,7 +181,7 @@ avl_find_greaterequal(const struct avl_tree *tree, const void *key) {
 
   /* go right as long as key>node.key */
   while (diff > 0) {
-    if (list_is_last(&tree->list_head, &node->list)) {
+    if (list_is_last(&node->list, &tree->list_head)) {
       return NULL;
     }
 
@@ -223,7 +193,7 @@ avl_find_greaterequal(const struct avl_tree *tree, const void *key) {
   next = node;
   while (diff <= 0) {
     node = next;
-    if (list_is_first(&tree->list_head, &node->list)) {
+    if (list_is_first(&node->list, &tree->list_head)) {
       break;
     }
 
@@ -255,7 +225,7 @@ avl_insert(struct avl_tree *tree, struct avl_node *new)
   new->leader = true;
 
   if (tree->root == NULL) {
-    list_add_head(&tree->list_head, &new->list);
+    list_add(&new->list, &tree->list_head);
     tree->root = new;
     tree->count = 1;
     return 0;
@@ -265,7 +235,7 @@ avl_insert(struct avl_tree *tree, struct avl_node *new)
 
   last = node;
 
-  while (!list_is_last(&tree->list_head, &last->list)) {
+  while (!list_is_last(&last->list, &tree->list_head)) {
     next = list_next_element(last, list);
     if (next->leader) {
       break;
@@ -336,7 +306,7 @@ avl_delete(struct avl_tree *tree, struct avl_node *node)
   struct avl_node *right;
   if (node->leader) {
     if (tree->allow_dups
-        && !list_is_last(&tree->list_head, &node->list)
+        && !list_is_last(&node->list, &tree->list_head)
         && !(next = list_next_element(node, list))->leader) {
       next->leader = true;
       next->balance = node->balance;