#include <stdbool.h>
#include <stddef.h>
Go to the source code of this file.
|
| struct | HashNode |
| | Node structure representing a key-value pair in a hash bucket's collision chain. More...
|
| |
| struct | HashMap |
| | Structure representing a generic Hash Map. More...
|
| |
|
| typedef struct HashNode | HashNode |
| | Node structure representing a key-value pair in a hash bucket's collision chain.
|
| |
|
| void | hashmap_init (HashMap *map, size_t bucket_count, size_t key_size, size_t value_size, unsigned long(*hash_fn)(void *), int(*cmp_fn)(void *, void *)) |
| | Initializes a Hash Map structure.
|
| |
| void | hashmap_destroy (HashMap *map) |
| | Destroys the Hash Map and frees all allocated buckets, nodes, and stored data.
|
| |
| bool | hashmap_insert (HashMap *map, void *key, const void *data) |
| | Inserts a new key-value pair into the Hash Map.
|
| |
| bool | hashmap_remove (HashMap *map, void *key) |
| | Removes a key-value pair from the Hash Map by key.
|
| |
| bool | hashmap_update (HashMap *map, void *key, const void *new_data) |
| | Updates the value associated with an existing key in the Hash Map.
|
| |
| void * | hashmap_get (HashMap *map, void *key) |
| | Retrieves the value associated with a given key.
|
| |
| int | hashmap_size (const HashMap *map) |
| | Retrieves the total number of key-value pairs stored in the Hash Map.
|
| |
◆ HashNode
Node structure representing a key-value pair in a hash bucket's collision chain.
◆ hashmap_destroy()
| void hashmap_destroy |
( |
HashMap * |
map | ) |
|
Destroys the Hash Map and frees all allocated buckets, nodes, and stored data.
- Parameters
-
| map | Pointer to the HashMap to destroy. |
◆ hashmap_get()
| void * hashmap_get |
( |
HashMap * |
map, |
|
|
void * |
key |
|
) |
| |
Retrieves the value associated with a given key.
- Parameters
-
| map | Pointer to the HashMap. |
| key | Pointer to the key to search for. |
- Returns
- Pointer to the stored value data if found, or NULL if the key does not exist.
◆ hashmap_init()
| void hashmap_init |
( |
HashMap * |
map, |
|
|
size_t |
bucket_count, |
|
|
size_t |
key_size, |
|
|
size_t |
value_size, |
|
|
unsigned long(*)(void *) |
hash_fn, |
|
|
int(*)(void *, void *) |
cmp_fn |
|
) |
| |
Initializes a Hash Map structure.
- Parameters
-
| map | Pointer to the HashMap structure to initialize. |
| bucket_count | Initial number of buckets to allocate. |
| key_size | Size of the key data in bytes. |
| value_size | Size of the value data in bytes. |
| hash_fn | Pointer to the hash function for keys. |
| cmp_fn | Pointer to the key comparison function (should return 0 when keys match). |
◆ hashmap_insert()
| bool hashmap_insert |
( |
HashMap * |
map, |
|
|
void * |
key, |
|
|
const void * |
data |
|
) |
| |
Inserts a new key-value pair into the Hash Map.
- Parameters
-
| map | Pointer to the HashMap. |
| key | Pointer to the key to insert. |
| data | Pointer to the value associated with the key. |
- Returns
true if the insertion was successful, or false on memory allocation failure or duplicate entry depending on implementation behavior.
◆ hashmap_remove()
| bool hashmap_remove |
( |
HashMap * |
map, |
|
|
void * |
key |
|
) |
| |
Removes a key-value pair from the Hash Map by key.
- Parameters
-
| map | Pointer to the HashMap. |
| key | Pointer to the key to remove. |
- Returns
true if the key was found and removed, false otherwise.
◆ hashmap_size()
| int hashmap_size |
( |
const HashMap * |
map | ) |
|
Retrieves the total number of key-value pairs stored in the Hash Map.
- Parameters
-
- Returns
- Total number of items stored.
◆ hashmap_update()
| bool hashmap_update |
( |
HashMap * |
map, |
|
|
void * |
key, |
|
|
const void * |
new_data |
|
) |
| |
Updates the value associated with an existing key in the Hash Map.
- Parameters
-
| map | Pointer to the HashMap. |
| key | Pointer to the key whose value should be updated. |
| new_data | Pointer to the new value data. |
- Returns
true if the key was found and updated, false if the key does not exist.