summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/rbtreeinsert.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2011-08-02 19:25:59 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2011-08-02 19:25:59 +0000
commit13c4f853e6655e6b1c759255bea4f63c77806cdc (patch)
tree6347f845f2761b7ea2863c44c672e83f40177c9e /cpukit/score/src/rbtreeinsert.c
parent2011-08-02 Ricardo Aguirre <el.mastin@ymail.com> (diff)
downloadrtems-13c4f853e6655e6b1c759255bea4f63c77806cdc.tar.bz2
2011-08-02 Joel Sherrill <joel.sherrill@oarcorp.com>
PR 1877/cpukit * libfs/src/imfs/imfs_mknod.c, libfs/src/imfs/memfile.c, sapi/inline/rtems/rbtree.inl, score/include/rtems/score/rbtree.h, score/inline/rtems/score/rbtree.inl, score/src/rbtree.c, score/src/rbtreefind.c, score/src/rbtreeinsert.c: Add comparison function for RBTrees.
Diffstat (limited to 'cpukit/score/src/rbtreeinsert.c')
-rw-r--r--cpukit/score/src/rbtreeinsert.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/cpukit/score/src/rbtreeinsert.c b/cpukit/score/src/rbtreeinsert.c
index 8a694063ff..bb1915de54 100644
--- a/cpukit/score/src/rbtreeinsert.c
+++ b/cpukit/score/src/rbtreeinsert.c
@@ -71,7 +71,7 @@ void _RBTree_Validate_insert_unprotected(
*
* @retval 0 Successfully inserted.
* @retval -1 NULL @a the_node.
- * @retval RBTree_Node* if one with equal value to @a the_node->value exists
+ * @retval RBTree_Node* if one with equal key to the key of @a the_node exists
* in @a the_rbtree.
*
* @note It does NOT disable interrupts to ensure the atomicity
@@ -85,6 +85,7 @@ RBTree_Node *_RBTree_Insert_unprotected(
if(!the_node) return (RBTree_Node*)-1;
RBTree_Node *iter_node = the_rbtree->root;
+ int compare_result;
if (!iter_node) { /* special case: first node inserted */
the_node->color = RBT_BLACK;
@@ -95,8 +96,9 @@ RBTree_Node *_RBTree_Insert_unprotected(
} else {
/* typical binary search tree insert, descend tree to leaf and insert */
while (iter_node) {
- if(the_node->value == iter_node->value) return(iter_node);
- RBTree_Direction dir = the_node->value > iter_node->value;
+ compare_result = the_rbtree->compare_function(the_node, iter_node);
+ if ( !compare_result ) return iter_node;
+ RBTree_Direction dir = (compare_result != -1);
if (!iter_node->child[dir]) {
the_node->child[RBT_LEFT] = the_node->child[RBT_RIGHT] = NULL;
the_node->color = RBT_RED;