]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
bintree_add: Return the correct member during add
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 3 Jul 2010 13:46:34 +0000 (16:46 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 3 Jul 2010 13:49:27 +0000 (16:49 +0300)
When a member is not found from the tree, return the new member
instead of the parent node. Also fix the comment regarding the
function.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
bintree.c

index c23394c67fba40bf3344deeaf665c997682759eb..4b119430e513e017897aef4a851f268f7b22239d 100644 (file)
--- a/bintree.c
+++ b/bintree.c
@@ -6,7 +6,7 @@
  * bintree_add - Add to tree
  *
  * Adds a node to a sorted tree. If the new node is already found from
- * the tree, the existing node is added and the new node is not
+ * the tree, the existing node is returned and the new node is not
  * added. If new node is not found, the new one is added and the tree
  * is kept sorted.
  */
@@ -25,7 +25,7 @@ struct bintree *bintree_add(struct bintree *tree, struct bintree *new,
                else
                        tree->left = new;
 
-               return tree;
+               return new;
        }
 
        if (ret > 0) {
@@ -34,7 +34,7 @@ struct bintree *bintree_add(struct bintree *tree, struct bintree *new,
                else
                        tree->right = new;
 
-               return tree;
+               return new;
        }
 
        return tree;