blob: 6fa6771f5ac6a81bff9d8def1fa7d15bbd8569b9 [file] [log] [blame]
Javier Bravo Conde13b0e7d2018-07-09 17:08:51 -05001
2#include <string>
3#include <unordered_map>
4
5extern "C" {
6 int initInt32HashList(void **hl);
7 void deleteInt32HashList(void *hl);
8 void deleteEntryInt32HashList(int32_t k, void *hl);
9 int insertInt32HashList(int32_t k, void *v, void *hl, void **duplicate);
10 int findInt32HashList(int32_t k, void *hl, void **result);
11
12 int initInt64HashList(void **hl);
13 void deleteInt64HashList(void *hl);
14 void deleteEntryInt64HashList(int64_t k, void *hl);
15 int insertInt64HashList(int64_t k, void *v, void *hl, void **duplicate);
16 int findInt64HashList(int64_t k, void *hl, void **result);
17
18 int initUInt32HashList(void **hl);
19 void deleteUInt32HashList(void *hl);
20 void deleteEntryUInt32HashList(uint32_t k, void *hl);
21 int insertUInt32HashList(uint32_t k, void *v, void *hl, void **duplicate);
22 int findUInt32HashList(uint32_t k, void *hl, void **result);
23
24 int initUInt64HashList(void **hl);
25 void deleteUInt64HashList(void *hl);
26 void deleteEntryUInt64HashList(uint64_t k, void *hl);
27 int insertUInt64HashList(uint64_t k, void *v, void *hl, void **duplicate);
28 int findUInt64HashList(uint64_t k, void *hl, void **result);
29
30 int initFloat32HashList(void **hl);
31 void deleteFloat32HashList(void *hl);
32 void deleteEntryFloat32HashList(float k, void *hl);
33 int insertFloat32HashList(float k, void *v, void *hl, void **duplicate);
34 int findFloat32HashList(float k, void *hl, void **result);
35
36 int initFloat64HashList(void **hl);
37 void deleteFloat64HashList(void *hl);
38 void deleteEntryFloat64HashList(double k, void *hl);
39 int insertFloat64HashList(double k, void *v, void *hl, void **duplicate);
40 int findFloat64HashList(double k, void *hl, void **result);
41
42 int initStringHashList(void **hl);
43 void deleteStringHashList(void *hl);
44 void deleteEntryStringHashList(const char *k, void *hl);
45 int insertStringHashList(const char *k, void *v, void *hl, void **duplicate);
46 int findStringHashList(const char *k, void *hl, void **result);
47}
48
49////////////////////////////////////////////////////////////////////////////////
50////////////////////////////////////////////////////////////////////////////////
51
52int initInt32HashList(void **hl)
53{
54 *hl = (void*)(new std::unordered_map<int32_t,void*>());
55 return 0;
56}
57
58void deleteInt32HashList(void *hl)
59{
60 delete (std::unordered_map<int32_t,void*>*)hl;
61}
62
63void deleteEntryInt32HashList(int32_t k, void *hl)
64{
65 std::unordered_map<int32_t,void*> &l( *(std::unordered_map<int32_t,void*>*)hl );
66
67 l.erase(k);
68}
69
70int insertInt32HashList(int32_t k, void *v, void *hl, void **duplicate)
71{
72 std::unordered_map<int32_t,void*> &l( *(std::unordered_map<int32_t,void*>*)hl );
73
74 auto result = l.insert({k,v});
75
76 if (!result.second && duplicate)
77 *duplicate = result.first->second;
78
79 return result.second ? 0 : EEXIST;
80}
81
82int findInt32HashList(int32_t k, void *hl, void **result)
83{
84 if (hl == NULL || result == NULL)
85 return EINVAL;
86
87 int ret = 0;
88 std::unordered_map<int32_t,void*> &l( *(std::unordered_map<int32_t,void*>*)hl );
89
90 auto search = l.find(k);
91
92 if (search != l.end())
93 *result = search->second;
94 else
95 ret = ENOENT;
96
97 return ret;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101////////////////////////////////////////////////////////////////////////////////
102
103int initInt64HashList(void **hl)
104{
105 *hl = (void*)(new std::unordered_map<int64_t,void*>());
106 return 0;
107}
108
109void deleteInt64HashList(void *hl)
110{
111 delete (std::unordered_map<int64_t,void*>*)hl;
112}
113
114void deleteEntryInt64HashList(int64_t k, void *hl)
115{
116 std::unordered_map<int64_t,void*> &l( *(std::unordered_map<int64_t,void*>*)hl );
117
118 l.erase(k);
119}
120
121int insertInt64HashList(int64_t k, void *v, void *hl, void **duplicate)
122{
123 std::unordered_map<int64_t,void*> &l( *(std::unordered_map<int64_t,void*>*)hl );
124
125 auto result = l.insert({k,v});
126
127 if (!result.second && duplicate)
128 *duplicate = result.first->second;
129
130 return result.second ? 0 : EEXIST;
131}
132
133int findInt64HashList(int64_t k, void *hl, void **result)
134{
135 if (hl == NULL || result == NULL)
136 return EINVAL;
137
138 int ret = 0;
139 std::unordered_map<int64_t,void*> &l( *(std::unordered_map<int64_t,void*>*)hl );
140
141 auto search = l.find(k);
142
143 if (search != l.end())
144 *result = search->second;
145 else
146 ret = ENOENT;
147
148 return ret;
149}
150
151////////////////////////////////////////////////////////////////////////////////
152////////////////////////////////////////////////////////////////////////////////
153
154int initUInt32HashList(void **hl)
155{
156 *hl = (void*)(new std::unordered_map<uint32_t,void*>());
157 return 0;
158}
159
160void deleteUInt32HashList(void *hl)
161{
162 delete (std::unordered_map<uint32_t,void*>*)hl;
163}
164
165void deleteEntryUInt32HashList(uint32_t k, void *hl)
166{
167 std::unordered_map<uint32_t,void*> &l( *(std::unordered_map<uint32_t,void*>*)hl );
168
169 l.erase(k);
170}
171
172int insertUInt32HashList(uint32_t k, void *v, void *hl, void **duplicate)
173{
174 std::unordered_map<uint32_t,void*> &l( *(std::unordered_map<uint32_t,void*>*)hl );
175
176 auto result = l.insert({k,v});
177
178 if (!result.second && duplicate)
179 *duplicate = result.first->second;
180
181 return result.second ? 0 : EEXIST;
182}
183
184int findUInt32HashList(uint32_t k, void *hl, void **result)
185{
186 if (hl == NULL || result == NULL)
187 return EINVAL;
188
189 int ret = 0;
190 std::unordered_map<uint32_t,void*> &l( *(std::unordered_map<uint32_t,void*>*)hl );
191
192 auto search = l.find(k);
193
194 if (search != l.end())
195 *result = search->second;
196 else
197 ret = ENOENT;
198
199 return ret;
200}
201
202////////////////////////////////////////////////////////////////////////////////
203////////////////////////////////////////////////////////////////////////////////
204
205int initUInt64HashList(void **hl)
206{
207 *hl = (void*)(new std::unordered_map<uint64_t,void*>());
208 return 0;
209}
210
211void deleteUInt64HashList(void *hl)
212{
213 delete (std::unordered_map<uint64_t,void*>*)hl;
214}
215
216void deleteEntryUInt64HashList(uint64_t k, void *hl)
217{
218 std::unordered_map<uint64_t,void*> &l( *(std::unordered_map<uint64_t,void*>*)hl );
219
220 l.erase(k);
221}
222
223int insertUInt64HashList(uint64_t k, void *v, void *hl, void **duplicate)
224{
225 std::unordered_map<uint64_t,void*> &l( *(std::unordered_map<uint64_t,void*>*)hl );
226
227 auto result = l.insert({k,v});
228
229 if (!result.second && duplicate)
230 *duplicate = result.first->second;
231
232 return result.second ? 0 : EEXIST;
233}
234
235int findUInt64HashList(uint64_t k, void *hl, void **result)
236{
237 if (hl == NULL || result == NULL)
238 return EINVAL;
239
240 int ret = 0;
241 std::unordered_map<uint64_t,void*> &l( *(std::unordered_map<uint64_t,void*>*)hl );
242
243 auto search = l.find(k);
244
245 if (search != l.end())
246 *result = search->second;
247 else
248 ret = ENOENT;
249
250 return ret;
251}
252
253////////////////////////////////////////////////////////////////////////////////
254////////////////////////////////////////////////////////////////////////////////
255
256int initFloat32HashList(void **hl)
257{
258 *hl = (void*)(new std::unordered_map<float,void*>());
259 return 0;
260}
261
262void deleteFloat32HashList(void *hl)
263{
264 delete (std::unordered_map<float,void*>*)hl;
265}
266
267void deleteEntryFloat32HashList(float k, void *hl)
268{
269 std::unordered_map<float,void*> &l( *(std::unordered_map<float,void*>*)hl );
270
271 l.erase(k);
272}
273
274int insertFloat32HashList(float k, void *v, void *hl, void **duplicate)
275{
276 std::unordered_map<float,void*> &l( *(std::unordered_map<float,void*>*)hl );
277
278 auto result = l.insert({k,v});
279
280 if (!result.second && duplicate)
281 *duplicate = result.first->second;
282
283 return result.second ? 0 : EEXIST;
284}
285
286int findFloat32HashList(float k, void *hl, void **result)
287{
288 if (hl == NULL || result == NULL)
289 return EINVAL;
290
291 int ret = 0;
292 std::unordered_map<float,void*> &l( *(std::unordered_map<float,void*>*)hl );
293
294 auto search = l.find(k);
295
296 if (search != l.end())
297 *result = search->second;
298 else
299 ret = ENOENT;
300
301 return ret;
302}
303
304////////////////////////////////////////////////////////////////////////////////
305////////////////////////////////////////////////////////////////////////////////
306
307int initFloat64HashList(void **hl)
308{
309 *hl = (void*)(new std::unordered_map<double,void*>());
310 return 0;
311}
312
313void deleteFloat64HashList(void *hl)
314{
315 delete (std::unordered_map<double,void*>*)hl;
316}
317
318void deleteEntryFloat64HashList(double k, void *hl)
319{
320 std::unordered_map<double,void*> &l( *(std::unordered_map<double,void*>*)hl );
321
322 l.erase(k);
323}
324
325int insertFloat64HashList(double k, void *v, void *hl, void **duplicate)
326{
327 std::unordered_map<double,void*> &l( *(std::unordered_map<double,void*>*)hl );
328
329 auto result = l.insert({k,v});
330
331 if (!result.second && duplicate)
332 *duplicate = result.first->second;
333
334 return result.second ? 0 : EEXIST;
335}
336
337int findFloat64HashList(double k, void *hl, void **result)
338{
339 if (hl == NULL || result == NULL)
340 return EINVAL;
341
342 int ret = 0;
343 std::unordered_map<double,void*> &l( *(std::unordered_map<double,void*>*)hl );
344
345 auto search = l.find(k);
346
347 if (search != l.end())
348 *result = search->second;
349 else
350 ret = ENOENT;
351
352 return ret;
353}
354
355////////////////////////////////////////////////////////////////////////////////
356////////////////////////////////////////////////////////////////////////////////
357
358int initStringHashList(void **hl)
359{
360 *hl = (void*)(new std::unordered_map<std::string,void*>());
361 return 0;
362}
363
364void deleteStringHashList(void *hl)
365{
366 delete (std::unordered_map<std::string,void*>*)hl;
367}
368
369void deleteEntryStringHashList(const char *k, void *hl)
370{
371 std::unordered_map<std::string,void*> &l( *(std::unordered_map<std::string,void*>*)hl );
372
373 l.erase(k);
374}
375
376int insertStringHashList(const char *k, void *v, void *hl, void **duplicate)
377{
378 std::unordered_map<std::string,void*> &l( *(std::unordered_map<std::string,void*>*)hl );
379
380 auto result = l.insert({k,v});
381
382 if (!result.second && duplicate)
383 *duplicate = result.first->second;
384
385 return result.second ? 0 : EEXIST;
386}
387
388int findStringHashList(const char *k, void *hl, void **result)
389{
390 if (hl == NULL || result == NULL)
391 return EINVAL;
392
393 int ret = 0;
394 std::unordered_map<std::string,void*> &l( *(std::unordered_map<std::string,void*>*)hl );
395
396 auto search = l.find(k);
397
398 if (search != l.end())
399 *result = search->second;
400 else
401 ret = ENOENT;
402
403 return ret;
404}