diff options
author | sommerfe <none@none> | 2006-05-18 16:49:52 -0700 |
---|---|---|
committer | sommerfe <none@none> | 2006-05-18 16:49:52 -0700 |
commit | 208e825d0597a017edee1b095c64040043c0c673 (patch) | |
tree | 9783584b9f888717dcdbc011c55c7db2b799b9fd /usr/src/common/avl/avl.c | |
parent | c73a93f2f62aa040c7fc1755230b787b0ad03967 (diff) | |
download | illumos-joyent-208e825d0597a017edee1b095c64040043c0c673.tar.gz |
6225914 avl_remove should assert that tree is not empty
6225934 avl_insert_here silent about duplicate key values
Diffstat (limited to 'usr/src/common/avl/avl.c')
-rw-r--r-- | usr/src/common/avl/avl.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/usr/src/common/avl/avl.c b/usr/src/common/avl/avl.c index 579e7408a9..7e035b8580 100644 --- a/usr/src/common/avl/avl.c +++ b/usr/src/common/avl/avl.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -569,6 +568,9 @@ avl_insert_here( { avl_node_t *node; int child = direction; /* rely on AVL_BEFORE == 0, AVL_AFTER == 1 */ +#ifdef DEBUG + int diff; +#endif ASSERT(tree != NULL); ASSERT(new_data != NULL); @@ -580,20 +582,34 @@ avl_insert_here( * node and reverse the insertion direction. */ node = AVL_DATA2NODE(here, tree->avl_offset); - ASSERT(tree->avl_compar(new_data, here) > 0 ? child == 1 : child == 0); + +#ifdef DEBUG + diff = tree->avl_compar(new_data, here); + ASSERT(-1 <= diff && diff <= 1); + ASSERT(diff != 0); + ASSERT(diff > 0 ? child == 1 : child == 0); +#endif if (node->avl_child[child] != NULL) { node = node->avl_child[child]; child = 1 - child; while (node->avl_child[child] != NULL) { - ASSERT(tree->avl_compar(new_data, - AVL_NODE2DATA(node, tree->avl_offset)) > 0 ? - child == 1 : child == 0); +#ifdef DEBUG + diff = tree->avl_compar(new_data, + AVL_NODE2DATA(node, tree->avl_offset)); + ASSERT(-1 <= diff && diff <= 1); + ASSERT(diff != 0); + ASSERT(diff > 0 ? child == 1 : child == 0); +#endif node = node->avl_child[child]; } - ASSERT(tree->avl_compar(new_data, - AVL_NODE2DATA(node, tree->avl_offset)) > 0 ? - child == 1 : child == 0); +#ifdef DEBUG + diff = tree->avl_compar(new_data, + AVL_NODE2DATA(node, tree->avl_offset)); + ASSERT(-1 <= diff && diff <= 1); + ASSERT(diff != 0); + ASSERT(diff > 0 ? child == 1 : child == 0); +#endif } ASSERT(node->avl_child[child] == NULL); @@ -727,6 +743,7 @@ avl_remove(avl_tree_t *tree, void *data) * Here we know "delete" is at least partially a leaf node. It can * be easily removed from the tree. */ + ASSERT(tree->avl_numnodes > 0); --tree->avl_numnodes; parent = AVL_XPARENT(delete); which_child = AVL_XCHILD(delete); |