A C implementation of Hash map data structure. So yes, reinventing the wheel. Makes use of FNV-1 hashing algorithm and supports dynamic resizing when crossing a form factor of 0.7.
- Copy the cmaps.c and cmaps.h files in your project and include "cmaps.h" to use the implementation.
struct hash_map: The struct that holds the hash mapstruct hash_map new_hashmap(): Creates a new hash map instance of default size (32) and returns it.struct hash_map new_hashmap_wsize(uint size): Creates a new hash map with specified size. Useful in cases where the number of elements need to be pushed is known prior. Doing so can skip the costly resizing process.int map_put(struct hash_map *map, const char* key, const char* value): Puts the given key value pair in the map. Overwrites old value if a key is already present. Returns 1 on success and 0 on failure.char* map_get(struct hash_map *map, const char* key): Retrieve value corresponding to the given key. Returns the pointer to the string if key is found or returns NULL on failure.void map_delete(struct hash_map *map, const char* key): Delete the key and value present in the map. Nothing is returned. If key is not found, not is happening.void resize(struct hash_map *map, uint new_cap): Resize the hash map to new capacity.void deinit_hashmap(struct hash_map *map): Deinitialize the map structure and free all memory