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