|
static struct bstreenode * | add_node (struct bstreenode *currentnode, const void *object, size_t objsize, struct bstree *tree) |
|
static void * | find_node (const struct bstreenode *currentnode, const void *searchobj, int(*comp)(const void *, const void *)) |
|
static int | get_counter_node (const struct bstreenode *currentnode, const void *searchobj, int(*comp)(const void *, const void *)) |
|
static void * | find_next_node (const struct bstreenode *currentnode, const void *searchobj, int(*comp)(const void *, const void *)) |
|
static void * | find_prev_node (const struct bstreenode *currentnode, const void *searchobj, int(*comp)(const void *, const void *)) |
|
static void * | upd_node (struct bstreenode *currentnode, const void *updobj, size_t objsize, int(*comp)(const void *, const void *)) |
|
static struct bstreenode * | del_node (struct bstreenode *currentnode, const void *searchobj, struct bstree *tree) |
|
static struct bstreenode * | free_bstree (struct bstreenode *currentnode) |
|
static struct bstreenode * | free_bst_node (struct bstreenode *currentnode) |
|
static struct bstobjcoord * | find_next_node_trace (const struct bstreenode *currentnode, struct bstobjcoord *searchobj, int(*comp)(const void *, const void *)) |
|
struct bstree * | cre_bst (int unique, int(*comp)(const void *, const void *)) |
| Create a binary search tree. More...
|
|
struct bstree * | add_bst_node (struct bstree *tree, const void *object, size_t objsize) |
| Add a node to a binary search tree. More...
|
|
void * | find_bst_node (const struct bstree *tree, const void *searchobj) |
| Find an exact object match. More...
|
|
int | get_counter_bst_node (const struct bstree *tree, const void *searchobj) |
| Get the counter for a node. More...
|
|
void * | find_next_bst_node (const struct bstree *tree, const void *searchobj) |
| Find the next node. More...
|
|
void * | find_prev_bst_node (const struct bstree *tree, const void *searchobj) |
| Find the previous node. More...
|
|
void * | upd_bst_node (const struct bstree *tree, const void *updobj, size_t objsize) |
| Update a node's object. More...
|
|
struct bstree * | del_bst_node (struct bstree *tree, const void *searchobj) |
| Delete a node. More...
|
|
struct bstree * | del_bst (struct bstree *tree) |
| Delete a bst. More...
|
|
Builds, searches and releases a binary search tree.
This implementation supports object independence by using a comparison function which conforms to the prototype:-
int (*comp)(const void *, const void *)
and which returns the value of:-
< 0 if the first parameter is less than the second,
0 if they are equal and
> 0 if the first is greater than the second.
In fact, the same as strcmp().
- Author
- Copyright (C) 2015-2022 Mark Grant
Released under the GPLv3 only.
SPDX-License-Identifier: GPL-3.0-only
- Version
- v1.1.11 ==== 16/09/2022
struct bstree * add_bst_node |
( |
struct bstree * |
tree, |
|
|
const void * |
object, |
|
|
size_t |
objsize |
|
) |
| |
Add a node to a binary search tree.
Attempts to add a node to a binary search tree. If the node exists and unique is true for this tree, an error is generated, if unique is false then the node counter is incremented. On error mge_errno is set and NULL is returned but the bst will remain as before the failed add. Hence it is important to preserve the pointer to the tree across this function.
tmp_tree = add_bst_node(tree, object, objsize);
if (tmp_tree == NULL) {
... error handling
return error;
}
tree = tmp_tree;
- Parameters
-
tree | The tree to add to. |
object | The object to add. |
objsize | The size of the object. |
- Returns
- A pointer to the binary tree 'tree' or NULL on error.