radsecproxy-1.6.5.
[libradsec.git] / hash.h
1 /*
2  * Copyright (C) 2008 Stig Venaas <venaas@uninett.no>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  */
8
9 #ifndef SYS_SOLARIS9
10 #include <stdint.h>
11 #endif
12
13 struct hash {
14     struct list *hashlist;
15     pthread_mutex_t mutex;
16 };
17
18 struct hash_entry {
19     void *key;
20     uint32_t keylen;
21     void *data;
22     struct list_node *next; /* used when walking through hash */
23 };
24
25 /* allocates and initialises hash structure; returns NULL if malloc fails */
26 struct hash *hash_create();
27
28 /* frees all memory associated with the hash */
29 void hash_destroy(struct hash *hash);
30
31 /* insert entry in hash; returns 1 if ok, 0 if malloc fails */
32 int hash_insert(struct hash *hash, void *key, uint32_t keylen, void *data);
33
34 /* reads entry from hash */
35 void *hash_read(struct hash *hash, void *key, uint32_t keylen);
36
37 /* extracts (read and remove) entry from hash */
38 void *hash_extract(struct hash *hash, void *key, uint32_t keylen);
39
40 /* returns first entry */
41 struct hash_entry *hash_first(struct hash *hash);
42
43 /* returns the next entry after the argument */
44 struct hash_entry *hash_next(struct hash_entry *entry);
45
46 /* Local Variables: */
47 /* c-file-style: "stroustrup" */
48 /* End: */