gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1
4#ifndef __HASH
5#define __HASH
6typedef struct Hash_ *Hash;
7struct Hash_ {
8 void ** table;
9 size_t size;
11};
12
13void hini(const Hash, const uint);
14void hdel(const Hash, void (*)(MemPool, void *));
15void hend(const Hash);
16ANN unsigned int hash(const m_str s0);
17
18#define haction(type, ret_type, argtype, prefix, func, pre, cmp, action, post, \
19 ret) \
20 ret_type prefix##_##func(const Hash h, argtype arg) { \
21 const unsigned int idx = hash((m_str)arg) % h->size; \
22 const type sym = h->table[idx]; \
23 pre for (type s = sym; s; s = s->next) { \
24 if (cmp) { action } \
25 post \
26 } \
27 ret; \
28 }
29
30// should go to ast
31#define hstraction(type, ret_type, func, pre, action, post, ret) \
32 haction(type, ret_type, m_str, macro, func, pre, !strcmp(s->name, arg), \
33 action, post, ret)
34#endif
unsigned int uint
Definition defs.h:63
#define ANN
Definition defs.h:19
char * m_str
Definition gwcommon.h:14
struct Hash_ * Hash
Definition hash.h:6
void hdel(const Hash, void(*)(MemPool, void *))
Definition hash.c:8
ANN unsigned int hash(const m_str s0)
void hini(const Hash, const uint)
Definition hash.c:3
void hend(const Hash)
Definition hash.c:18
Definition hash.h:7
void ** table
Definition hash.h:8
MemPool p
Definition hash.h:10
size_t size
Definition hash.h:9