diff --git a/README.md b/README.md index d8def3a..17d5bb7 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ ### A quick look at the current state of the art -If you haven't been living under a rock, you know that Google open sourced late last year their Abseil library, which includes a very efficient flat hash table implementation. The flat hash table stores the values directly in a memory array, which avoids memory indirections. Using parallel SSE2 instructions, the flat hash table is able to look up items by checking 16 slots in parallel, which allows the implementation to remain fast even when the table is filled to 87.5% capacity. +If you haven't been living under a rock, you know that Google open sourced late last year their Abseil library, which includes a very efficient flat hash table implementation. The absl::flat_hash_map stores the values directly in a memory array, which avoids memory indirections. Using parallel SSE2 instructions, the flat hash table is able to look up items by checking 16 slots in parallel, which allows the implementation to remain fast even when the table is filled to 87.5% capacity. + +![closed_hashing](https://github.com/greg7mdp/parallel-hashmap/blob/master/img/closed_hashing.png?raw=true) The graphs below show a comparison of time and memory usage necessary to insert up to 100 million values (each value is composed of two 8-byte integers), between the default hash map of Visual Studio 2017 (std::unordered_map), and Abseil's flat_hast_map: diff --git a/diagrams/closed_hashing b/diagrams/closed_hashing new file mode 100644 index 0000000..5e901b5 --- /dev/null +++ b/diagrams/closed_hashing @@ -0,0 +1,28 @@ + + + + +----------------+ + |"(keyi, valuei)"| "(key, value) pairs are stored directly" + +----+-----------+ "into the array (no pointers)" + | +--------+---------------------+ + | | | | + | | | | + | | | | + | | | | + | | | | + | +--------+---------------------+ + +---------------> | keyi | valuei | + hasher(keyi) +--------+---------------------+ + | | | + | | | + | | | + +--------+---------------------+ + | | | + +--------+---------------------+ + | | | + | | | + | | | + +--------+---------------------+ + + absl::flat_hash_map + diff --git a/diagrams/closed_hashing.svg b/diagrams/closed_hashing.svg new file mode 100644 index 0000000..7c2bd24 --- /dev/null +++ b/diagrams/closed_hashing.svg @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +(keyi, valuei) + + + + +hasher(keyi) + + + + +absl::flat_hash_map + + + + +(key, value) pairs are stored directly + + + + +into the array (no pointers) + + + + +keyi + + + + +valuei + + + diff --git a/diagrams/index_computation b/diagrams/index_computation index 6a980eb..e79cfc1 100644 --- a/diagrams/index_computation +++ b/diagrams/index_computation @@ -1,26 +1,29 @@ - +---------------+ - | "(Key, Value)"| - +------+--------+ - | - | hasher "Parallel Hash Map" - v "(with 8 submaps)" - +--------+-------------+ +----------------+ - | h=0x7d84ea13707f4657 | | submap0 | - +---------+------------+ +----------------+ - | | submap1 | - | "(h ^ (h >> 3)) & 0x7" +----------------+ - v | submap2 | - +----+----+ +----------------+ - |"idx = 5"| | submap3 | - +----+----+ +----------------+ - | | submap4 | - | +----------------+ - +------------------------------->| submap5 | - +----------------+ - | submap6 | - +----------------+ - | submap7 | - +----------------+ - - "parallel_hash_map with 8 submaps, each submap is an absl::flat_hash_map" - + + + + +----------------+ + |"(keyi, valuei)"| + +------+---------+ + | + | hasher(keyi) "Parallel Hash Map" + v "(with 8 submaps)" + +--------+-------------+ +----------------+ + | h=0x7d84ea13707f4657 | | submap0 | + +---------+------------+ +----------------+ + | | submap1 | + | "(h ^ (h >> 3)) & 0x7" +----------------+ + v | submap2 | + +----+----+ +----------------+ + |"idx = 5"| | submap3 | + +----+----+ +----------------+ + | | submap4 | + | +----------------+ + +------------------------------->| submap5 | + +----------------+ + | submap6 | + +----------------+ + | submap7 | + +----------------+ + + "parallel_hash_map with 8 submaps, each submap is an absl::flat_hash_map" + diff --git a/img/closed_hashing.png b/img/closed_hashing.png new file mode 100644 index 0000000..0662041 Binary files /dev/null and b/img/closed_hashing.png differ