#include <stddef.h>
#include <assert.h>
#include <stdbool.h>
Go to the source code of this file.
|
#define | K void* |
| Defines a generic, non-resizing hashmap data type.
|
|
#define | V void* |
|
#define | HASH_OF(key) |
|
#define | HASHMAP(token) |
|
◆ HASH_OF
Value:
static K key
Definition hashmap.h:70
◆ HASHMAP
Defines a generic, non-resizing hashmap data type.
- Author
- Peter Donovan (peter.nosp@m.dono.nosp@m.van@b.nosp@m.erke.nosp@m.ley.e.nosp@m.du)
Hashmaps are defined by redefining K, V, HASH_OF, and HASHMAP, and including this file. A default hashmap type is defined here. See pointer_hashmap.h for an example of a hashmap declaration.
- K and V must be the types of keys and values of the hashmap, respectively.
- HASH_OF must be the hash of a key.
- HASHMAP must be a function-like macro that prefixes tokens with the name of the hashmap. For example, the name of the hashmap data type is given by evaluation of the macro HASHMAP(t) so that it is "t" prefixed with the name of the hashmap. The function names associated with the data type are similar.
◆ assert() [1/3]
assert |
( |
address >=hashmap-> | entries | ) |
|
◆ assert() [2/3]
◆ assert() [3/3]
◆ for()
◆ free()
Free all memory used by the given hashmap.
◆ get()
Get the value associated with the given key. Precondition: The key must be present in the map.
◆ HASHMAP() [1/2]
Return the actual address of the hashmap entry corresponding to key
, or the address of the closest empty entry if no such entry exists.
- Parameters
-
key | The key from which to begin a search. |
desired | The key that the desired returnable entry should have. |
◆ HASHMAP() [2/2]
HASHMAP |
( |
t | | ) |
= (HASHMAP(t)*)malloc(sizeof(HASHMAP(t))) |
|
new |
Construct a new hashmap object.
- Parameters
-
capacity | A number that is much larger than the maximum number of items that this hashmap will contain. Insufficient surplus capacity will cause poor performance. |
nothing | A key that is guaranteed never to be used. |
◆ if() [1/2]
◆ if() [2/2]
◆ put()
Associate a value with the given key.
◆ while()
◆ address
◆ capacity
◆ entries
◆ key
Initial value:{
#define HASH_OF(key)
Definition hashmap.h:22
#define HASHMAP(token)
Definition hashmap.h:25
return address
Definition hashmap.h:74
◆ nothing
Initial value:{
ret capacity
Definition hashmap.h:113
ret entries
Definition hashmap.h:112
◆ num_entries
◆ ret