1 /*
2  * $Id: hashtbl.h,v 1.2 2007/05/11 04:51:12 wessels Exp $
3  *
4  * http://dnstop.measurement-factory.com/
5  *
6  * Copyright (c) 2006, The Measurement Factory, Inc.  All rights
7  * reserved.  See the LICENSE file for details.
8  */
9 
10 typedef struct _hashitem {
11 	const void *key;
12 	void *data;
13 	struct _hashitem *next;
14 } hashitem;
15 
16 typedef unsigned int hashfunc(const void *key);
17 typedef int hashkeycmp(const void *a, const void *b);
18 
19 typedef struct {
20 	unsigned int modulus;
21 	hashitem **items;
22 	hashfunc *hasher;
23 	hashkeycmp *keycmp;
24 	struct {
25 		hashitem *next;
26 		unsigned int slot;
27 	} iter;
28 } hashtbl;
29 
30 hashtbl *hash_create(int N, hashfunc *, hashkeycmp *);
31 int hash_add(const void *key, void *data, hashtbl *);
32 void *hash_find(const void *key, hashtbl *);
33 void hash_iter_init(hashtbl *);
34 void *hash_iterate(hashtbl *);
35 int hash_count(hashtbl *);
36 void hash_free(hashtbl *, void freefunc(void *));
37 
38 extern uint32_t hashlittle(const void *key, size_t length, uint32_t initval);
39 extern uint32_t hashbig(const void *key, size_t length, uint32_t initval);
40 extern uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval);
41 
42 #ifndef BYTE_ORDER
43 #define hashendian hashlittle
44 #elif BYTE_ORDER == BIG_ENDIAN
45 #define hashendian hashbig
46 #else
47 #define hashendian hashlittle
48 #endif
49