a95b50b37b08abf95bf6f034e4b5f9a8f8306399
[libradsec.git] / lib / rsp_hash.h
1 /* Copyright (c) 2008, UNINETT AS */
2 /* See COPYING for licensing information. */
3
4 #ifndef SYS_SOLARIS9
5 #include <stdint.h>
6 #endif
7
8 #if defined (__cplusplus)
9 extern "C" {
10 #endif
11
12 struct hash {
13     struct list *hashlist;
14     pthread_mutex_t mutex;
15 };
16
17 struct hash_entry {
18     void *key;
19     uint32_t keylen;
20     void *data;
21     struct list_node *next; /* used when walking through hash */
22 };
23
24 /* allocates and initialises hash structure; returns NULL if malloc fails */
25 struct hash *hash_create();
26
27 /* frees all memory associated with the hash */
28 void hash_destroy(struct hash *hash);
29
30 /* insert entry in hash; returns 1 if ok, 0 if malloc fails */
31 int hash_insert(struct hash *hash, void *key, uint32_t keylen, void *data);
32
33 /* reads entry from hash */
34 void *hash_read(struct hash *hash, void *key, uint32_t keylen);
35
36 /* extracts (read and remove) entry from hash */
37 void *hash_extract(struct hash *hash, void *key, uint32_t keylen);
38
39 /* returns first entry */
40 struct hash_entry *hash_first(struct hash *hash);
41
42 /* returns the next entry after the argument */
43 struct hash_entry *hash_next(struct hash_entry *entry);
44
45 #if defined (__cplusplus)
46 }
47 #endif
48
49 /* Local Variables: */
50 /* c-file-style: "stroustrup" */
51 /* End: */