data_structures
bst.h
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* bst.h :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/17 22:00:24 by unite #+# #+# */
10 /* Updated: 2020/09/07 22:15:57 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #ifndef BST_H
15 
16 # define BST_H
17 
18 # include <errno.h>
19 # include <sys/types.h>
20 # include "types.h"
21 # include "utils.h"
22 
36 typedef struct s_bst_node
37 {
38  void *key;
39  void *val;
40  struct s_bst_node *left;
41  struct s_bst_node *right;
42 } t_bst_node;
43 
57 typedef struct s_bst
58 {
60  size_t size;
61  const t_type *key_type;
62  const t_type *val_type;
63 } t_bst;
64 
75 t_bst *bst_new(const t_type *key_type, const t_type *val_type);
76 
83 void bst_put(t_bst *bst, const void *key, const void *val);
84 
92 void *bst_get(const t_bst *bst, const void *key);
93 
99 size_t bst_size(const t_bst *bst);
100 
106 void bst_delete(t_bst *bst);
107 
114 size_t bst_height(const t_bst *bst);
115 
116 #endif
bst_get
void * bst_get(const t_bst *bst, const void *key)
Returns the value associated with a specified key.
Definition: bst_get.c:16
bst_delete
void bst_delete(t_bst *bst)
Deletes this tree and free all its items and the associated data.
Definition: bst_delete.c:34
types.h
s_bst_node
A node in a binary search tree.
Definition: bst.h:36
bst_size
size_t bst_size(const t_bst *bst)
Returns the number of elements in this tree.
Definition: bst_size.c:16
s_bst_node::val
void * val
The value.
Definition: bst.h:39
utils.h
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.
Definition: bst_put.c:46
s_bst::val_type
const t_type * val_type
The type of values in the ree.
Definition: bst.h:62
s_bst::key_type
const t_type * key_type
The type of keys in the tree.
Definition: bst.h:61
s_bst::size
size_t size
The number of elements in this tree.
Definition: bst.h:60
s_bst_node::right
struct s_bst_node * right
The right child.
Definition: bst.h:41
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
s_bst_node::left
struct s_bst_node * left
The left child.
Definition: bst.h:40
s_bst_node::key
void * key
The key.
Definition: bst.h:38
s_bst
A binary search tree.
Definition: bst.h:57
bst_height
size_t bst_height(const t_bst *bst)
Returns the number of tiers in the tree.
Definition: bst_height.c:28
bst_new
t_bst * bst_new(const t_type *key_type, const t_type *val_type)
Initializes a new empty tree.
Definition: bst_new.c:16
s_bst::root
t_bst_node * root
The root of the tree.
Definition: bst.h:59