|
1 | 1 | [](https://travis-ci.org/Tessil/array-hash) [](https://ci.appveyor.com/project/Tessil/array-hash/branch/master) |
2 | 2 | ## A C++ implementation of a fast and memory efficient hash map/set for strings |
3 | 3 |
|
4 | | -Cache consious hash map for string based on the "Cache-conscious collision resolution in string hash tables." (Askitis Nikolas and Justin Zobel, 2005) paper. |
| 4 | +Cache conscious hash map for strings based on the "Cache-conscious collision resolution in string hash tables." (Askitis Nikolas and Justin Zobel, 2005) paper. |
| 5 | + |
| 6 | +Due to its cache friendliness, the structure is well-adapted to store strings long enough to hinder the Small String Optimization (SSO). But even with shorter string, it provides a good balance between speed and memory usage. |
5 | 7 |
|
6 | 8 | <p align="center"> |
7 | 9 | <img src="https://tessil.github.io/images/array_hash.png" width="500px" /> |
8 | 10 | </p> |
9 | 11 |
|
10 | 12 | The library provides two classes: `tsl::array_map` and `tsl::array_set`. |
11 | 13 |
|
| 14 | +### Overview |
| 15 | +- Header-only library, just include [src/](src/) to your include path and you're ready to go. |
| 16 | +- Low memory usage with good performances. |
| 17 | +- By default the maximum allowed size for a key is set to 65 535. This can be raised through the `KeySizeT` template parameter. |
| 18 | +- By default the maximum size of the map is limited to 4 294 967 296 elements. This can be raised through the `IndexSizeT` template parameter. |
| 19 | + |
| 20 | + |
| 21 | +Thread-safety and exception guarantees are similar to the STL containers. |
| 22 | + |
| 23 | +### Benchmark |
| 24 | + |
| 25 | +You can find a benchmark of the map on the [`tsl::htrie_map`](https://github.com/Tessil/hat-trie#benchmark) page. But note that the benchmark is not complete as the average size of the key in the dataset can be stored with SSO. A benchmark with longer keys may arrive later. |
| 26 | + |
| 27 | +### Hash function |
| 28 | + |
| 29 | +To avoid dependencies, the default hash function is a simple [FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash) hash function. If you can, I recommend to use something like [CityHash](https://github.com/google/cityhash), MurmurHash, [FarmHash](https://github.com/google/farmhash), ... for better performances. |
| 30 | + |
| 31 | + |
| 32 | +```c++ |
| 33 | +#include <city.h> |
| 34 | + |
| 35 | +struct str_hash { |
| 36 | + std::size_t operator()(const char* key, std::size_t key_size) const { |
| 37 | + return CityHash64(key, key_size); |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +tsl::array_map<char, int, str_hash> map; |
| 42 | +``` |
| 43 | +
|
12 | 44 | ### Installation |
13 | 45 | To use array-hash, just add the [src/](src/) directory to your include path. It's a **header-only** library. |
14 | 46 |
|
|
27 | 59 | ``` |
28 | 60 |
|
29 | 61 |
|
| 62 | + |
30 | 63 | ### Usage |
31 | | -The API can be found [here](https://tessil.github.io/hopscotch-map/doc/html/). |
| 64 | + |
| 65 | +The API can be found [here](https://tessil.github.io/array-hash/doc_without_string_view/html). If `std::string_view` is available, the API changes slightly and can be found [here](https://tessil.github.io/array-hash/doc/html/). |
32 | 66 |
|
33 | 67 |
|
34 | 68 | ### Example |
|
0 commit comments