-
Notifications
You must be signed in to change notification settings - Fork 0
/
abhash.h
48 lines (40 loc) · 1.37 KB
/
abhash.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
/***************************************************************************
* Copyright (c) 2009-2009, Aaron Brady
* All Rights Reserved
*
* Module Description:
*
*
***************************************************************************/
#ifndef ABHASHTABLE_H
#define ABHASHTABLE_H
#include "abutil.h"
typedef struct HashNode
{
char *key;
void *p;
U32 hash;
} HashNode;
typedef struct HashTable
{
HashNode *elts;
int n_elts;
int n_used;
void *ctxt;
U32 (*hashfp)(char *key, void *ctxt);
int (*cmpfp)(const void*, const void*);
} HashTable;
//void inthash_init(HashTable *ht, void *ctxt);
void ptrhash_init(HashTable *ht, void *ctxt);
typedef void (HashCleanupFp)(HashNode *n, void *ctxt);
void hash_free_cleanupcb(HashNode *n, void *ctxt); // free all keys and p's
HashNode *hash_findnode(HashTable *ht, char *key);
HashNode *hash_findnode_prehash(HashTable *ht, char *key, U32 hash);
void *hash_find(HashTable *ht, char *key);
BOOL hash_insert(HashTable *ht, char *key, void *p);
void hash_cleanup(HashTable *ht, HashCleanupFp *cb);
void hash_resize(HashTable *ht, int n_new);
int hash_test();
ABINLINE void *ptrhash_find(HashTable *ht, void *key) { return hash_find(ht,(char*)key); }
ABINLINE BOOL ptrhash_insert(HashTable *ht, void *key, void *p) { return hash_insert(ht,(char*)key,p); }
#endif //ABHASHTABLE_H