jubilant-funicular
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
nta::utils::SlotMap< T, IndexType, GenType > Class Template Reference

#include <SlotMap.h>

Collaboration diagram for nta::utils::SlotMap< T, IndexType, GenType >:
Collaboration graph
[legend]

Public Types

using value_type = T
 
using iterator = T *
 
using const_iterator = const T *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
using reference = T &
 
using const_reference = const T &
 
using index_type = IndexType
 
using size_type = IndexType
 
using gen_type = GenType
 
using Key = SlotMapKey< IndexType, GenType >
 
using storage_type = typename std::aligned_storage_t< sizeof(T), alignof(T)>
 

Public Member Functions

size_type size () const
 
size_type capacity () const
 
size_type cap () const
 
bool is_empty () const
 
bool empty () const
 
Option< reference > at (Key k)
 
Option< const_reference > at (Key k) const
 
Option< reference > operator[] (Key k)
 
Option< const_reference > operator[] (Key k) const
 
T & at_unsafe (Key k)
 
const T & at_unsafe (Key k) const
 
gen_type get_curr_gen (index_type idx) const
 
gen_type get_curr_gen (Key k) const
 
Key get_curr_key (index_type idx) const
 
Key get_curr_key (Key k) const
 
bool is_free (index_type key_idx) const
 
bool is_free (Key k) const
 
Key add (const T &elem)
 
Key push (const T &elem)
 
template<typename... Args>
Key emplace (Args &&... args)
 
bool insert (Key k, const T &elem)
 
template<typename... Args>
bool insert_emplace (Key k, Args &&... args)
 
void reserve (size_type new_cap)
 
void remove (Key k)
 
void deactivate (Key k)
 Same thing as remove, but odes not bump the generation.
 
void erase (Key k)
 
void clear ()
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
const_reverse_iterator crbegin ()
 
const_reverse_iterator crend ()
 

Private Member Functions

void grow ()
 
void remove_impl (Key k, bool gen_bump)
 
Option< reference > at_impl (Key k) const
 
reference _get_raw (index_type idx) const
 

Private Attributes

Keym_slots {}
 
storage_type * m_data {}
 
index_type * m_slot_idxes {}
 
size_type m_size {}
 
size_type m_cap {}
 
index_type m_free_head {}
 

Static Private Attributes

constexpr static size_type DEFAULT_CAP = 4
 

Detailed Description

template<typename T, typename IndexType = std::size_t, typename GenType = uint16_t>
class nta::utils::SlotMap< T, IndexType, GenType >

An unsorted container supporting fast insertion/deletion without invalidating references to its elements.

Warning: Doesn't really do error checking, so use carefully.

Definition at line 105 of file SlotMap.h.

Member Function Documentation

◆ insert()

template<typename T , typename IndexType , typename GenType >
bool nta::utils::SlotMap< T, IndexType, GenType >::insert ( Key  k,
const T &  elem 
)

Checks that k refers to a free slot with the right generation

Returns true on success

Definition at line 297 of file SlotMap.h.


The documentation for this class was generated from the following file: