File: hashtbl.h

package info (click to toggle)
dnstop 20120611-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 372 kB
  • ctags: 299
  • sloc: ansic: 3,065; sh: 340; makefile: 112
file content (48 lines) | stat: -rw-r--r-- 1,272 bytes parent folder | download | duplicates (2)
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: hashtbl.h,v 1.2 2007/05/11 04:51:12 wessels Exp $
 *
 * 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