|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
#include <stdbool.h>#include <stdlib.h>Go to the source code of this file.
Data Structures | |
| struct | kv_pair_t |
| Single key/value slot used internally by the open-addressing hash map. More... | |
| struct | hash_map_t |
| Minimal open-addressing hash map for 64-bit key/value pairs used in deduplication lookup. More... | |
Functions | |
| hash_map_t * | create_map (size_t size) |
| Creates a new hash map with the specified initial size. | |
| void | free_map (hash_map_t *map) |
| Frees all memory associated with a hash map. | |
| bool | insert_map (hash_map_t *map, uint64_t key, uint64_t value) |
| Inserts a key-value pair into the hash map. | |
| bool | lookup_map (const hash_map_t *map, uint64_t key, uint64_t *out_value) |
| Looks up a value by key in the hash map. | |
| hash_map_t * create_map | ( | size_t | size | ) |
Creates a new hash map with the specified initial size.
Allocates and initializes a new hash map structure with the given size. The hash map uses open addressing with linear probing for collision resolution. The table is zero-initialized, making empty slots identifiable by having a key value of 0.
| size | Initial size of the hash table. Must be greater than 0. |
| hash_map_t* | Successfully created hash map with:
|
| NULL | Memory allocation failed |
Definition at line 49 of file hash_map.c.
References hash_map_t::count, hash_map_t::size, and hash_map_t::table.
Referenced by aaruf_create(), and aaruf_open().
| void free_map | ( | hash_map_t * | map | ) |
Frees all memory associated with a hash map.
Deallocates the hash table and the hash map structure itself. After calling this function, the hash map pointer becomes invalid and should not be used.
| map | Pointer to the hash map to free. Can be NULL (no operation performed). |
Definition at line 73 of file hash_map.c.
References hash_map_t::table.
Referenced by aaruf_close(), and cleanup_failed_create().
| bool insert_map | ( | hash_map_t * | map, |
| uint64_t | key, | ||
| uint64_t | value ) |
Inserts a key-value pair into the hash map.
Adds a new key-value pair to the hash map using open addressing with linear probing for collision resolution. If the key already exists, the insertion fails and returns false. The function automatically resizes the hash table when the load factor exceeds the threshold (0.75) to maintain optimal performance.
| map | Pointer to the hash map. Must not be NULL. |
| key | The key to insert. Must not be 0 as this value is reserved for empty slots. |
| value | The value to associate with the key. |
| true | Successfully inserted the key-value pair. The map count is incremented. |
| false | Key already exists in the map. No changes made to the map. |
Definition at line 153 of file hash_map.c.
References hash_map_t::count, kv_pair_t::key, LOAD_FACTOR, resize_map(), hash_map_t::size, hash_map_t::table, and kv_pair_t::value.
Referenced by aaruf_write_sector().
| bool lookup_map | ( | const hash_map_t * | map, |
| uint64_t | key, | ||
| uint64_t * | out_value ) |
Looks up a value by key in the hash map.
Searches for the specified key in the hash map and retrieves its associated value. Uses linear probing to handle collisions during the search. The function does not modify the hash map in any way.
| map | Pointer to the hash map to search. Must not be NULL. |
| key | The key to search for. Must not be 0. |
| out_value | Pointer to store the found value. Must not be NULL. Only modified if the key is found. |
| true | Key found. The associated value is written to *out_value. |
| false | Key not found. *out_value is not modified. |
Definition at line 196 of file hash_map.c.
References kv_pair_t::key, hash_map_t::size, hash_map_t::table, and kv_pair_t::value.
Referenced by aaruf_write_sector().