Kohi Game Engine
u64_bst.h File Reference
#include "defines.h"

Go to the source code of this file.

Data Structures

union  bt_node_value
 
struct  bt_node
 

Typedefs

typedef union bt_node_value bt_node_value
 
typedef struct bt_node bt_node
 

Functions

KAPI bt_nodeu64_bst_insert (bt_node *root, u64 key, bt_node_value value)
 
KAPI bt_nodeu64_bst_delete (bt_node *root, u64 key)
 
KAPI const bt_nodeu64_bst_find (const bt_node *root, u64 key)
 
KAPI void u64_bst_cleanup (bt_node *node)
 

Typedef Documentation

◆ bt_node

typedef struct bt_node bt_node

A binary tree node, which also represents the base node of the BST itself.

◆ bt_node_value

Function Documentation

◆ u64_bst_cleanup()

KAPI void u64_bst_cleanup ( bt_node node)

Performs cleanup operations on the given node and its branches. Recursive.

Parameters
nodeA pointer to the node to cleanup.

◆ u64_bst_delete()

KAPI bt_node* u64_bst_delete ( bt_node root,
u64  key 
)

Attempts to delete a node with the given key from the tree. This should be cleaned up by the caller.

Parameters
rootA pointer to the node to begin the search from.
keyThe key to be deleted.
Returns
A pointer to the deleted key, if found; otherwise 0.

◆ u64_bst_find()

KAPI const bt_node* u64_bst_find ( const bt_node root,
u64  key 
)

Attempts to find a node with the given key.

Parameters
rootA constant pointer to the root node to search from.
keyThe key to search for.
Returns
A constant pointer to the node, if found; otherwise 0/null.

◆ u64_bst_insert()

KAPI bt_node* u64_bst_insert ( bt_node root,
u64  key,
bt_node_value  value 
)

Inserts a node into the given tree (represented by the root node).

Parameters
rootA pointer to the root node.
keyThe key to be inserted.
valueThe value to be inserted. NOTE: The BST does NOT take its own copy of this data.
Returns
A pointer to the inserted node. This should be saved off if creating the root node.