Skip to content

Commit

Permalink
Remove unused functions for rbtree
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Apr 22, 2014
1 parent 1aa339c commit 7631ecc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 73 deletions.
23 changes: 1 addition & 22 deletions src/include/libradius.h
Expand Up @@ -817,7 +817,6 @@ bool rbtree_deletebydata(rbtree_t *tree, void const *data);
rbnode_t *rbtree_find(rbtree_t *tree, void const *data);
void *rbtree_finddata(rbtree_t *tree, void const *data);
int rbtree_num_elements(rbtree_t *tree);
void *rbtree_min(rbtree_t *tree);
void *rbtree_node2data(rbtree_t *tree, rbnode_t *node);

/*
Expand All @@ -826,7 +825,7 @@ void *rbtree_node2data(rbtree_t *tree, rbnode_t *node);
*
* The "context" is some user-defined context.
* The "data" is the pointer to the user data in the node,
* NOT the node itself.
* NOT the node itself.
*
* It should return 0 if all is OK, and !0 for any error.
* The walking will stop on any error.
Expand All @@ -838,26 +837,6 @@ void *rbtree_node2data(rbtree_t *tree, rbnode_t *node);
*/
int rbtree_walk(rbtree_t *tree, rb_order_t order, rb_walker_t compare, void *context);

/*
* Find a matching data item in an rbtree and, if one is found,
* perform a callback on it.
*
* The callback is similar to rbtree_walk above, except that a
* positive return code from the callback will cause the found node
* to be deleted from the tree. If the tree was created with
* RBTREE_FLAG_LOCK, then the entire find/callback/delete/rebalance
* sequence happens while the lock is held.
*
* Note that the callback MUST NOT alter any of the data which
* is used as the rbtree key, nor attempt to alter the rest of
* the rbtree in any way.
*
* Returns a pointer to the user data in the found node, or NULL if the
* item was not found, or NULL if the item was deleted and the tree was
* created with a freeNode garbage collection routine.
*/
void *rbtree_callbydata(rbtree_t *tree, void const *data, rb_comparator_t compare, void *context);

/*
* FIFOs
*/
Expand Down
51 changes: 0 additions & 51 deletions src/lib/rbtree.c
Expand Up @@ -542,38 +542,6 @@ void *rbtree_finddata(rbtree_t *tree, void const *data)
return x->data;
}

/** Find a node by data, perform a compare, and perhaps delete the node.
*
*/
void *rbtree_callbydata(rbtree_t *tree, void const *data, rb_comparator_t compare, void *context) {
rbnode_t *current;

PTHREAD_MUTEX_LOCK(tree);

current = tree->root;
while (current != NIL) {
int result = tree->compare(data, current->data);

if (result == 0) {
void *our_data = current->data;

if (compare(context, our_data) > 0) {
rbtree_delete_internal(tree, current, true);
if (tree->free) {
our_data = NULL;
}
}
PTHREAD_MUTEX_UNLOCK(tree);
return our_data;
} else {
current = (result < 0) ? current->left : current->right;
}
}

PTHREAD_MUTEX_UNLOCK(tree);
return NULL;
}

/** Walk the tree, Pre-order
*
* We call ourselves recursively for each function, but that's OK,
Expand Down Expand Up @@ -770,22 +738,3 @@ void *rbtree_node2data(UNUSED rbtree_t *tree, rbnode_t *node)

return node->data;
}

/*
* Return left-most child.
*/
void *rbtree_min(rbtree_t *tree)
{
void *data;
rbnode_t *current;

if (!tree || !tree->root) return NULL;

PTHREAD_MUTEX_LOCK(tree);
current = tree->root;
while (current->left != NIL) current = current->left;

data = current->data;
PTHREAD_MUTEX_UNLOCK(tree);
return data;
}

0 comments on commit 7631ecc

Please sign in to comment.