-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhashmap.h
More file actions
executable file
·107 lines (87 loc) · 2.49 KB
/
hashmap.h
File metadata and controls
executable file
·107 lines (87 loc) · 2.49 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef _hashmap_h_
#define _hashmap_h_
#include "dict.h"
/* .h macros */
#define HM_STR_t const void *
#define HM_PTR_t const void *
#define double_t double
/* Get */
#define hm_get_h(type) type##_t hm_##type##_get(HashMap hm, const char * key)
/* for dict structure */
#define field_str entry->v.val
#define field_ptr entry->v.val
#define field_u64 entry->v.u64
#define field_s64 entry->v.s64
#define field_d entry->v.d
#define get_ret(dict, key, field, ret) do { \
dictEntry *entry = dictFind(dict, key); \
return entry ? field : ret; \
} while (0)
/* Set */
#define hm_set_h(type) int hm_##type##_set(HashMap hm, const char *key, type##_t value)
#define set_not_str(settype) do { \
dictEntry *entry = dictAddRaw(hm->dt, key); \
if (entry != NULL) \
{ \
settype(entry, value); \
return DICT_OK; \
} \
return DICT_ERR; \
} while (0)
/* Update */
#define hm_update_h(type) int hm_##type##_update(HashMap hm, const char *key, type##_t newvalue)
#define update_not_str(settype, type) do { \
dictEntry *entry = dictFind(hm->dt, key); \
if (entry != NULL) \
settype(entry, newvalue); \
else \
return hm_set(hm, key, newvalue, type); \
return DICT_OK; \
} while (0)
/* Delete */
#define hm_del_h(type) void hm_##type##_del(HashMap hm, const char *key)
/* API macros */
#define hm_get(hm, key, type) hm_##type##_get(hm, key)
#define hm_set(hm, key, value, type) hm_##type##_set(hm, key, value)
#define hm_update(hm, key, newvalue, type) hm_##type##_update(hm, key, newvalue)
#define hm_del(hm, key, type) hm_##type##_del(hm, key)
typedef struct _hashmap
{
dict *dt;
} _HashMap;
typedef _HashMap* HashMap; /* Basic Type */
HashMap hm_init();
hm_get_h(HM_STR);
hm_get_h(HM_PTR);
hm_get_h(int32);
hm_get_h(uint32);
hm_get_h(int64);
hm_get_h(uint64);
hm_get_h(double);
hm_set_h(HM_STR);
hm_set_h(HM_PTR);
hm_set_h(int32);
hm_set_h(uint32);
hm_set_h(int64);
hm_set_h(uint64);
hm_set_h(double);
hm_update_h(HM_STR);
hm_update_h(HM_PTR);
hm_update_h(int32);
hm_update_h(uint32);
hm_update_h(int64);
hm_update_h(uint64);
hm_update_h(double);
hm_del_h(HM_STR);
hm_del_h(HM_PTR);
hm_del_h(int32);
hm_del_h(uint32);
hm_del_h(int64);
hm_del_h(uint64);
hm_del_h(double);
void hm_release(HashMap hm);
static unsigned int _hashmapELFHash(const void *key);
static void *_hashmapStringDup(const void *data);
static int _hashmapKeyCompare(const void *key1, const void *key2);
static void _hashmapStringDestructor(const void *data);
#endif