| FEAT 3
    Finite Element Analysis Toolbox | 
High-performance associative container. More...
#include <slotmap.hpp>
| Classes | |
| class | ConstSlotMapIterator | 
| Const iterator type for the SlotMap.  More... | |
| struct | Slot | 
| Internal data structure for slots.  More... | |
| class | SlotMapIterator | 
| Iterator type for the SlotMap.  More... | |
| Public Types | |
| using | KeyType = Key | 
| using | ValueType = V | 
| Public Member Functions | |
| SlotMap () | |
| Construct SlotMapwith initial capacity zero.  More... | |
| SlotMapIterator | begin () | 
| ConstSlotMapIterator | begin () const | 
| std::size_t | bytes () const | 
| Index | capacity () const | 
| Retrieve current capacity of the SlotMap.  More... | |
| bool | contains_key (const Key &key) const | 
| Check if given key is still valid.  More... | |
| V * | data () | 
| const V * | data () const | 
| SlotMapIterator | end () | 
| ConstSlotMapIterator | end () const | 
| void | erase (const Key &key) | 
| Remove a key from the SlotMap.  More... | |
| Key | insert (const V &value) | 
| Insert a value into the SlotMap.  More... | |
| Key | insert (V &&value) | 
| Insert valueinto theSlotMap.  More... | |
| V & | operator[] (const Key &key) | 
| Access Operator.  More... | |
| const V & | operator[] (const Key &key) const | 
| Access Operator.  More... | |
| Key | replace (Key &key, V &&value) | 
| Replace the value stored at keywithvalue.  More... | |
| Key | replace (Key &key, V &value) | 
| Replace the value stored at keywithvalue.  More... | |
| void | reserve (Index capacity) | 
| Reserve at least capacityspace in theSlotMap.  More... | |
| Index | size () const | 
| Retrieve current size of the SlotMap.  More... | |
| Private Member Functions | |
| Slot & | try_get_slot (const Key &key) | 
| Helper method to retrieve a slot.  More... | |
| const Slot & | try_get_slot (const Key &key) const | 
| Private Attributes | |
| std::vector< V > | _data | 
| std::vector< std::uint32_t > | _erase | 
| std::vector< Slot > | _slots | 
| struct { | |
| std::uint32_t head | |
| std::uint32_t tail | |
| } | freelist | 
High-performance associative container.
| V | Type of value to be stored. | 
| Key | Type of keys returned by this SlotMap. SlotMapKey by default. | 
A SlotMap is a high-performance associative container. It:
To do so it hands out its own keys, instead of letting the user provide a key like a traditional hashmap would do. Keys consist of an index into the SlotMap used to access elements, and a generation used to detect if the slot has been reused since the key has been issued.
The implementation consists of three dynamic arrays (std::vectors) called slots, data, erase, as well as head and tail indices for a list of free slots.
The data array is where the inserted elements are stored.
The slots array provides the indirection required to keep keys stable while guaranteeing to store the elements densely. Each entry in the slots array consists of an index and a generation. The generation indicates how often this slot has been reused. This is what allows detecting if an old key is used to access new data. The index either points into the data array (if the slot is currently occupied) or to the next free slot (if the slot is currently not occupied). The keys given out by the SlotMap point towards slots. This way elements in the data array can be shifted around and only indices in the slots array need to be fixed, while the keys stay valid.
The erase array contains the index of the slot pointing towards itself (and the associated element in the data array). In short slots[erase[i]].index == i. It is used to quickly find affected slots during deletion of a key, allowing O(1) deletions.
The freelist tracks the start and end of the linked list of unoccupied slots established. As an invariant the SlotMap always keeps at least one Slot unoccupied to guarantee that freelist.head and freelist.tail point towards a valid slot. Note that keeping track of the tail is not strictly required. A stack of unoccupied slots could be used instead, but using a list increments the slots generations more evenly.
Inserting a new value works as follows
Deleting a value works as follows
See https://www.youtube.com/watch?v=SHaAR7XPtNU for more details.
The SlotMap returns keys of type SlotMapKey per default. For more type safety when using multiple SlotMaps simultaneously a custom key type can be provided as a second template argument.
A valid key type requires a constructor accepting the index and the generation in that order, a public member index and a public member generation.
Definition at line 148 of file slotmap.hpp.
| using FEAT::Util::SlotMap< V, Key >::KeyType = Key | 
Definition at line 152 of file slotmap.hpp.
| using FEAT::Util::SlotMap< V, Key >::ValueType = V | 
Definition at line 151 of file slotmap.hpp.
| 
 | inline | 
Construct SlotMap with initial capacity zero. 
Definition at line 157 of file slotmap.hpp.
| 
 | inline | 
Definition at line 498 of file slotmap.hpp.
| 
 | inline | 
Definition at line 508 of file slotmap.hpp.
| 
 | inline | 
Definition at line 399 of file slotmap.hpp.
| 
 | inline | 
Retrieve current capacity of the SlotMap. 
SlotMap Definition at line 374 of file slotmap.hpp.
Referenced by FEAT::Util::SlotMap< V, Key >::reserve().
| 
 | inline | 
Check if given key is still valid.
| [in] | key | The key to check. | 
true if the key is valid, false otherwise.A key is valid if it points to an existing slot and matches that slots generation.
Definition at line 322 of file slotmap.hpp.
Referenced by FEAT::Util::SlotMap< V, Key >::erase().
| 
 | inline | 
Definition at line 389 of file slotmap.hpp.
| 
 | inline | 
Definition at line 394 of file slotmap.hpp.
| 
 | inline | 
Definition at line 503 of file slotmap.hpp.
| 
 | inline | 
Definition at line 513 of file slotmap.hpp.
| 
 | inline | 
Remove a key from the SlotMap. 
Will invalidate all further uses of the key.
| [in] | key | The key to remove | 
Definition at line 249 of file slotmap.hpp.
References FEAT::Util::SlotMap< V, Key >::contains_key(), and FEAT::Util::SlotMap< V, Key >::try_get_slot().
Referenced by FEAT::Geometry::Intern::MeshLayer< TemplateSet_, MeshShape_, VertexType_, 0 >::erase(), and FEAT::Util::SlotMap< V, Key >::replace().
| 
 | inline | 
Insert a value into the SlotMap. 
| [in] | value | The value to be inserted. | 
Definition at line 211 of file slotmap.hpp.
References FEAT::value.
| 
 | inline | 
Insert value into the SlotMap. 
| [in] | value | The value to be inserted. | 
Definition at line 171 of file slotmap.hpp.
References FEAT::value.
Referenced by FEAT::Geometry::Intern::MeshLayer< TemplateSet_, MeshShape_, VertexType_, 0 >::insert_vertex(), and FEAT::Util::SlotMap< V, Key >::replace().
| 
 | inline | 
Access Operator.
| [in] | key | The key to retrieve | 
Aborts if the given key is not valid.
Definition at line 350 of file slotmap.hpp.
References ASSERTM, and FEAT::Util::SlotMap< V, Key >::try_get_slot().
| 
 | inline | 
Access Operator.
| [in] | key | The key to retrieve | 
Aborts if the given key is not valid.
Definition at line 335 of file slotmap.hpp.
References ASSERTM, and FEAT::Util::SlotMap< V, Key >::try_get_slot().
| 
 | inline | 
Replace the value stored at key with value. 
| [in] | key | The key to replace | 
| [in] | value | The new value to store | 
Shortcut to erasing a key and then inserting a new value. The new value is not guaranteed to be stored at the same memory location as the previous one.
Definition at line 291 of file slotmap.hpp.
References FEAT::Util::SlotMap< V, Key >::erase(), FEAT::Util::SlotMap< V, Key >::insert(), and FEAT::value.
| 
 | inline | 
Replace the value stored at key with value. 
| [in] | key | The key to replace | 
| [in] | value | The new value to store | 
Shortcut to erasing a key and then inserting a new value. The new value is not guaranteed to be stored at the same memory location as the previous one.
Definition at line 308 of file slotmap.hpp.
References FEAT::Util::SlotMap< V, Key >::erase(), FEAT::Util::SlotMap< V, Key >::insert(), and FEAT::value.
| 
 | inline | 
Reserve at least capacity space in the SlotMap. 
| [in] | capacity | Minimum capacity | 
Definition at line 362 of file slotmap.hpp.
References FEAT::Util::SlotMap< V, Key >::capacity().
| 
 | inline | 
Retrieve current size of the SlotMap. 
SlotMap Definition at line 384 of file slotmap.hpp.
Referenced by FEAT::Geometry::Intern::MeshLayer< TemplateSet_, MeshShape_, VertexType_, 0 >::num_vertices().
| 
 | inlineprivate | 
Helper method to retrieve a slot.
| [in] | key | Key | 
Aborts if given key is not valid, returns reference to slot otherwise.
Definition at line 543 of file slotmap.hpp.
References ASSERTM.
Referenced by FEAT::Util::SlotMap< V, Key >::erase(), and FEAT::Util::SlotMap< V, Key >::operator[]().
| 
 | inlineprivate | 
Definition at line 551 of file slotmap.hpp.
| 
 | private | 
Definition at line 566 of file slotmap.hpp.
| 
 | private | 
Definition at line 567 of file slotmap.hpp.
| 
 | private | 
Definition at line 565 of file slotmap.hpp.
| std::uint32_t FEAT::Util::SlotMap< V, Key >::head | 
Definition at line 561 of file slotmap.hpp.
| std::uint32_t FEAT::Util::SlotMap< V, Key >::tail | 
Definition at line 562 of file slotmap.hpp.