31    SlotMapKey(std::uint32_t i, std::uint32_t g) : index(i), generation(g)
 
   36    std::uint32_t generation;
 
   46  template<
typename V, 
typename Key = SlotMapKey>
 
   64  template<
typename V, 
typename Key = SlotMapKey>
 
  147  template<
typename V, 
typename Key = SlotMapKey>
 
  160      _slots.emplace_back(
Slot());
 
  173      std::uint32_t idx = freelist.head;
 
  176      if(idx == freelist.tail)
 
  179        _slots.push_back(
Slot());
 
  180        freelist.head = freelist.tail = (std::uint32_t)_slots.size() - 1;
 
  185        freelist.head = _slots[idx].index;
 
  188      Slot& slot = _slots[idx];
 
  191      slot.index = (std::uint32_t)_data.size();
 
  194      _data.push_back(std::move(
value));
 
  198      _erase.push_back(idx);
 
  200      return Key(idx, slot.generation);
 
  213      std::uint32_t idx = freelist.head;
 
  215      if(idx == freelist.tail)
 
  218        _slots.push_back(
Slot());
 
  219        freelist.head = freelist.tail = (std::uint32_t)_slots.size() - 1;
 
  224        freelist.head = _slots[idx].index;
 
  227      Slot& slot = _slots[idx];
 
  230      slot.index = 
static_cast<std::uint32_t
>(_data.size());
 
  233      _data.push_back(
value);
 
  237      _erase.push_back(idx);
 
  239      return Key(idx, slot.generation);
 
  264      std::swap(_data[slot.index], _data[_data.size() - 1]);
 
  265      std::swap(_erase[slot.index], _erase[_erase.size() - 1]);
 
  268      _slots[_erase[slot.index]].index = slot.index;
 
  275      _slots[freelist.tail].index = key.index;
 
  276      freelist.tail = key.index;
 
  277      _slots[freelist.tail].index = freelist.tail;
 
  324      return (key.index < _slots.size() && _slots[key.index].generation == key.generation);
 
  338      ASSERTM(slot.index < _data.size(), 
"Invalid slot index.");
 
  339      return _data[slot.index];
 
  353      ASSERTM(slot.index < _data.size(), 
"Invalid slot index.");
 
  354      return _data[slot.index];
 
  376      return _data.capacity();
 
  394    const V* data()
 const 
  399    std::size_t bytes()
 const 
  401      return sizeof(freelist) + _slots.size() * 
sizeof(Slot) + _data.size() * 
sizeof(V) +
 
  402             _erase.size() * 
sizeof(
Index);
 
  429        return &(this->_slotmap) == &(rhs._slotmap) && this->_index == rhs._index;
 
  433        return !(*
this == rhs);
 
  445        std::uint32_t slot_index = _slotmap._erase[_index];
 
  446        Slot& slot = _slotmap._slots[slot_index];
 
  472        return &(this->_slotmap) == &(rhs._slotmap) && this->_index == rhs._index;
 
  476        return !(*
this == rhs);
 
  488        std::uint32_t slot_index = _slotmap._erase[_index];
 
  489        const Slot& slot = _slotmap._slots[slot_index];
 
  503    SlotMapIterator end()
 
  505      return SlotMapIterator(*
this, _data.size());
 
  508    ConstSlotMapIterator begin()
 const 
  510      return ConstSlotMapIterator(*
this, 0);
 
  513    ConstSlotMapIterator end()
 const 
  515      return ConstSlotMapIterator(*
this, _data.size());
 
  524      Slot() : index(0), generation(1)
 
  527      Slot(std::uint32_t i, std::uint32_t g) : index(i), generation(g)
 
  532      std::uint32_t generation;
 
  545      ASSERTM(key.index < _slots.size(), 
"Invalid SlotMap key. Index exceeds number of slots.");
 
  546      Slot& slot = _slots[key.index];
 
  547      ASSERTM(key.generation == slot.generation, 
"Invalid SlotMap key. Generation mismatch.");
 
  553      ASSERTM(key.index < _slots.size(), 
"Invalid SlotMap key. Index exceeds number of slots.");
 
  554      const Slot& slot = _slots[key.index];
 
  555      ASSERTM(key.generation == slot.generation, 
"Invalid SlotMap key. Generation mismatch.");
 
  565    std::vector<Slot> _slots;
 
  566    std::vector<V> _data;
 
  567    std::vector<std::uint32_t> _erase;
 
  570  template<
typename V, 
typename Key = SlotMapKey>
 
  574    void insert(
const Key& key, 
const V& 
value)
 
  576      if(key.index >= _slots.size())
 
  578        Index extend_by = 1 + key.index - _slots.size();
 
  579        _slots.insert(_slots.end(), extend_by, 
Slot());
 
  582      Slot& slot = _slots[key.index];
 
  583      slot.value = std::optional<V>(
value);
 
  584      slot.generation = key.generation;
 
  587    bool contains_key(
const Key& key)
 
  589      return key.index < _slots.size() && _slots[key.index].generation == key.generation &&
 
  590             _slots[key.index].value.has_value();
 
  603      ASSERTM(key.index < _slots.size(), 
"Invalid SecondaryMap key. Index exceeds number of slots.");
 
  604      const Slot& slot = _slots[key.index];
 
  605      ASSERTM(slot.value.has_value(), 
"Invalid SecondaryMap key. Slot is unoccupied.");
 
  606      ASSERTM(key.generation == slot.generation, 
"Invalid SecondaryMap key. Generation mismatch.");
 
  607      return slot.value.value();
 
  620      ASSERTM(key.index < _slots.size(), 
"Invalid SecondaryMap key. Index exceeds number of slots.");
 
  621      Slot& slot = _slots[key.index];
 
  622      ASSERTM(slot.value.has_value(), 
"Invalid SecondaryMap key. Slot is unoccupied.");
 
  623      ASSERTM(key.generation == slot.generation, 
"Invalid SecondaryMap key. Generation mismatch.");
 
  624      return slot.value.value();
 
  630      Slot() : generation(1), 
value(std::nullopt)
 
  633      explicit Slot(V&& v) : generation(1), 
value(std::move(v))
 
  637      std::uint32_t generation;
 
  638      std::optional<V> 
value;
 
  641    std::vector<Slot> _slots;
 
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
V & operator[](const Key &key)
Access Operator.
const V & operator[](const Key &key) const
Access Operator.
Const iterator type for the SlotMap.
Iterator type for the SlotMap.
High-performance associative container.
const V & operator[](const Key &key) const
Access Operator.
Key insert(V &&value)
Insert value into the SlotMap.
void reserve(Index capacity)
Reserve at least capacity space in the SlotMap.
V & operator[](const Key &key)
Access Operator.
SlotMap()
Construct SlotMap with initial capacity zero.
Key replace(Key &key, V &&value)
Replace the value stored at key with value.
bool contains_key(const Key &key) const
Check if given key is still valid.
void erase(const Key &key)
Remove a key from the SlotMap.
Index size() const
Retrieve current size of the SlotMap.
Key insert(const V &value)
Insert a value into the SlotMap.
Key replace(Key &key, V &value)
Replace the value stored at key with value.
Index capacity() const
Retrieve current capacity of the SlotMap.
Slot & try_get_slot(const Key &key)
Helper method to retrieve a slot.
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.
Return type for ConstSlotMapIterator.
Return type for SlotMapIterator.
Internal data structure for slots.
Default key type for SlotMap.