ECP-VELOC Components
User documentation for all components
kvtree.h
Go to the documentation of this file.
1 /* Several lines are reproduced from queue.h, under the following license */
2 
3 /*
4  * Copyright (c) 1991, 1993
5  * The Regents of the University of California. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * @(#)queue.h 8.5 (Berkeley) 8/20/94
32  */
33 #ifndef KVTREE_H
34 #define KVTREE_H
35 
36 #include <stdarg.h>
37 #include <sys/types.h>
38 
39 /* enable C++ codes to include this header directly */
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
65 #define KVTREE_VERSION "1.3.0"
66 #define KVTREE_SUCCESS (0)
67 #define KVTREE_MAX_FILENAME (1024)
68 
69 #define KVTREE_PRINT_TREE (1)
70 #define KVTREE_PRINT_KEYVAL (2)
71 
72 /********************************************************/
74 #define KVTREE_SORT_ASCENDING (0)
76 #define KVTREE_SORT_DESCENDING (1)
77 
79 /********************************************************/
81 
84 struct kvtree_elem_struct;
85 
86 // the following 3 lines reproduced from queue.h
89 };
90 
93  char* key;
95  // the following 4 lines reproduced from queue.h
96  struct{
97  struct kvtree_elem_struct *le_next; /* next element */
98  struct kvtree_elem_struct **le_prev; /* address of previos next element */
99  } pointers;
100 };
101 
103 typedef struct kvtree_struct kvtree;
104 typedef struct kvtree_elem_struct kvtree_elem;
106 
107 /********************************************************/
109 
112 kvtree* kvtree_new(void);
113 
115 int kvtree_delete(kvtree** ptr_hash);
117 
118 /********************************************************/
120 
123 int kvtree_size(const kvtree* hash);
124 
126 kvtree* kvtree_get(const kvtree* hash, const char* key);
127 
129 kvtree* kvtree_set(kvtree* hash, const char* key, kvtree* hash_value);
130 
132 kvtree* kvtree_extract(kvtree* hash, const char* key);
133 
135 int kvtree_unset(kvtree* hash, const char* key);
136 
138 int kvtree_unset_all(kvtree* hash);
139 
141 int kvtree_merge(kvtree* hash1, const kvtree* hash2);
142 
145 kvtree* kvtree_setf(kvtree* hash, kvtree* hash_value, const char* format, ...);
146 
148 kvtree* kvtree_getf(const kvtree* hash, const char* format, ...);
149 
151 int kvtree_sort(kvtree* hash, int direction);
152 
154 int kvtree_sort_int(kvtree* hash, int direction);
155 
157 int kvtree_list_int(const kvtree* hash, int* num, int** list);
159 
160 /********************************************************/
162 
165 kvtree* kvtree_set_kv(kvtree* hash, const char* key, const char* val);
166 
168 kvtree* kvtree_set_kv_int(kvtree* hash, const char* key, int val);
169 
171 kvtree* kvtree_get_kv(const kvtree* hash, const char* key, const char* val);
172 
174 kvtree* kvtree_get_kv_int(const kvtree* hash, const char* key, int val);
175 
177 int kvtree_unset_kv(kvtree* hash, const char* key, const char* val);
178 
180 int kvtree_unset_kv_int(kvtree* hash, const char* key, int val);
182 
183 /********************************************************/
185 
188 kvtree_elem* kvtree_elem_first(const kvtree* hash);
189 
191 kvtree_elem* kvtree_elem_next(const kvtree_elem* elem);
192 
194 char* kvtree_elem_key(const kvtree_elem* elem);
195 
197 int kvtree_elem_key_int(const kvtree_elem* elem);
198 
200 kvtree* kvtree_elem_hash(const kvtree_elem* elem);
201 
203 kvtree_elem* kvtree_elem_get(const kvtree* hash, const char* key);
204 
206 char* kvtree_elem_get_first_val(const kvtree* hash, const char* key);
207 
209 kvtree_elem* kvtree_elem_extract(kvtree* hash, const char* key);
210 
212 kvtree_elem* kvtree_elem_extract_int(kvtree* hash, int key);
213 
215 kvtree_elem* kvtree_elem_extract_by_addr(kvtree* hash, kvtree_elem* elem);
216 
217 char* kvtree_get_val(const kvtree* hash, const char* key);
219 
220 /********************************************************/
222 
225 size_t kvtree_pack_size(const kvtree* hash);
226 
228 size_t kvtree_pack(char* buf, const kvtree* hash);
229 
231 size_t kvtree_unpack(const char* buf, kvtree* hash);
233 
234 /********************************************************/
236 
240 int kvtree_write_persist(void** ptr_buf, size_t* ptr_size, const kvtree* hash);
241 
243 ssize_t kvtree_write_fd(const char* file, int fd, const kvtree* hash);
244 
246 ssize_t kvtree_read_fd(const char* file, int fd, kvtree* hash);
247 
249 int kvtree_write_file(const char* file, const kvtree* hash);
250 
252 int kvtree_read_file(const char* file, kvtree* hash);
253 
255 int kvtree_read_with_lock(const char* file, kvtree* hash);
256 
258 int kvtree_write_with_lock(const char* file, kvtree* hash);
259 
263 int kvtree_lock_open_read(const char* file, int* fd, kvtree* hash);
264 
266 int kvtree_write_close_unlock(const char* file, int* fd, const kvtree* hash);
267 
277 int kvtree_write_to_gather(const char* prefix, kvtree* data, int ranks);
279 
280 /* Read a scatter/gather file and all of its subfiles into a single kvtree */
281 int kvtree_read_scatter_single(const char* prefix, kvtree* data);
282 
283 /********************************************************/
285 
288 int kvtree_print(const kvtree* hash, int indent);
289 
291 int kvtree_print_mode(const kvtree* hash, int indent, int mode);
292 
294 int kvtree_log(const kvtree* hash, int log_level, int indent);
296 
298 #ifdef __cplusplus
299 } /* extern "C" */
300 #endif
301 
302 #endif
kvtree_unset_kv_int
int kvtree_unset_kv_int(kvtree *hash, const char *key, int val)
kvtree_delete
int kvtree_delete(kvtree **ptr_hash)
kvtree_print_mode
int kvtree_print_mode(const kvtree *hash, int indent, int mode)
kvtree_write_persist
int kvtree_write_persist(void **ptr_buf, size_t *ptr_size, const kvtree *hash)
kvtree_read_fd
ssize_t kvtree_read_fd(const char *file, int fd, kvtree *hash)
kvtree_elem_struct::le_prev
struct kvtree_elem_struct ** le_prev
Definition: kvtree.h:98
kvtree_extract
kvtree * kvtree_extract(kvtree *hash, const char *key)
kvtree_unset
int kvtree_unset(kvtree *hash, const char *key)
kvtree_struct::lh_first
struct kvtree_elem_struct * lh_first
Definition: kvtree.h:88
kvtree_read_scatter_single
int kvtree_read_scatter_single(const char *prefix, kvtree *data)
kvtree_unset_all
int kvtree_unset_all(kvtree *hash)
kvtree_pack
size_t kvtree_pack(char *buf, const kvtree *hash)
kvtree_set_kv
kvtree * kvtree_set_kv(kvtree *hash, const char *key, const char *val)
kvtree_get
kvtree * kvtree_get(const kvtree *hash, const char *key)
kvtree_size
int kvtree_size(const kvtree *hash)
kvtree_unpack
size_t kvtree_unpack(const char *buf, kvtree *hash)
kvtree_get_val
char * kvtree_get_val(const kvtree *hash, const char *key)
kvtree_set_kv_int
kvtree * kvtree_set_kv_int(kvtree *hash, const char *key, int val)
kvtree_get_kv_int
kvtree * kvtree_get_kv_int(const kvtree *hash, const char *key, int val)
kvtree_pack_size
size_t kvtree_pack_size(const kvtree *hash)
kvtree_elem_struct
Definition: kvtree.h:92
kvtree_write_close_unlock
int kvtree_write_close_unlock(const char *file, int *fd, const kvtree *hash)
kvtree_lock_open_read
int kvtree_lock_open_read(const char *file, int *fd, kvtree *hash)
kvtree_elem_extract
kvtree_elem * kvtree_elem_extract(kvtree *hash, const char *key)
kvtree_merge
int kvtree_merge(kvtree *hash1, const kvtree *hash2)
kvtree_sort
int kvtree_sort(kvtree *hash, int direction)
kvtree_elem_hash
kvtree * kvtree_elem_hash(const kvtree_elem *elem)
kvtree_read_file
int kvtree_read_file(const char *file, kvtree *hash)
kvtree_setf
kvtree * kvtree_setf(kvtree *hash, kvtree *hash_value, const char *format,...)
kvtree_list_int
int kvtree_list_int(const kvtree *hash, int *num, int **list)
kvtree_write_with_lock
int kvtree_write_with_lock(const char *file, kvtree *hash)
kvtree_write_file
int kvtree_write_file(const char *file, const kvtree *hash)
kvtree_write_fd
ssize_t kvtree_write_fd(const char *file, int fd, const kvtree *hash)
kvtree_unset_kv
int kvtree_unset_kv(kvtree *hash, const char *key, const char *val)
kvtree_read_with_lock
int kvtree_read_with_lock(const char *file, kvtree *hash)
kvtree_print
int kvtree_print(const kvtree *hash, int indent)
kvtree_getf
kvtree * kvtree_getf(const kvtree *hash, const char *format,...)
kvtree_get_kv
kvtree * kvtree_get_kv(const kvtree *hash, const char *key, const char *val)
kvtree_elem_extract_int
kvtree_elem * kvtree_elem_extract_int(kvtree *hash, int key)
kvtree_write_to_gather
int kvtree_write_to_gather(const char *prefix, kvtree *data, int ranks)
kvtree_elem_next
kvtree_elem * kvtree_elem_next(const kvtree_elem *elem)
kvtree_elem_key_int
int kvtree_elem_key_int(const kvtree_elem *elem)
kvtree_elem_struct::le_next
struct kvtree_elem_struct * le_next
Definition: kvtree.h:97
kvtree_log
int kvtree_log(const kvtree *hash, int log_level, int indent)
kvtree_sort_int
int kvtree_sort_int(kvtree *hash, int direction)
kvtree_new
kvtree * kvtree_new(void)
kvtree_elem_struct::hash
struct kvtree_struct * hash
Definition: kvtree.h:94
kvtree_elem_get
kvtree_elem * kvtree_elem_get(const kvtree *hash, const char *key)
kvtree_elem_first
kvtree_elem * kvtree_elem_first(const kvtree *hash)
kvtree_struct
Definition: kvtree.h:87
kvtree_elem_struct::pointers
struct kvtree_elem_struct::@0 pointers
kvtree_set
kvtree * kvtree_set(kvtree *hash, const char *key, kvtree *hash_value)
kvtree_elem_key
char * kvtree_elem_key(const kvtree_elem *elem)
kvtree_elem_struct::key
char * key
Definition: kvtree.h:93
kvtree_elem_extract_by_addr
kvtree_elem * kvtree_elem_extract_by_addr(kvtree *hash, kvtree_elem *elem)
kvtree_elem_get_first_val
char * kvtree_elem_get_first_val(const kvtree *hash, const char *key)