gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
hash.h File Reference

Hash table implementation and (near) generic set of macros. More...

Go to the source code of this file.

Data Structures

struct  Hash_
 

Macros

#define haction(type, ret_type, argtype, prefix, func, pre, cmp, action, post, ret)
 
#define hstraction(type, ret_type, func, pre, action, post, ret)
 

Typedefs

typedef struct Hash_Hash
 

Functions

void hini (const Hash, const uint)
 
void hdel (const Hash, void(*)(MemPool, void *))
 
void hend (const Hash)
 
ANN unsigned int hash (const m_str s0)
 

Detailed Description

Hash table implementation and (near) generic set of macros.

Definition in file hash.h.

Macro Definition Documentation

◆ haction

#define haction ( type,
ret_type,
argtype,
prefix,
func,
pre,
cmp,
action,
post,
ret )
Value:
ret_type prefix##_##func(const Hash h, argtype arg) { \
const unsigned int idx = hash((m_str)arg) % h->size; \
const type sym = h->table[idx]; \
pre for (type s = sym; s; s = s->next) { \
if (cmp) { action } \
post \
} \
ret; \
}
#define _(String)
Definition defs.h:13
char * m_str
Definition gwcommon.h:14
ANN unsigned int hash(const m_str s0)
Definition hash.h:7
void ** table
Definition hash.h:8
size_t size
Definition hash.h:9
void void * arg
Definition threadpool.h:27

Definition at line 18 of file hash.h.

◆ hstraction

#define hstraction ( type,
ret_type,
func,
pre,
action,
post,
ret )
Value:
haction(type, ret_type, m_str, macro, func, pre, !strcmp(s->name, arg), \
action, post, ret)
#define haction(type, ret_type, argtype, prefix, func, pre, cmp, action, post, ret)
Definition hash.h:18

Definition at line 31 of file hash.h.

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)

Typedef Documentation

◆ Hash

typedef struct Hash_* Hash

Definition at line 6 of file hash.h.

Function Documentation

◆ hash()

ANN unsigned int hash ( const m_str s0)

◆ hdel()

void hdel ( const Hash h,
void(*)(MemPool, void *) func )

Definition at line 8 of file hash.c.

8 {
9 for (unsigned int i = h->size + 1; --i;) {
10 void *s = h->table[i - 1];
11 if (s) {
12 func(h->p, s);
13 h->table[i - 1] = NULL;
14 }
15 }
16}
MemPool p
Definition hash.h:10

◆ hend()

void hend ( const Hash h)

Definition at line 18 of file hash.c.

18{ xfree(h->table); }
#define xfree(a)
Definition xalloc.h:28

◆ hini()

void hini ( const Hash h,
const uint nmemb )

Definition at line 3 of file hash.c.

3 {
4 h->table = (void *)xcalloc(((nmemb + 3) & 0xfffffffc), sizeof(void *));
5 h->size = nmemb;
6}
static ANEW void * xcalloc(const m_uint n, const m_uint sz)
Definition xalloc.h:18