updated Doxyfile
[strongswan.git] / src / libstrongswan / utils / hashtable.h
1 /*
2 * Copyright (C) 2008 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 /**
19 * @defgroup hashtable hashtable
20 * @{ @ingroup utils
21 */
22
23 #ifndef HASHTABLE_H_
24 #define HASHTABLE_H_
25
26 #include <utils/enumerator.h>
27
28 typedef struct hashtable_t hashtable_t;
29
30 /**
31 * Prototype for a function that computes the hash code from the given key.
32 *
33 * @param key key to hash
34 * @return hash code
35 */
36 typedef u_int (*hashtable_hash_t)(void *key);
37
38 /**
39 * Prototype for a function that compares the two keys for equality.
40 *
41 * @param key first key (the one we are looking for)
42 * @param other_key second key
43 * @return TRUE if the keys are equal
44 */
45 typedef bool (*hashtable_equals_t)(void *key, void *other_key);
46
47 /**
48 * Class implementing a hash table.
49 *
50 * General purpose hash table. This hash table is not synchronized.
51 */
52 struct hashtable_t {
53
54 /**
55 * Create an enumerator over the hash table key/value pairs.
56 *
57 * @return enumerator over (void *key, void *value)
58 */
59 enumerator_t *(*create_enumerator) (hashtable_t *this);
60
61 /**
62 * Adds the given value with the given key to the hash table, if there
63 * exists no entry with that key. NULL is returned in this case.
64 * Otherwise the existing value is replaced and the function returns the
65 * old value.
66 *
67 * @param key the key to store
68 * @param value the value to store
69 * @return NULL if no item was replaced, the old value otherwise
70 */
71 void *(*put) (hashtable_t *this, void *key, void *value);
72
73 /**
74 * Returns the value with the given key, if the hash table contains such an
75 * entry, otherwise NULL is returned.
76 *
77 * @param key the key of the requested value
78 * @return the value, NULL if not found
79 */
80 void *(*get) (hashtable_t *this, void *key);
81
82 /**
83 * Removes the value with the given key from the hash table and returns the
84 * removed value (or NULL if no such value existed).
85 *
86 * @param key the key of the value to remove
87 * @return the removed value, NULL if not found
88 */
89 void *(*remove) (hashtable_t *this, void *key);
90
91 /**
92 * Gets the number of items in the hash table.
93 *
94 * @return number of items
95 */
96 u_int (*get_count) (hashtable_t *this);
97
98 /**
99 * Destroys a hash table object.
100 */
101 void (*destroy) (hashtable_t *this);
102
103 };
104
105 /**
106 * Creates an empty hash table object.
107 *
108 * @param hash hash function
109 * @param equals equals function
110 * @param capacity initial capacity
111 * @return hashtable_t object.
112 */
113 hashtable_t *hashtable_create(hashtable_hash_t hash, hashtable_equals_t equals,
114 u_int capacity);
115
116 #endif /** HASHTABLE_H_ @}*/