1 /* libcomps - C alternative to yum.comps library
2  * Copyright (C) 2013 Jindrich Luza
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to  Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
17  * USA
18  */
19 
20 #ifndef COMPS_MRADIX_H
21 #define COMPS_MRADIX_H
22 
23 #include <stdlib.h>
24 #include <string.h>
25 #include "comps_hslist.h"
26 
27 typedef struct {
28     char * key;
29     unsigned is_leaf;
30     COMPS_HSList * subnodes;
31     COMPS_HSList * data;
32 } COMPS_MRTreeData;
33 
34 typedef struct {
35     COMPS_HSList *  subnodes;
36     void* (*data_constructor)(void*);
37     void* (*data_cloner)(void*);
38     void (*data_destructor)(void*);
39 } COMPS_MRTree;
40 
41 void comps_mrtree_data_destroy(COMPS_MRTreeData * rtd);
42 void comps_mrtree_data_destroy_v(void * rtd);
43 COMPS_MRTreeData * comps_mrtree_data_create(COMPS_MRTree* tree,
44                                             char * key, void * data);
45 COMPS_MRTreeData * comps_mrtree_data_create_n(COMPS_MRTree * tree, char * key,
46                                               size_t keylen, void * data);
47 
48 COMPS_MRTree * comps_mrtree_create(void* (*data_constructor)(void*),
49                                    void* (*data_cloner)(void*),
50                                    void (*data_destructor)(void*));
51 void comps_mrtree_destroy(COMPS_MRTree *rt);
52 
53 void comps_mrtree_set(COMPS_MRTree *rt, char *key, void *data);
54 void comps_mrtree_set_n(COMPS_MRTree * rt, char * key, size_t len, void * data);
55 
56 COMPS_HSList* comps_mrtree_get(COMPS_MRTree *rt, const char *key);
57 COMPS_HSList** comps_mrtree_getp(COMPS_MRTree *rt, const char *key);
58 
59 void comps_mrtree_unset(COMPS_MRTree *rt, const char *key);
60 void comps_mrtree_clear(COMPS_MRTree *rt);
61 
62 void comps_mrtree_values_walk(COMPS_MRTree *rt, void *udata,
63                               void (*walk_f)(void*, void*));
64 COMPS_MRTree * comps_mrtree_clone(COMPS_MRTree *rt);
65 COMPS_HSList* comps_mrtree_keys(COMPS_MRTree *rt);
66 void comps_mrtree_unite(COMPS_MRTree *rt1, COMPS_MRTree *rt2);
67 
68 #endif
69