X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Favl_tree.c;h=d3afae4e2114e7de667113b433d905af98dc6c24;hp=293db45d408903580fb001747082af28ac6b97bc;hb=eb3e3b72db23ecaa7789a807afeb9577962653fe;hpb=83a29687e9fd2a8b9367c735b6e3273ac82ef99b diff --git a/src/avl_tree.c b/src/avl_tree.c index 293db45d..d3afae4e 100644 --- a/src/avl_tree.c +++ b/src/avl_tree.c @@ -1,17 +1,29 @@ /* - * avl_tree.c + * avl_tree.c - intrusive, nonrecursive AVL tree data structure (self-balancing + * binary search tree), implementation file * - * Intrusive, nonrecursive AVL tree data structure (self-balancing binary search - * tree), implementation file. + * The following copying information applies to this specific source code file: * - * Author: Eric Biggers - * Year: 2014 + * Written in 2014 by Eric Biggers * - * The author dedicates this file to the public domain. - * You can do whatever you want with this file. + * To the extent possible under law, the author(s) have dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide via the Creative Commons Zero 1.0 Universal Public Domain + * Dedication (the "CC0"). + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the CC0 for more details. + * + * You should have received a copy of the CC0 along with this software; if not + * see . */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "wimlib/avl_tree.h" /* Starts an in-order traversal of the tree: returns the least-valued node, or * NULL if the tree is empty. */ @@ -127,15 +139,6 @@ avl_get_balance_factor(const struct avl_tree_node *node) return (int)(node->parent_balance & 3) - 1; } -/* Sets the balance factor of the specified AVL tree node. This must be - * -1, 0, or 1. */ -static AVL_INLINE void -avl_set_balance_factor(struct avl_tree_node *node, int balance_factor) -{ - node->parent_balance = - (node->parent_balance & ~3) | (balance_factor + 1); -} - /* Adds @amount to the balance factor of the specified AVL tree node. * The caller must ensure this still results in a valid balance factor * (-1, 0, or 1). */ @@ -380,12 +383,10 @@ avl_handle_subtree_growth(struct avl_tree_node ** const root_ptr, */ avl_rotate(root_ptr, parent, -sign); - /* Equivalent to: - * avl_set_balance_factor(parent, 0); */ + /* Equivalent to setting @parent's balance factor to 0. */ avl_adjust_balance_factor(parent, -sign); /* A */ - /* Equivalent to: - * avl_set_balance_factor(node, 0); */ + /* Equivalent to setting @node's balance factor to 0. */ avl_adjust_balance_factor(node, -sign); /* B */ } else { /* @node (B below) is heavy in the direction opposite