forked from measurement-factory/dnstop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashtbl.h
48 lines (42 loc) · 1.19 KB
/
hashtbl.h
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
/*
* $Id$
*
* http://dnstop.measurement-factory.com/
*
* Copyright (c) 2006, The Measurement Factory, Inc. All rights
* reserved. See the LICENSE file for details.
*/
typedef struct _hashitem {
const void *key;
void *data;
struct _hashitem *next;
} hashitem;
typedef unsigned int hashfunc(const void *key);
typedef int hashkeycmp(const void *a, const void *b);
typedef struct {
unsigned int modulus;
hashitem **items;
hashfunc *hasher;
hashkeycmp *keycmp;
struct {
hashitem *next;
unsigned int slot;
} iter;
} hashtbl;
hashtbl *hash_create(int N, hashfunc *, hashkeycmp *);
int hash_add(const void *key, void *data, hashtbl *);
void *hash_find(const void *key, hashtbl *);
void hash_iter_init(hashtbl *);
void *hash_iterate(hashtbl *);
int hash_count(hashtbl *);
void hash_free(hashtbl *, void freefunc(void *));
extern uint32_t hashlittle(const void *key, size_t length, uint32_t initval);
extern uint32_t hashbig(const void *key, size_t length, uint32_t initval);
extern uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval);
#ifndef BYTE_ORDER
#define hashendian hashlittle
#elif BYTE_ORDER == BIG_ENDIAN
#define hashendian hashbig
#else
#define hashendian hashlittle
#endif