Skip to content

Commit 1a89fae

Browse files
committed
Improve documentation
1 parent 4cf1c72 commit 1a89fae

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

README.md

+45-18
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,42 @@ interface, but with much higher performance for many workloads.
88

99
## Implementation
1010

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].
1616

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:
2018

21-
## Benchmark
19+
1. Wikipedia. ["Open addressing"][1]
20+
2. Wikipedia. ["Linear probing"][2]
21+
3. Wikipedia. ["Lazy deletion"][3]
2222

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"
2726

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).
3347
3448
## Example
3549
@@ -48,6 +62,19 @@ for (const auto &e : hm) {
4862
hm.erase(1);
4963
```
5064

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+
5178
## About
5279

5380
This project was created by [Erik Rigtorp](http://rigtorp.se)

0 commit comments

Comments
 (0)