Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
rbtree.h
Go to the documentation of this file.
1
/*
2
* rbtree.h -- generic red-black tree
3
*
4
* Copyright (c) 2001-2007, NLnet Labs. All rights reserved.
5
*
6
* This software is open source.
7
*
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
10
* are met:
11
*
12
* Redistributions of source code must retain the above copyright notice,
13
* this list of conditions and the following disclaimer.
14
*
15
* Redistributions in binary form must reproduce the above copyright notice,
16
* this list of conditions and the following disclaimer in the documentation
17
* and/or other materials provided with the distribution.
18
*
19
* Neither the name of the NLNET LABS nor the names of its contributors may
20
* be used to endorse or promote products derived from this software without
21
* specific prior written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*
35
*/
36
42
43
#ifndef UTIL_RBTREE_H_
44
#define UTIL_RBTREE_H_
45
51
typedef
struct
rbnode_type
rbnode_type
;
55
struct
rbnode_type
{
57
rbnode_type
*
parent
;
59
rbnode_type
*
left
;
61
rbnode_type
*
right
;
63
const
void
*
key
;
65
uint8_t
color
;
66
};
67
69
#define RBTREE_NULL &rbtree_null_node
71
extern
rbnode_type
rbtree_null_node
;
72
74
typedef
struct
rbtree_type
rbtree_type
;
76
struct
rbtree_type
{
78
rbnode_type
*
root
;
79
81
size_t
count
;
82
87
int (*
cmp
) (
const
void
*,
const
void
*);
88
};
89
95
rbtree_type
*
rbtree_create
(
int
(*cmpf)(
const
void
*,
const
void
*));
96
102
void
rbtree_init
(
rbtree_type
*rbtree,
int
(*cmpf)(
const
void
*,
const
void
*));
103
110
rbnode_type
*
rbtree_insert
(
rbtree_type
*rbtree,
rbnode_type
*data);
111
119
rbnode_type
*
rbtree_delete
(
rbtree_type
*rbtree,
const
void
*
key
);
120
127
rbnode_type
*
rbtree_search
(
rbtree_type
*rbtree,
const
void
*
key
);
128
138
int
rbtree_find_less_equal
(
rbtree_type
*rbtree,
const
void
*
key
,
139
rbnode_type
**result);
140
146
rbnode_type
*
rbtree_first
(
rbtree_type
*rbtree);
147
153
rbnode_type
*
rbtree_last
(
rbtree_type
*rbtree);
154
160
rbnode_type
*
rbtree_next
(
rbnode_type
*rbtree);
161
167
rbnode_type
*
rbtree_previous
(
rbnode_type
*rbtree);
168
173
#define RBTREE_FOR(node, type, rbtree) \
174
for(node=(type)rbtree_first(rbtree); \
175
(rbnode_type*)node != RBTREE_NULL; \
176
node = (type)rbtree_next((rbnode_type*)node))
177
189
void
traverse_postorder
(
rbtree_type
* tree,
void
(*func)(
rbnode_type
*,
void
*),
190
void
* arg);
191
192
#endif
/* UTIL_RBTREE_H_ */
key
const char * key
Definition
hmac_keccak.cpp:39
rbtree_delete
rbnode_type * rbtree_delete(rbtree_type *rbtree, const void *key)
rbtree_last
rbnode_type * rbtree_last(rbtree_type *rbtree)
rbtree_search
rbnode_type * rbtree_search(rbtree_type *rbtree, const void *key)
rbtree_next
rbnode_type * rbtree_next(rbnode_type *rbtree)
rbtree_previous
rbnode_type * rbtree_previous(rbnode_type *rbtree)
rbtree_insert
rbnode_type * rbtree_insert(rbtree_type *rbtree, rbnode_type *data)
rbtree_null_node
rbnode_type rbtree_null_node
rbtree_init
void rbtree_init(rbtree_type *rbtree, int(*cmpf)(const void *, const void *))
rbtree_create
rbtree_type * rbtree_create(int(*cmpf)(const void *, const void *))
rbtree_find_less_equal
int rbtree_find_less_equal(rbtree_type *rbtree, const void *key, rbnode_type **result)
traverse_postorder
void traverse_postorder(rbtree_type *tree, void(*func)(rbnode_type *, void *), void *arg)
rbtree_first
rbnode_type * rbtree_first(rbtree_type *rbtree)
uint8_t
unsigned char uint8_t
Definition
stdint.h:124
rbnode_type
Definition
rbtree.h:55
rbnode_type::right
rbnode_type * right
Definition
rbtree.h:61
rbnode_type::color
uint8_t color
Definition
rbtree.h:65
rbnode_type::left
rbnode_type * left
Definition
rbtree.h:59
rbnode_type::key
const void * key
Definition
rbtree.h:63
rbnode_type::parent
rbnode_type * parent
Definition
rbtree.h:57
rbtree_type
Definition
rbtree.h:76
rbtree_type::cmp
int(* cmp)(const void *, const void *)
Definition
rbtree.h:87
rbtree_type::count
size_t count
Definition
rbtree.h:81
rbtree_type::root
rbnode_type * root
Definition
rbtree.h:78
external
unbound
util
rbtree.h
Generated on
for Electroneum by
1.17.0