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