blob: 9d5e375aafc8000028f310403ae758568d8eb019 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include <stdio.h>
#include <stdlib.h>
#include "debug.h"
#include "dictionnary.h"
#include "custommem.h"
#include "khash.h"
KHASH_SET_INIT_STR(dic);
dic_t *NewDictionnary()
{
dic_t *dic = kh_init(dic);
return dic;
}
void FreeDictionnary(dic_t **d)
{
if(!d || !*d)
return;
kh_dic_t* dic = (kh_dic_t*)*d;
const char* k;
kh_foreach_key(dic, k, box_free((void*)k));
kh_destroy(dic, dic);
*d = NULL;
}
const char* AddDictionnary(dic_t* d, const char* s)
{
kh_dic_t* dic = (kh_dic_t*)d;
khint_t k = kh_get(dic, dic, s);
if(k!=kh_end(dic))
return kh_key(dic, k);
char* n = box_strdup(s);
int ret;
k = kh_put(dic, dic, n, &ret);
return n;
}
int ExistDictionnary(dic_t* d, const char* s)
{
kh_dic_t* dic = (kh_dic_t*)d;
khint_t k = kh_get(dic, dic, s);
if(k!=kh_end(dic))
return 1;
return 0;
}
|