libstd v0.1.0
Loading...
Searching...
No Matches
hashmap.h
Go to the documentation of this file.
1#ifndef HASHMAP_H_
2#define HASHMAP_H_
3
4#include <stdbool.h>
5#include <stddef.h>
6
11typedef struct HashNode {
12 void* key;
13 void* value;
14 struct HashNode*
17
21typedef struct {
23 size_t bucket_count;
24 size_t key_size;
25 size_t value_size;
26 size_t size;
27 unsigned long (*hash_fn)(
28 void*);
29 int (*cmp_fn)(void*, void*);
31} HashMap;
32
44void hashmap_init(HashMap* map, size_t bucket_count, size_t key_size,
45 size_t value_size, unsigned long (*hash_fn)(void*),
46 int (*cmp_fn)(void*, void*));
47
54void hashmap_destroy(HashMap* map);
55
65bool hashmap_insert(HashMap* map, void* key, const void* data);
66
74bool hashmap_remove(HashMap* map, void* key);
75
85bool hashmap_update(HashMap* map, void* key, const void* new_data);
86
95void* hashmap_get(HashMap* map, void* key);
96
103int hashmap_size(const HashMap* map);
104
105#endif // HASHMAP_H_
int hashmap_size(const HashMap *map)
Retrieves the total number of key-value pairs stored in the Hash Map.
Definition hashmap.c:172
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.
Definition hashmap.c:32
void hashmap_destroy(HashMap *map)
Destroys the Hash Map and frees all allocated buckets, nodes, and stored data.
Definition hashmap.c:53
void * hashmap_get(HashMap *map, void *key)
Retrieves the value associated with a given key.
Definition hashmap.c:154
bool hashmap_update(HashMap *map, void *key, const void *new_data)
Updates the value associated with an existing key in the Hash Map.
Definition hashmap.c:135
bool hashmap_remove(HashMap *map, void *key)
Removes a key-value pair from the Hash Map by key.
Definition hashmap.c:105
bool hashmap_insert(HashMap *map, void *key, const void *data)
Inserts a new key-value pair into the Hash Map.
Definition hashmap.c:77
Structure representing a generic Hash Map.
Definition hashmap.h:21
size_t value_size
Definition hashmap.h:25
HashNode ** buckets
Definition hashmap.h:22
size_t key_size
Definition hashmap.h:24
size_t size
Definition hashmap.h:26
size_t bucket_count
Definition hashmap.h:23
Node structure representing a key-value pair in a hash bucket's collision chain.
Definition hashmap.h:11
struct HashNode * next
Definition hashmap.h:14
void * key
Definition hashmap.h:12
void * value
Definition hashmap.h:13