libuproc  1.2.0
bst.h
Go to the documentation of this file.
1 /* Copyright 2014 Peter Meinicke, Robin Martinjak
2  *
3  * This file is part of libuproc.
4  *
5  * libuproc is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License as published by the Free
7  * Software Foundation, either version 3 of the License, or (at your option)
8  * any later version.
9  *
10  * libuproc is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libuproc. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
30 #ifndef UPROC_BST_H
31 #define UPROC_BST_H
32 
33 #include <stdlib.h>
34 #include <stdint.h>
35 
36 #include "uproc/common.h"
37 #include "uproc/word.h"
38 
82 typedef struct uproc_bst_s uproc_bst;
83 
86 {
88  uintmax_t uint;
89 
91  struct uproc_word word;
92 };
93 
98 
101 };
102 
104 enum {
108 
111 };
112 
118 uproc_bst *uproc_bst_create(enum uproc_bst_keytype key_type, size_t value_size);
119 
122 
125 
127 size_t uproc_bst_size(const uproc_bst *t);
128 
140 int uproc_bst_insert(uproc_bst *t, union uproc_bst_key key, const void *value);
141 
150 int uproc_bst_update(uproc_bst *t, union uproc_bst_key key, const void *value);
151 
163 int uproc_bst_get(uproc_bst *t, union uproc_bst_key key, void *value);
164 
175 int uproc_bst_remove(uproc_bst *t, union uproc_bst_key key, void *value);
176 
188 void uproc_bst_map(const uproc_bst *t,
189  void (*func)(union uproc_bst_key, void *, void *),
190  void *opaque);
205 typedef struct uproc_bstiter_s uproc_bstiter;
206 
220 
232 int uproc_bstiter_next(uproc_bstiter *iter, union uproc_bst_key *key,
233  void *value);
234 
237 
244 #endif
The BST key type.
Definition: bst.h:85
BST in-order iterator.
int uproc_bst_remove(uproc_bst *t, union uproc_bst_key key, void *value)
Remove item.
uproc_bst_keytype
Which member of union uproc_bst_key is used.
Definition: bst.h:95
int uproc_bst_insert(uproc_bst *t, union uproc_bst_key key, const void *value)
Insert item.
BST already contains an item with the given key.
Definition: bst.h:110
.word (struct uproc_word)
Definition: bst.h:100
void uproc_bst_destroy(uproc_bst *t)
Destroy BST and all contained nodes.
uintmax_t uint
Unsigned integer.
Definition: bst.h:88
void uproc_bst_map(const uproc_bst *t, void(*func)(union uproc_bst_key, void *, void *), void *opaque)
Apply function to all items.
struct uproc_word word
Amino acid word.
Definition: bst.h:91
uproc_bstiter * uproc_bstiter_create(const uproc_bst *t)
Create BST in-order iterator.
uproc_bst * uproc_bst_create(enum uproc_bst_keytype key_type, size_t value_size)
Initialize an empty binary search tree.
Module: Amino acid words.
int uproc_bst_update(uproc_bst *t, union uproc_bst_key key, const void *value)
Insert or update item.
Binary search tree.
size_t uproc_bst_size(const uproc_bst *t)
Return the number of nodes.
int uproc_bstiter_next(uproc_bstiter *iter, union uproc_bst_key *key, void *value)
Obtain next key/value pair.
BST doesn't contain an item with the given key.
Definition: bst.h:107
Module: Common definitions.
void uproc_bstiter_destroy(uproc_bstiter *iter)
Destroy BST iterator.
int uproc_bst_get(uproc_bst *t, union uproc_bst_key key, void *value)
Get item.
Amino acid word.
Definition: word.h:45
.uint (uintmax_t)
Definition: bst.h:97
int uproc_bst_isempty(uproc_bst *t)
Return non-zero if the tree is empty.