Implementation of a hash table.
More...
Go to the source code of this file.
|
static int | reHash (HashMap hmap) |
| Resizes a hash table. More...
|
|
HashMap | newHash (int size, float factor, int(*hash)(void *), int(*equals)(void *, void *)) |
| Creates a hash table. More...
|
|
int | hashSetHash (HashMap hmap, int(*hash)(void *)) |
| Sets the hash function of a hash table. More...
|
|
int | hashSetEquals (HashMap hmap, int(*equals)(void *, void *)) |
| Sets the comparison function of a hash table. More...
|
|
int | hashSetFactor (HashMap hmap, int factor) |
| Sets the load factor of a hash table. More...
|
|
void | hashDelete (HashMap hmap) |
| Deletes a hash table. More...
|
|
int | hashInsert (HashMap hmap, void *key, void *value, int replace) |
| Associates a value to a key in a hash table. More...
|
|
int | hashRemove (HashMap hmap, void *key, void **value, void(*del)(void *)) |
| Removes the mapping for a key from a hash table. More...
|
|
int | hashGet (HashMap hmap, void *key, void **value) |
| Provides the mapping for a key from a hash table. More...
|
|
int | hashSize (HashMap hmap) |
| Returns the number of elements present in a hash table. More...
|
|
Iterator | hashKeys (HashMap hmap) |
| Creates an iterator from the keys of a hash table. More...
|
|
Iterator | hashValues (HashMap hmap) |
| Creates an iterator from the values of a hash table. More...
|
|
Implementation of a hash table.
- Author
- Rui Carlos Gonçalves
- Version
- 3.0.1
- Date
- 01/2014
Definition in file hashmap.c.
Deletes a hash table.
- Attention
- This function only free the memory used by the hash table. It does not free the memory used by elements the hash table contains.
- Parameters
-
hmap | the hash table to be deleted |
Definition at line 110 of file hashmap.c.
int hashGet |
( |
HashMap |
hmap, |
|
|
void * |
key, |
|
|
void ** |
value |
|
) |
| |
Provides the mapping for a key from a hash table.
If there is no mapping for the specified key, it will be put the value NULL
at value
. However, the NULL
value may also say that the mapping for the specified key was NULL
. Check the returned value in order to know whether the key was in the hash table.
- Attention
- This function puts at
value
a pointer to the mapping of the specified key. Changes to this value will affect the value in the hash table.
- Parameters
-
hmap | the hash table |
key | key whose mapping is to be provided |
value | pointer where the mapping value will be put |
- Returns
- 0 if there was a mapping for the specified key
1 otherwise
Definition at line 193 of file hashmap.c.
int hashInsert |
( |
HashMap |
hmap, |
|
|
void * |
key, |
|
|
void * |
value, |
|
|
int |
replace |
|
) |
| |
Associates a value to a key in a hash table.
If the key already had a value, the replace
argument specifies whether the new element should be added (it will be added only if replace!=0
).
- Parameters
-
hmap | the hash table |
key | the key |
value | the value to be inserted |
replace | specifies whether an old value shall be replaced |
- Returns
- 0 if the value was inserted
1 if the key already had a value
2 if an error occurred
Definition at line 129 of file hashmap.c.
Creates an iterator from the keys of a hash table.
- See Also
- Iterator
- Parameters
-
- Returns
NULL
if an error occurred
the iterator otherwise
Definition at line 218 of file hashmap.c.
int hashRemove |
( |
HashMap |
hmap, |
|
|
void * |
key, |
|
|
void ** |
value, |
|
|
void(*)(void *) |
del |
|
) |
| |
Removes the mapping for a key from a hash table.
Provides the value of the removed element if the value of elem
is not NULL
.
- Attention
- This function does not free the memory used by the removed element. To free the memory used by its key, you have to provide the argument
del
.
- Parameters
-
hmap | the hash table |
key | key whose mapping is to be removed |
value | pointer where the removed element shall be put (or NULL ) |
del | function to free the memory used by the key (or NULL ) |
- Returns
- 0 if an element was removed from the specified position
1 otherwise
Definition at line 167 of file hashmap.c.
int hashSetEquals |
( |
HashMap |
hmap, |
|
|
int(*)(void *, void *) |
equals |
|
) |
| |
Sets the comparison function of a hash table.
- Parameters
-
hmap | the hash table |
equals | the new comparison function |
- Returns
- 1 if
equals
was equal to NULL
(no change was made)
0 otherwise
Definition at line 90 of file hashmap.c.
int hashSetFactor |
( |
HashMap |
hmap, |
|
|
int |
factor |
|
) |
| |
Sets the load factor of a hash table.
The new value must be greater than or equal to 0.1.
- Parameters
-
hmap | the hash table |
factor | the new load factor |
- Returns
- 1 if
factor
was less than 0.1 (no change was made)
0 otherwise
Definition at line 100 of file hashmap.c.
int hashSetHash |
( |
HashMap |
hmap, |
|
|
int(*)(void *) |
hash |
|
) |
| |
Sets the hash function of a hash table.
- Parameters
-
hmap | the hash table |
hash | the new hash function |
- Returns
- 1 if
hash
was equal to NULL
(no change was made)
0 otherwise
Definition at line 80 of file hashmap.c.
Returns the number of elements present in a hash table.
- Parameters
-
- Returns
- the number of elements present in the hash table
Definition at line 211 of file hashmap.c.
Creates an iterator from the values of a hash table.
- See Also
- Iterator
- Parameters
-
- Returns
NULL
if an error occurred
the iterator otherwise
Definition at line 239 of file hashmap.c.
HashMap newHash |
( |
int |
size, |
|
|
float |
factor, |
|
|
int(*)(void *) |
hash, |
|
|
int(*)(void *, void *) |
equals |
|
) |
| |
Creates a hash table.
The load factor (factor
) specifies when the number of buckets should be increased (it will be increased when size > factor*length
). The load factor must be greater than or equal to 0.1 (otherwise value 0.1 will be used).
- Parameters
-
size | the initial number of buckets |
factor | the load factor |
hash | the hash function |
equals | the comparison function |
- Returns
NULL
if an error occurred
the new hash table otherwise
Definition at line 52 of file hashmap.c.
Resizes a hash table.
Doubles the number of buckets of a hash table, and updates the positions of the elements.
- Parameters
-
- Returns
- 1 if an error occured
0 otherwise
Definition at line 24 of file hashmap.c.