This change is a preparation to migrate the documentation from the gh-pages branch to the docs/ folder in the master branch (once dev is merged)
15 lines
1.5 KiB
Plaintext
15 lines
1.5 KiB
Plaintext
<h1 id='multimap-h'>multimap.h</h1>
|
|
<p>The MultiMap is a Map that allows for multiple keys. This is a data structure that has a very narrow usage. A Map (either TreeMap or HashMap) can also work like a MultiMap if a certain key is mapped to another collection.</p>
|
|
|
|
<p><code>Map<K = int, V = List<int>></code> maps an integer to a list of integer.</p>
|
|
|
|
<p><code>MultiMap<K = int, V = int></code> maps many integer keys to integer values.</p>
|
|
|
|
<p>The difference is that in a MultiMap you can store keys that are the same but might be different instances of the same value. This is also relevant if your data type is more complex like a struct where its ID is the same but some other members of this data type are different.</p>
|
|
<h2 id='multimap-implementation'>MultiMap Implementation</h2>
|
|
<p>The map uses separate chaining and robin hood hashing. Its internal buffer is made of a pair of pointers to entries that represent a linked list. So accessing map->buffer[0] would give the first pair of pointers. Each entry has both a pointer to a previous entry and a next entry. This design choice was made so that every collection in this library has a two-way iterator with a very few exceptions.</p>
|
|
|
|
<p>Each entry is composed of a Key and a Value. Entries with the same key should always hash to the same linked list. Also, keys that hash to the same bucket will also be in the same linked list.</p>
|
|
|
|
<p>The order of inserting and removing the same keys will behave like a FIFO. So the first key added will be the first to be removed.</p>
|