plibsys 0.0.5
ptree.h
Go to the documentation of this file.
1/*
2 * The MIT License
3 *
4 * Copyright (C) 2015-2016 Alexander Saprykin <saprykin.spb@gmail.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * 'Software'), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
61#if !defined (PLIBSYS_H_INSIDE) && !defined (PLIBSYS_COMPILATION)
62# error "Header files shouldn't be included directly, consider using <plibsys.h> instead."
63#endif
64
65#ifndef PLIBSYS_HEADER_PTREE_H
66#define PLIBSYS_HEADER_PTREE_H
67
68#include <pmacros.h>
69#include <ptypes.h>
70
72
74typedef struct PTree_ PTree;
75
82
93 PCompareFunc func);
94
106 PCompareDataFunc func,
107 ppointer data);
108
125 PCompareDataFunc func,
126 ppointer data,
127 PDestroyFunc key_destroy,
128 PDestroyFunc value_destroy);
129
143 ppointer key,
144 ppointer value);
145
157 pconstpointer key);
158
167 pconstpointer key);
168
183 PTraverseFunc traverse_func,
184 ppointer user_data);
185
197
205
215
227
229
230#endif /* PLIBSYS_HEADER_PTREE_H */
Miscellaneous macros.
#define P_BEGIN_DECLS
Starts .h file declarations to be exported as C functions.
Definition pmacros.h:298
#define P_END_DECLS
Closes .h file declarations to be exported as C functions, should be always used after P_BEGIN_DECLS.
Definition pmacros.h:299
#define P_LIB_API
Exports a symbol from a shared library.
Definition pmacros.h:138
P_LIB_API PTreeType p_tree_get_type(const PTree *tree)
Gets a tree algorithm type.
P_LIB_API void p_tree_clear(PTree *tree)
Clears a tree.
PTreeType_
Internal data organization algorithm for PTree.
Definition ptree.h:77
@ P_TREE_TYPE_RB
Red-black self-balancing tree.
Definition ptree.h:79
@ P_TREE_TYPE_BINARY
Unbalanced binary tree.
Definition ptree.h:78
@ P_TREE_TYPE_AVL
AVL self-balancing tree.
Definition ptree.h:80
P_LIB_API void p_tree_foreach(PTree *tree, PTraverseFunc traverse_func, ppointer user_data)
Iterates in-order through the tree nodes.
enum PTreeType_ PTreeType
Internal data organization algorithm for PTree.
struct PTree_ PTree
Tree opaque data structure.
Definition ptree.h:74
P_LIB_API PTree * p_tree_new_with_data(PTreeType type, PCompareDataFunc func, ppointer data)
Initializes new PTree with additional data.
P_LIB_API PTree * p_tree_new_full(PTreeType type, PCompareDataFunc func, ppointer data, PDestroyFunc key_destroy, PDestroyFunc value_destroy)
Initializes new PTree with additional data and memory management.
P_LIB_API ppointer p_tree_lookup(PTree *tree, pconstpointer key)
Lookups a value by a given key.
P_LIB_API pboolean p_tree_remove(PTree *tree, pconstpointer key)
Removes a key from a tree.
P_LIB_API pint p_tree_get_nnodes(const PTree *tree)
Gets node count.
P_LIB_API PTree * p_tree_new(PTreeType type, PCompareFunc func)
Initializes new PTree.
P_LIB_API void p_tree_free(PTree *tree)
Frees a previously initialized tree object.
P_LIB_API void p_tree_insert(PTree *tree, ppointer key, ppointer value)
Inserts a new key-value pair into a tree.
Types definitions.
void(* PDestroyFunc)(ppointer data)
Object destroy notification function.
Definition ptypes.h:1097
pint(* PCompareDataFunc)(pconstpointer a, pconstpointer b, ppointer data)
Compares two values with additional data.
Definition ptypes.h:1118
const void * pconstpointer
Type for a const pointer.
Definition ptypes.h:111
void * ppointer
Type for a pointer.
Definition ptypes.h:109
pint(* PCompareFunc)(pconstpointer a, pconstpointer b)
Compares two values.
Definition ptypes.h:1107
int pint
Type for an int.
Definition ptypes.h:120
pboolean(* PTraverseFunc)(ppointer key, ppointer value, ppointer user_data)
Function to traverse through a key-value container.
Definition ptypes.h:1080
signed int pboolean
Type for a bool.
Definition ptypes.h:114