data_structures
src
data_structures
rbt
rbt_get.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* rbt_get.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/17 22:11:54 by unite #+# #+# */
10
/* Updated: 2020/07/18 16:56:42 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
rbt.h
"
15
16
void
*
rbt_get
(
const
t_rbt
*rbt,
const
void
*key)
17
{
18
t_rbt_node
*node;
19
int
cmp;
20
21
node = rbt->
root
;
22
while
(node != NULL)
23
{
24
cmp = rbt->
key_type
->
cmp
(key, node->
key
);
25
if
(cmp < 0)
26
node = node->
left
;
27
else
if
(cmp > 0)
28
node = node->
right
;
29
else
30
return
(node->
val
);
31
}
32
return
(NULL);
33
}
s_rbt
A left-leaning red-black binary search tree.
Definition:
rbt.h:72
s_type::cmp
int(* cmp)(const void *, const void *)
(optional) A function ponter used to compare members of this data type
Definition:
types.h:52
s_rbt_node::right
struct s_rbt_node * right
The right child.
Definition:
rbt.h:56
s_rbt_node::left
struct s_rbt_node * left
The left child.
Definition:
rbt.h:55
s_rbt_node::key
void * key
The key.
Definition:
rbt.h:53
rbt_get
void * rbt_get(const t_rbt *rbt, const void *key)
Returns the value associated with a specified key.
Definition:
rbt_get.c:16
s_rbt::key_type
const t_type * key_type
The type of keys in the tree.
Definition:
rbt.h:75
rbt.h
s_rbt_node
A node in a red-black tree.
Definition:
rbt.h:51
s_rbt::root
t_rbt_node * root
The root of the tree.
Definition:
rbt.h:74
s_rbt_node::val
void * val
The value.
Definition:
rbt.h:54
Generated by
1.8.16