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_DICT_H
21 #define COMPS_DICT_H
22 
23 #include "comps_radix.h"
24 #include "comps_mradix.h"
25 
26 typedef COMPS_RTree COMPS_Dict;
27 typedef COMPS_MRTree COMPS_MDict;
28 
29 COMPS_Dict* comps_dict_create(void* (*data_constructor)(void*),
30                                      void* (*data_cloner)(void*),
31                                      void (*data_destructor)(void*));
32 COMPS_MDict* comps_mdict_create(void* (*data_constructor)(void*),
33                                        void* (*data_cloner)(void*),
34                                        void (*data_destructor)(void*));
35 
36 void comps_dict_destroy(COMPS_Dict *rt);
37 void comps_dict_destroy_v(void *rt);
38 void comps_mdict_destroy(COMPS_MDict *rt);
39 void comps_mdict_destroy_v(void *rt);
40 
41 void comps_dict_set(COMPS_Dict *rt, char *key, void *data);
42 void comps_dict_set_n(COMPS_Dict *rt, char *key, unsigned int len, void *data);
43 void comps_mdict_set(COMPS_MDict *rt, char *key, void *data);
44 void comps_mdict_set_n(COMPS_MDict *rt, char *key, unsigned int len,
45                             void *data);
46 
47 void* comps_dict_get(COMPS_Dict *rt, const char *key);
48 COMPS_HSList * comps_mdict_get(COMPS_MDict *rt, const char *key);
49 COMPS_HSList ** comps_mdict_getp(COMPS_MDict *rt, const char * key);
50 
51 void comps_dict_unset(COMPS_Dict * rt, const char * key);
52 void comps_mdict_unset(COMPS_MDict * rt, const char * key);
53 
54 void comps_dict_clear(COMPS_Dict * rt);
55 void comps_mdict_clear(COMPS_MDict * rt);
56 
57 COMPS_HSList * comps_dict_values(COMPS_Dict * rt);
58 
59 void comps_dict_values_walk(COMPS_RTree *rt, void *udata,
60                               void (*walk_f)(void*, void*));
61 void comps_mdict_values_walk(COMPS_MDict *rt, void *udata,
62                               void (*walk_f)(void*, void*));
63 
64 COMPS_Dict* comps_dict_clone(COMPS_Dict *rt);
65 void * comps_dict_clone_v(void * rt);
66 
67 COMPS_MDict* comps_mdict_clone(COMPS_MDict *rt);
68 void* comps_mdict_clone_v(void *rt);
69 
70 COMPS_HSList* comps_mdict_keys(COMPS_MDict *rt);
71 COMPS_HSList* comps_dict_keys(COMPS_Dict *rt);
72 COMPS_HSList* comps_dict_pairs(COMPS_Dict *rt);
73 void comps_mdict_unite(COMPS_MDict *d1, COMPS_MDict *d2);
74 COMPS_Dict* comps_dict_union(COMPS_Dict *d1, COMPS_Dict *d2);
75 
76 #endif
77