This is a simple generic hashmap which supports user-defined types for both the keys and values (at the moment there is no support yet for custom deallocators if your custom types contain dynamically-allocated memory but this is planned soon).
The performance of this map is extremely quick, inserting and searching 100,000 keys almost instantaneously (on i7 processor, 32GB RAM) in debug mode. However, this map is very heap intensive with lots of allocations. The memory usage could probably be optimized more, but won't bother with that until it becomes a serious problem; didn't want to prematurely optimize.
There are built-in hash functions for the basic types (string, int, float, double) but you will have to provide your own hash function for user-defined types. See hash functions for examples.
When inserting values with map_put, an enum map_code_e is returned with either SUCCESS or DUPLICATE_KEY. In the case of duplicate keys, they are silently ignored so you must check for that status code if you want any special behaviour to occur.
See this for a complete example of how the map is used.
After cloning this repo, in the root directory you can:
mkdir build && cd buildcmake ..for Release mode (default) orcmake -DCMAKE_BUILD_TYPE=Debugfor debug modemake
This will generate a static library libhashmap.a.
You can add this project as a git submodule into your project. Just add the following in your CMakeLists wherever appropriate:
add_subdirectory(/path/to/hashmap)target_include_directories([your target] PUBLIC ${hashmap_SOURCE_DIR}/include)target_link_libraries([your target] hashmap)
Then it should become a part of your build and you can use #include "hashmap.h".