summaryrefslogtreecommitdiff
path: root/libhurd-btree
diff options
context:
space:
mode:
authorneal <neal>2007-11-05 14:11:27 +0000
committerneal <neal>2007-11-05 14:11:27 +0000
commit8a113b4d63639f35ea929746431970cfba53a0fd (patch)
treee730bf8f7d695c32c97b6c82f106b65ae21451eb /libhurd-btree
parente6fd7b068116ee5d4477bd1bd28b81c1bc973335 (diff)
2007-11-05 Neal H. Walfield <neal@gnu.org>
* btree.h (insert): Don't return an error code. Return the node with the overlapping key. (BTREE_CLASS): Update insert template.
Diffstat (limited to 'libhurd-btree')
-rw-r--r--libhurd-btree/ChangeLog6
-rw-r--r--libhurd-btree/btree.h18
2 files changed, 16 insertions, 8 deletions
diff --git a/libhurd-btree/ChangeLog b/libhurd-btree/ChangeLog
index 1ccdf6a..ffc5dea 100644
--- a/libhurd-btree/ChangeLog
+++ b/libhurd-btree/ChangeLog
@@ -1,3 +1,9 @@
+2007-11-05 Neal H. Walfield <neal@gnu.org>
+
+ * btree.h (insert): Don't return an error code. Return the node
+ with the overlapping key.
+ (BTREE_CLASS): Update insert template.
+
2007-10-17 Neal H. Walfield <neal@gnu.org>
* btree.h: Don't include <stdlib.h>.
diff --git a/libhurd-btree/btree.h b/libhurd-btree/btree.h
index c7e066e..e4f28a7 100644
--- a/libhurd-btree/btree.h
+++ b/libhurd-btree/btree.h
@@ -283,13 +283,13 @@ BTREE_(find) (BTREE_(t) *btree, BTREE_(key_compare_t) compare,
}
/* Insert node NODE into btree BTREE. COMPARE is the comparison
- function. NEWNODE's key must be valid. Returns 0 on success.
- Otherwise, EEXIST if a node with the same key as NEWNODE exists in
- the tree. */
-BTREE_EXTERN_INLINE error_t
+ function. NEWNODE's key must be valid. If the node cannot be
+ inserted as a node with the key already exists, returns the node.
+ Otherwise, returns 0. */
+BTREE_EXTERN_INLINE BTREE_(node_t) *
BTREE_(insert) (BTREE_(t) *btree, BTREE_(key_compare_t) compare,
size_t key_offset, BTREE_(node_t) *newnode);
-BTREE_EXTERN_INLINE error_t
+BTREE_EXTERN_INLINE BTREE_(node_t) *
BTREE_(insert) (BTREE_(t) *btree, BTREE_(key_compare_t) compare,
size_t key_offset, BTREE_(node_t) *newnode)
{
@@ -300,7 +300,9 @@ BTREE_(insert) (BTREE_(t) *btree, BTREE_(key_compare_t) compare,
(void *) newnode + key_offset,
&nodep, &pred, &succ, &parent);
if (! err)
- return EEXIST;
+ /* Overlap! Bail. */
+ return BTREE_(link_internal) (*nodep);
+
assert (err == ESRCH);
assert (BTREE_(link_internal) (*nodep) == NULL);
@@ -410,7 +412,7 @@ extern BTREE_(node_t) *BTREE_(prev) (BTREE_(node_t) *node);
Functions:
void btree_NAME_tree_init (btree_NAME_t *btree, NODE_TYPE *node);
NODE_TYPE *btree_NAME_find (btree_NAME_t *btree, const KEY_TYPE *key);
- error_t btree_NAME_insert (btree_NAME_t *btree, NODE_TYPE *newnode);
+ NODE_TYPE *btree_NAME_insert (btree_NAME_t *btree, NODE_TYPE *newnode);
void btree_NAME_detach (btree_NAME_t *btree, NODE_TYPE *node);
NODE_TYPE *btree_NAME_first (btree_NAME_t *btree);
NODE_TYPE *btree_NAME_next (NODE_TYPE *node);
@@ -494,7 +496,7 @@ BTREE_(name##_find) (BTREE_(name##_t) *btree, const key_type *key) \
return n ? n - offsetof (node_type, btree_node_field) : NULL; \
} \
\
-static inline error_t \
+static inline node_type * \
BTREE_(name##_insert) (BTREE_(name##_t) *btree, node_type *newnode) \
{ \
int (*cmp) (const key_type *, const key_type *) = (cmp_function); \