X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=avl.c;h=8d0bf65aaa5bdaaf83f0910465281a0542e6dfa1;hp=3efeaf53e7310c2934923cda7938b87a0fe88cd0;hb=72613ca2c8f9b9905c6372c1b19ecbcd7cace007;hpb=3edc29942c43a8178019c4821c1ee9a11d26ba99 diff --git a/avl.c b/avl.c index 3efeaf5..8d0bf65 100644 --- a/avl.c +++ b/avl.c @@ -90,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; @@ -98,6 +98,11 @@ avl_init(struct avl_tree *tree, avl_tree_comp comp, bool allow_dups, void *ptr) tree->cmp_ptr = ptr; } +static inline struct avl_node *avl_next(struct avl_node *node) +{ + return list_entry(node->list.next, struct avl_node, list); +} + /** * Finds a node in an avl-tree with a certain key * @param tree pointer to avl-tree @@ -225,7 +230,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; @@ -236,7 +241,7 @@ avl_insert(struct avl_tree *tree, struct avl_node *new) last = node; while (!list_is_last(&last->list, &tree->list_head)) { - next = list_next_element(last, list); + next = avl_next(last); if (next->leader) { break; } @@ -307,7 +312,7 @@ avl_delete(struct avl_tree *tree, struct avl_node *node) if (node->leader) { if (tree->allow_dups && !list_is_last(&node->list, &tree->list_head) - && !(next = list_next_element(node, list))->leader) { + && !(next = avl_next(node))->leader) { next->leader = true; next->balance = node->balance; @@ -484,21 +489,21 @@ post_insert(struct avl_tree *tree, struct avl_node *node) static void avl_insert_before(struct avl_tree *tree, struct avl_node *pos_node, struct avl_node *node) { - list_add_before(&pos_node->list, &node->list); + list_add_tail(&node->list, &pos_node->list); tree->count++; } static void avl_insert_after(struct avl_tree *tree, struct avl_node *pos_node, struct avl_node *node) { - list_add_after(&pos_node->list, &node->list); + list_add(&node->list, &pos_node->list); tree->count++; } static void avl_remove(struct avl_tree *tree, struct avl_node *node) { - list_remove(&node->list); + list_del(&node->list); tree->count--; }