@@ -8,28 +8,42 @@ interface, but with much higher performance for many workloads.
8
8
9
9
## Implementation
10
10
11
- This hash table uses open addressing with linear probing and backshift
12
- deletion. Open addressing and linear probing minimizes memory
13
- allocations and achives high cache effiency. Backshift deletion keeps
14
- performance high for delete heavy workloads by not clobbering the hash
15
- table with tombestones.
11
+ This hash table uses [ open addressing] [ 1 ] with [ linear probing] [ 2 ] and
12
+ backshift deletion. Open addressing and linear probing minimizes
13
+ memory allocations and achives high cache effiency. Backshift deletion
14
+ keeps performance high for delete heavy workloads by not clobbering
15
+ the hash table with [ tombestones] [ 3 ] .
16
16
17
- Please note that this hash table currently only works with POD-types,
18
- destructors are not called on * erase()* . It's not too hard to make it
19
- work with complex types.
17
+ References:
20
18
21
- ## Benchmark
19
+ 1 . Wikipedia. [ "Open addressing"] [ 1 ]
20
+ 2 . Wikipedia. [ "Linear probing"] [ 2 ]
21
+ 3 . Wikipedia. [ "Lazy deletion"] [ 3 ]
22
22
23
- The benchmark first inserts 1M random entries in the table and then
24
- removes the last inserted item and inserts a new random entry 1
25
- billion times. This is benchmark is designed to simulate a delete
26
- heavy workload.
23
+ [ 1 ] : https://en.wikipedia.org/wiki/Open_addressing " Open addressing "
24
+ [ 2 ] : https://en.wikipedia.org/wiki/Linear_probing " Linear probing "
25
+ [ 3 ] : https://en.wikipedia.org/wiki/Lazy_deletion " Lazy deletion "
27
26
28
- | Implementation | ns/iter |
29
- | ---------------------- | -------:|
30
- | HashMap | 77 |
31
- | google::dense_hash_map | 122 |
32
- | std::unordered_map | 220 |
27
+ ## Usage
28
+
29
+ ` HashMap ` is mostly compatible with the C++11 container interface. The
30
+ main differences are:
31
+
32
+ * A key value to represent the empty key is required.
33
+ * ` T ` needs to be default constructible.
34
+ * Iterators are invalidated on all modifying operations.
35
+ * It's invalid to perform any operations with the empty key.
36
+ * Destructors are not called on ` erase ` .
37
+
38
+ ``` cpp
39
+ HashMap (size_type bucket_count, key_type empty_key);
40
+ ```
41
+
42
+ Construct a `HashMap` with `bucket_count` buckets and `empty_key` as
43
+ the empty key.
44
+
45
+ The rest of the member functions are implemented as for
46
+ [`std::unordered_map`](http://en.cppreference.com/w/cpp/container/unordered_map).
33
47
34
48
## Example
35
49
@@ -48,6 +62,19 @@ for (const auto &e : hm) {
48
62
hm.erase(1);
49
63
```
50
64
65
+ ## Benchmark
66
+
67
+ The benchmark first inserts 1M random entries in the table and then
68
+ removes the last inserted item and inserts a new random entry 1
69
+ billion times. This is benchmark is designed to simulate a delete
70
+ heavy workload.
71
+
72
+ | Implementation | ns/iter |
73
+ | ---------------------- | -------:|
74
+ | HashMap | 77 |
75
+ | google::dense_hash_map | 122 |
76
+ | std::unordered_map | 220 |
77
+
51
78
## About
52
79
53
80
This project was created by [ Erik Rigtorp] ( http://rigtorp.se )
0 commit comments