/*
- * 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 <ebiggers3@gmail.com>
*
- * 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 <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
-#include <wimlib/avl_tree.h>
+#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. */
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). */
*/
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