gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
hash.c
Go to the documentation of this file.
1#include "gwion_util.h"
2
3void hini(Hash h, const uint nmemb) {
4 h->table = (void *)xcalloc(((nmemb + 3) & 0xfffffffc), sizeof(void *));
5 h->size = nmemb;
6}
7
8void hdel(const Hash h, void (*func)(MemPool, void *)) {
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}
17
18void hend(const Hash h) { xfree(h->table); }
19
20__attribute__((hot, pure)) unsigned int hash(const m_str s0) {
21 unsigned int h = 0;
22 const unsigned char *s;
23 for (s = (unsigned char *)s0; *s; ++s) h = h * 65599 + *s;
24 return h;
25}
unsigned int uint
Definition defs.h:63
char * m_str
Definition gwcommon.h:14
meta header (use this to include the whole library)
void hini(Hash h, const uint nmemb)
Definition hash.c:3
void hdel(const Hash h, void(*func)(MemPool, void *))
Definition hash.c:8
void hend(const Hash h)
Definition hash.c:18
__attribute__((hot, pure))
Definition hash.c:20
ANN unsigned int hash(const m_str s0)
Definition hash.h:7
void ** table
Definition hash.h:8
MemPool p
Definition hash.h:10
size_t size
Definition hash.h:9
#define xfree(a)
Definition xalloc.h:28
static ANEW void * xcalloc(const m_uint n, const m_uint sz)
Definition xalloc.h:18