summaryrefslogtreecommitdiff
path: root/src/include/util_Hash.h
blob: 4d9e5db96e28361220bd2fb93235c2149cbacbd1 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 /*@@
   @header    Hash.h
   @date      Wed Oct 27 23:28:53 1999
   @author    Tom Goodale
   @desc 
   Header file for hash stuff.
   @enddesc 
   @version $Header$
 @@*/

#ifndef _UTIL_HASH_H_
#define _UTIL_HASH_H_ 1

#ifdef __cplusplus
extern "C" 
{
#endif

typedef struct T_HASH_ENTRY
{
  struct T_HASH_ENTRY *last;
  struct T_HASH_ENTRY *next;
 
  unsigned int hash;

  unsigned int klen;
  char *key;

  void *data;
} iHashEntry;

typedef struct T_HASH
{
  unsigned int size;
  unsigned int fill;
  unsigned int keys;

  iHashEntry **array;
} uHash;

uHash *Util_HashCreate(unsigned int initial_size);

int Util_HashDestroy(uHash *hash, void (*delete_entry)(void *));

int Util_HashStore(uHash *hash, 
                   unsigned int klen, 
                   const char *key, 
                   unsigned int hashval,
                   void *data);

int Util_HashAdd(uHash *hash, 
                 unsigned int klen, 
                 const char *key, 
                 unsigned int hashval, 
                 void *data);

int Util_HashDelete(uHash *hash, 
                    unsigned int klen, 
                    const char *key, 
                    unsigned int hashval);

void *Util_HashData(uHash *hash, 
                    unsigned int klen, 
                    const char *key, 
                    unsigned int hashval);

unsigned int Util_HashHash(unsigned int klen, 
                           const char *key);

#ifdef __cplusplus
}
#endif

#endif /* _UTIL_HASH_H_ */