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 #include "comps_dict.h"
21 
comps_dict_create(void * (* data_constructor)(void *),void * (* data_cloner)(void *),void (* data_destructor)(void *))22 inline COMPS_Dict* comps_dict_create(void* (*data_constructor)(void*),
23                                      void* (*data_cloner)(void*),
24                                      void (*data_destructor)(void*)) {
25     return (COMPS_RTree*) comps_rtree_create(data_constructor,
26                                              data_cloner, data_destructor);
27 }
28 
comps_dict_destroy(COMPS_Dict * rt)29 inline void comps_dict_destroy(COMPS_Dict *rt) {
30     comps_rtree_destroy((COMPS_RTree*)rt);
31 }
comps_dict_destroy_v(void * rt)32 inline void comps_dict_destroy_v(void *rt) {
33     comps_rtree_destroy((COMPS_RTree*)rt);
34 }
comps_dict_set(COMPS_Dict * rt,char * key,void * data)35 inline void comps_dict_set(COMPS_Dict *rt, char *key, void *data) {
36     comps_rtree_set((COMPS_RTree*) rt, key, data);
37 }
comps_dict_set_n(COMPS_Dict * rt,char * key,unsigned int len,void * data)38 inline void comps_dict_set_n(COMPS_Dict *rt, char *key, unsigned int len,
39                             void *data) {
40     comps_rtree_set_n((COMPS_RTree*) rt, key, len, data);
41 }
42 
comps_dict_get(COMPS_Dict * rt,const char * key)43 inline void* comps_dict_get(COMPS_Dict *rt, const char *key) {
44     return comps_rtree_get((COMPS_RTree*) rt, key);
45 }
comps_dict_unset(COMPS_Dict * rt,const char * key)46 inline void comps_dict_unset(COMPS_Dict * rt, const char * key) {
47     comps_rtree_unset((COMPS_RTree*) rt, key);
48 }
comps_dict_clear(COMPS_Dict * rt)49 inline void comps_dict_clear(COMPS_Dict * rt) {
50     comps_rtree_clear((COMPS_RTree*) rt);
51 }
comps_dict_values(COMPS_Dict * rt)52 inline COMPS_HSList * comps_dict_values(COMPS_Dict * rt) {
53     return comps_rtree_values((COMPS_RTree*)rt);
54 }
comps_dict_values_walk(COMPS_RTree * rt,void * udata,void (* walk_f)(void *,void *))55 inline void comps_dict_values_walk(COMPS_RTree * rt, void* udata,
56                               void (*walk_f)(void*, void*)) {
57     comps_rtree_values_walk((COMPS_RTree*)rt, udata, walk_f);
58 }
comps_dict_clone(COMPS_Dict * rt)59 inline COMPS_Dict * comps_dict_clone(COMPS_Dict * rt) {
60     return (COMPS_RTree*) comps_rtree_clone((COMPS_RTree*)rt);
61 }
comps_dict_clone_v(void * rt)62 inline void * comps_dict_clone_v(void * rt) {
63     return (COMPS_RTree*) comps_rtree_clone((COMPS_RTree*)rt);
64 }
comps_dict_keys(COMPS_Dict * rt)65 inline COMPS_HSList* comps_dict_keys(COMPS_Dict * rt) {
66     return comps_rtree_keys((COMPS_RTree*)rt);
67 }
comps_dict_pairs(COMPS_Dict * rt)68 inline COMPS_HSList* comps_dict_pairs(COMPS_Dict *rt) {
69     return comps_rtree_pairs((COMPS_RTree*)rt);
70 }
comps_dict_union(COMPS_Dict * d1,COMPS_Dict * d2)71 inline COMPS_Dict* comps_dict_union(COMPS_Dict *d1, COMPS_Dict *d2) {
72     return comps_rtree_union((COMPS_RTree*)d1, (COMPS_RTree*)d2);
73 }
74 
75 
comps_mdict_create(void * (* data_constructor)(void *),void * (* data_cloner)(void *),void (* data_destructor)(void *))76 inline COMPS_MDict* comps_mdict_create(void* (*data_constructor)(void*),
77                                        void* (*data_cloner)(void*),
78                                        void (*data_destructor)(void*)) {
79     return (COMPS_MRTree*) comps_mrtree_create(data_constructor,
80                                                data_cloner, data_destructor);
81 }
82 
comps_mdict_destroy(COMPS_MDict * rt)83 inline void comps_mdict_destroy(COMPS_MDict *rt) {
84     comps_mrtree_destroy((COMPS_MRTree*)rt);
85 }
comps_mdict_destroy_v(void * rt)86 inline void comps_mdict_destroy_v(void *rt) {
87     comps_mrtree_destroy((COMPS_MRTree*)rt);
88 }
89 
comps_mdict_set(COMPS_MDict * rt,char * key,void * data)90 inline void comps_mdict_set(COMPS_MDict *rt, char *key, void *data) {
91     comps_mrtree_set((COMPS_MRTree*) rt, key, data);
92 }
93 
comps_mdict_set_n(COMPS_MDict * rt,char * key,unsigned int len,void * data)94 inline void comps_mdict_set_n(COMPS_MDict *rt, char *key, unsigned int len,
95                             void *data) {
96     comps_mrtree_set_n((COMPS_MRTree*) rt, key, len, data);
97 }
98 
comps_mdict_get(COMPS_MDict * rt,const char * key)99 inline COMPS_HSList* comps_mdict_get(COMPS_MDict *rt, const char *key) {
100     return comps_mrtree_get((COMPS_MRTree*) rt, key);
101 }
comps_mdict_getp(COMPS_MDict * rt,const char * key)102 inline COMPS_HSList** comps_mdict_getp(COMPS_MDict *rt, const char *key) {
103     return comps_mrtree_getp((COMPS_MRTree*) rt, key);
104 }
comps_mdict_unset(COMPS_MDict * rt,const char * key)105 inline void comps_mdict_unset(COMPS_MDict * rt, const char * key) {
106     comps_mrtree_unset((COMPS_MRTree*) rt, key);
107 }
comps_mdict_clear(COMPS_MDict * rt)108 inline void comps_mdict_clear(COMPS_MDict * rt) {
109     comps_mrtree_clear((COMPS_MRTree*) rt);
110 }
comps_mdict_values_walk(COMPS_MDict * rt,void * udata,void (* walk_f)(void *,void *))111 inline void comps_mdict_values_walk(COMPS_MDict * rt, void* udata,
112                               void (*walk_f)(void*, void*)) {
113     comps_mrtree_values_walk((COMPS_MRTree*)rt, udata, walk_f);
114 }
115 
comps_mdict_clone(COMPS_MDict * rt)116 inline COMPS_MDict* comps_mdict_clone(COMPS_MDict * rt) {
117     return (COMPS_MRTree*) comps_mrtree_clone((COMPS_MRTree*)rt);
118 }
comps_mdict_clone_v(void * rt)119 inline void* comps_mdict_clone_v(void *rt) {
120     return (COMPS_MRTree*) comps_mrtree_clone((COMPS_MRTree*)rt);
121 }
comps_mdict_keys(COMPS_MDict * rt)122 inline COMPS_HSList* comps_mdict_keys(COMPS_MDict * rt) {
123     return comps_mrtree_keys((COMPS_MRTree*)rt);
124 }
comps_mdict_unite(COMPS_MDict * d1,COMPS_MDict * d2)125 inline void comps_mdict_unite(COMPS_MDict * d1, COMPS_MDict *d2) {
126     comps_mrtree_unite((COMPS_MRTree*)d1, (COMPS_MRTree*)d2);
127 }
128