8.5. hash_map — Hash map¶
Source code: src/collections/hash_map.h, src/collections/hash_map.c
Test code: tst/collections/hash_map/main.c
Test coverage: src/collections/hash_map.c
Typedefs
-
typedef int (*
hash_map_hash_t)(longptr_t key)¶
Functions
-
int
hash_map_init(struct hash_map_t *self_p, struct hash_map_bucket_t *buckets_p, size_t buckets_max, struct hash_map_entry_t *entries_p, size_t entries_max, hash_map_hash_t hash)¶ Initialize hash map with given parameters.
- Return
- zero(0) or negative error code.
- Parameters
self_p: Initialized hash map.buckets_p: Array of buckets.buckets_max: Number of entries inbuckets_p.entries_p: Array of empty entries.entries_max: Number of entries inentries_p.hash: Hash function.
-
int
hash_map_add(struct hash_map_t *self_p, longptr_t key, longptr_t value)¶ Add given key-value pair into hash map. Overwrites old value if the key is already present in map.
- Return
- zero(0) or negative error code.
- Parameters
self_p: Initialized hash map.key: Key to add.value: Value to insert for key.
-
int
hash_map_remove(struct hash_map_t *self_p, longptr_t key)¶ Remove given key from hash map.
- Return
- zero(0) or negative error code.
- Parameters
self_p: Initialized hash map.key: Key to remove.
-
int
hash_map_get(struct hash_map_t *self_p, longptr_t key, longptr_t *value_p)¶ Get value for given key.
- Return
- zero(0) if the key was found, otherwise negative error code.
- Parameters
self_p: Initialized hash map.key: Key to find.value_p: Value found for given key. Unmodified if the key was not found.
-
struct
hash_map_entry_t¶
-
struct
hash_map_bucket_t¶ Public Members
-
struct hash_map_entry_t *
list_p¶
-
struct hash_map_entry_t *
-
struct
hash_map_t¶ Public Members
-
struct hash_map_bucket_t *
buckets_p¶
-
size_t
buckets_max¶
-
struct hash_map_entry_t *
entries_p¶
-
hash_map_hash_t
hash¶
-
struct hash_map_bucket_t *