Files
C-Macro-Collections/docs/includes/multimap
T
Leonardo 8f64d4bca2 Changed documentation backup folder and added generated documentation to docs/
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)
2020-03-11 21:16:37 -03:00

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&lt;K = int, V = List&lt;int&gt;&gt;</code> maps an integer to a list of integer.</p>
<p><code>MultiMap&lt;K = int, V = int&gt;</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-&gt;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>