Debian Codegraph @

libcdata/libcdata_btree.h

raw symbols SCIP
1 /*
2 * Balanced tree type functions
3 *
4 * Copyright (C) 2006-2024, Joachim Metz <[email protected]>
5 *
6 * Refer to AUTHORS for acknowledgements.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #if !defined( _LIBCDATA_BTREE_H )
23 #define _LIBCDATA_BTREE_H
24
25 #include <common.h>
26 #include <types.h>
27
28 #include "libcdata_extern.h"
29 #include "libcdata_libcerror.h"
30 #include "libcdata_libcthreads.h"
31 #include "libcdata_types.h"
32
33 #if defined( __cplusplus )
34 extern "C" {
35 #endif
36
37 /* The balanced tree uses the list and tree node
38 * The value of a tree node contains a list where each value in the list corresponds with either a sub node or a leaf value
39 * The values array is used for sequential access to the leaf values
40 */
41 typedef struct libcdata_internal_btree libcdata_internal_btree_t;
42
43 struct libcdata_internal_btree
44 {
45 /* The values array
46 */
47 libcdata_array_t *values_array;
48
49 /* The root node
50 */
51 libcdata_tree_node_t *root_node;
52
53 /* The maximum number of values
54 */
55 int maximum_number_of_values;
56
57 #if defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBCDATA )
58 /* The read/write lock
59 */
60 libcthreads_read_write_lock_t *read_write_lock;
61 #endif
62 };
63
64 LIBCDATA_EXTERN \
65 int libcdata_btree_initialize(
66 libcdata_btree_t **tree,
67 int maximum_number_of_sub_nodes,
68 libcerror_error_t **error );
69
70 LIBCDATA_EXTERN \
71 int libcdata_btree_free(
72 libcdata_btree_t **tree,
73 int (*value_free_function)(
74 intptr_t **value,
75 libcerror_error_t **error ),
76 libcerror_error_t **error );
77
78 /* TODO clone function */
79
80 LIBCDATA_EXTERN \
81 int libcdata_btree_get_number_of_values(
82 libcdata_btree_t *tree,
83 int *number_of_values,
84 libcerror_error_t **error );
85
86 LIBCDATA_EXTERN \
87 int libcdata_btree_get_value_by_index(
88 libcdata_btree_t *tree,
89 int value_index,
90 intptr_t **value,
91 libcerror_error_t **error );
92
93 LIBCDATA_EXTERN \
94 int libcdata_btree_get_value_by_value(
95 libcdata_btree_t *tree,
96 intptr_t *value,
97 int (*value_compare_function)(
98 intptr_t *first_value,
99 intptr_t *second_value,
100 libcerror_error_t **error ),
101 libcdata_tree_node_t **upper_node,
102 intptr_t **existing_value,
103 libcerror_error_t **error );
104
105 LIBCDATA_EXTERN \
106 int libcdata_btree_insert_value(
107 libcdata_btree_t *tree,
108 int *value_index,
109 intptr_t *value,
110 int (*value_compare_function)(
111 intptr_t *first_value,
112 intptr_t *second_value,
113 libcerror_error_t **error ),
114 libcdata_tree_node_t **upper_node,
115 intptr_t **existing_value,
116 libcerror_error_t **error );
117
118 LIBCDATA_EXTERN \
119 int libcdata_btree_replace_value(
120 libcdata_btree_t *tree,
121 libcdata_tree_node_t *upper_node,
122 int *value_index,
123 intptr_t *value,
124 int *replacement_value_index,
125 intptr_t *replacement_value,
126 libcerror_error_t **error );
127
128 LIBCDATA_EXTERN \
129 int libcdata_btree_remove_value(
130 libcdata_btree_t *tree,
131 libcdata_tree_node_t *upper_node,
132 int *value_index,
133 intptr_t *value,
134 libcerror_error_t **error );
135
136 #if defined( __cplusplus )
137 }
138 #endif
139
140 #endif /* !defined( _LIBCDATA_BTREE_H ) */
141