data_structures
Data Structures | Typedefs | Functions
bst.h File Reference
#include <errno.h>
#include <sys/types.h>
#include "types.h"
#include "utils.h"
+ Include dependency graph for bst.h:

Go to the source code of this file.

Data Structures

struct  s_bst_node
 A node in a binary search tree. More...
 
struct  s_bst
 A binary search tree. More...
 

Typedefs

typedef struct s_bst_node t_bst_node
 
typedef struct s_bst t_bst
 

Functions

t_bstbst_new (const t_type *key_type, const t_type *val_type)
 Initializes a new empty tree. More...
 
void bst_put (t_bst *bst, const void *key, const void *val)
 Adds a new item to the tree or overwrites an existing one. More...
 
void * bst_get (const t_bst *bst, const void *key)
 Returns the value associated with a specified key. More...
 
size_t bst_size (const t_bst *bst)
 Returns the number of elements in this tree. More...
 
void bst_delete (t_bst *bst)
 Deletes this tree and free all its items and the associated data. More...
 
size_t bst_height (const t_bst *bst)
 Returns the number of tiers in the tree. More...
 

Function Documentation

◆ bst_delete()

void bst_delete ( t_bst bst)

Deletes this tree and free all its items and the associated data.

Does nothing if the argument is NULL.

Definition at line 34 of file bst_delete.c.

◆ bst_get()

void* bst_get ( const t_bst bst,
const void *  key 
)

Returns the value associated with a specified key.

Parameters
keyThe key to search for
Returns
The value associated with the key, or NULL if the key is not in the tree.

Definition at line 16 of file bst_get.c.

◆ bst_height()

size_t bst_height ( const t_bst bst)

Returns the number of tiers in the tree.

Returns
The number of tiers
Remarks
(used primarily for debugging purposes)

Definition at line 28 of file bst_height.c.

◆ bst_new()

t_bst* bst_new ( const t_type key_type,
const t_type val_type 
)

Initializes a new empty tree.

Parameters
key_typeThe type of keys
val_typeThe type of values
Returns
The new tree, or NULL on failure. In case of an error, errno is set accordingly.
Note
For this function to work, the datatype in this array must be comparable (i.e. implement the cmp function).

Definition at line 16 of file bst_new.c.

◆ bst_put()

void bst_put ( t_bst bst,
const void *  key,
const void *  val 
)

Adds a new item to the tree or overwrites an existing one.

Parameters
keyThe key to be copied
valThe value to be copied

Definition at line 46 of file bst_put.c.

◆ bst_size()

size_t bst_size ( const t_bst bst)

Returns the number of elements in this tree.

Returns
the number of elements in this tree.

Definition at line 16 of file bst_size.c.