2 * Copyright (C) 2008 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
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>.
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
19 * @defgroup hashtable hashtable
26 #include <utils/enumerator.h>
28 typedef struct hashtable_t hashtable_t
;
31 * Prototype for a function that computes the hash code from the given key.
33 * @param key key to hash
36 typedef u_int (*hashtable_hash_t
)(void *key
);
39 * Prototype for a function that compares the two keys for equality.
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
45 typedef bool (*hashtable_equals_t
)(void *key
, void *other_key
);
48 * Class implementing a hash table.
50 * General purpose hash table. This hash table is not synchronized.
55 * Create an enumerator over the hash table.
57 * @return enumerator over hash table entries
59 enumerator_t
*(*create_enumerator
) (hashtable_t
*this);
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
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
71 void *(*put
) (hashtable_t
*this, void *key
, void *value
);
74 * Returns the value with the given key, if the hash table contains such an
75 * entry, otherwise NULL is returned.
77 * @param key the key of the requested value
78 * @return the value, NULL if not found
80 void *(*get
) (hashtable_t
*this, void *key
);
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).
86 * @param key the key of the value to remove
87 * @return the removed value, NULL if not found
89 void *(*remove
) (hashtable_t
*this, void *key
);
92 * Gets the number of items in the hash table.
94 * @return number of items
96 u_int (*get_count
) (hashtable_t
*this);
99 * Destroys a hash table object.
101 void (*destroy
) (hashtable_t
*this);
106 * Creates an empty hash table object.
108 * @param hash hash function
109 * @param equals equals function
110 * @param capacity initial capacity
111 * @return hashtable_t object.
113 hashtable_t
*hashtable_create(hashtable_hash_t hash
, hashtable_equals_t equals
,
116 #endif /* HASHTABLE_H_ @} */