nngn
Loading...
Searching...
No Matches
nngn::static_vector< T > Class Template Reference

Fixed-size vector with an embedded free list. More...

#include <static_vector.h>

Inheritance diagram for nngn::static_vector< T >:
Collaboration diagram for nngn::static_vector< T >:

Classes

union  entry
 

Public Member Functions

 ~static_vector (void)=default
 
 static_vector (void)=default
 Constructs an empty vector.
 
 static_vector (std::size_t n)
 Constructs an empty vector with capacity n.
 
std::size_t size (void) const
 Calculates the true size (excluding the entries in the free list).
 
std::size_t n_free (void) const
 Calculates the number of entries in the free list.
 
bool full (void) const
 Checks if the vector is full (i.e.
 
void set_capacity (std::size_t c)
 Changes the total number of items of the vector can hold.
 
Tinsert (T t)
 Inserts an element in the first free position.
 
template<typename ... Ts>
Templace (Ts &&...ts)
 Emplace an element in the first free position.
 
void erase (T *p)
 Removes element p from the vector.
 
void erase (iterator it)
 Removes the element at *it from the vector.
 
 ~static_vector (void)=default
 
 static_vector (void)=default
 Constructs an empty vector.
 
 static_vector (std::size_t n)
 Constructs an empty vector with capacity n.
 
std::size_t size (void) const
 Calculates the true size (excluding the entries in the free list).
 
std::size_t n_free (void) const
 Calculates the number of entries in the free list.
 
bool full (void) const
 Checks if the vector is full (i.e.
 
void set_capacity (std::size_t c)
 Changes the total number of items of the vector can hold.
 
Tinsert (T t)
 Inserts an element in the first free position.
 
template<typename ... Ts>
Templace (Ts &&...ts)
 Emplace an element in the first free position.
 
void erase (T *p)
 Removes element p from the vector.
 
void erase (iterator it)
 Removes the element at *it from the vector.
 

Private Types

using vector_type = std::vector< T >
 
using vector_type = std::vector< T >
 

Private Attributes

entryfree_head = {}
 Pointer to the first entry in the free list.
 

Detailed Description

template<typename T>
class nngn::static_vector< T >

Fixed-size vector with an embedded free list.

Provides constant time insertion and removal. The free list is kept in the first sizeof(std::uintptr_t) bytes of T. Adding elements when the vector is full results in undefined behavior, but the size can be changed using set_capacity.

Member Typedef Documentation

◆ vector_type [1/2]

template<typename T >
using nngn::static_vector< T >::vector_type = std::vector<T>
private

◆ vector_type [2/2]

template<typename T >
using nngn::static_vector< T >::vector_type = std::vector<T>
private

Constructor & Destructor Documentation

◆ ~static_vector() [1/2]

template<typename T >
nngn::static_vector< T >::~static_vector ( void  )
default

◆ static_vector() [1/4]

template<typename T >
nngn::static_vector< T >::static_vector ( void  )
default

Constructs an empty vector.

set_capacity must be called before items are added.

◆ static_vector() [2/4]

template<typename T >
nngn::static_vector< T >::static_vector ( std::size_t  n)
inlineexplicit

Constructs an empty vector with capacity n.

Here is the call graph for this function:

◆ ~static_vector() [2/2]

template<typename T >
nngn::static_vector< T >::~static_vector ( void  )
default

◆ static_vector() [3/4]

template<typename T >
nngn::static_vector< T >::static_vector ( void  )
default

Constructs an empty vector.

set_capacity must be called before items are added.

◆ static_vector() [4/4]

template<typename T >
nngn::static_vector< T >::static_vector ( std::size_t  n)
inlineexplicit

Constructs an empty vector with capacity n.

Here is the call graph for this function:

Member Function Documentation

◆ emplace() [1/2]

template<typename T >
template<typename ... Ts>
T & nngn::static_vector< T >::emplace ( Ts &&...  ts)

Emplace an element in the first free position.

Complexity: O(1).

Here is the caller graph for this function:

◆ emplace() [2/2]

template<typename T >
template<typename ... Ts>
T & nngn::static_vector< T >::emplace ( Ts &&...  ts)

Emplace an element in the first free position.

Complexity: O(1).

◆ erase() [1/4]

template<typename T >
void nngn::static_vector< T >::erase ( iterator  it)

Removes the element at *it from the vector.

Complexity: O(1).

Here is the call graph for this function:

◆ erase() [2/4]

template<typename T >
void nngn::static_vector< T >::erase ( iterator  it)

Removes the element at *it from the vector.

Complexity: O(1).

◆ erase() [3/4]

template<typename T >
void nngn::static_vector< T >::erase ( T p)

Removes element p from the vector.

Complexity: O(1).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase() [4/4]

template<typename T >
void nngn::static_vector< T >::erase ( T p)

Removes element p from the vector.

Complexity: O(1).

◆ full() [1/2]

template<typename T >
bool nngn::static_vector< T >::full ( void  ) const

Checks if the vector is full (i.e.

no more items can be added).

Here is the caller graph for this function:

◆ full() [2/2]

template<typename T >
bool nngn::static_vector< T >::full ( void  ) const

Checks if the vector is full (i.e.

no more items can be added).

◆ insert() [1/2]

template<typename T >
T & nngn::static_vector< T >::insert ( T  t)
inline

Inserts an element in the first free position.

Complexity: O(1).

Here is the call graph for this function:

◆ insert() [2/2]

template<typename T >
T & nngn::static_vector< T >::insert ( T  t)
inline

Inserts an element in the first free position.

Complexity: O(1).

Here is the call graph for this function:

◆ n_free() [1/2]

template<typename T >
std::size_t nngn::static_vector< T >::n_free ( void  ) const

Calculates the number of entries in the free list.

◆ n_free() [2/2]

template<typename T >
std::size_t nngn::static_vector< T >::n_free ( void  ) const

Calculates the number of entries in the free list.

◆ set_capacity() [1/2]

template<typename T >
void nngn::static_vector< T >::set_capacity ( std::size_t  c)

Changes the total number of items of the vector can hold.

Previous data are lost.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_capacity() [2/2]

template<typename T >
void nngn::static_vector< T >::set_capacity ( std::size_t  c)

Changes the total number of items of the vector can hold.

Previous data are lost.

◆ size() [1/2]

template<typename T >
std::size_t nngn::static_vector< T >::size ( void  ) const

Calculates the true size (excluding the entries in the free list).

Complexity: O(n_free()).

Here is the caller graph for this function:

◆ size() [2/2]

template<typename T >
std::size_t nngn::static_vector< T >::size ( void  ) const

Calculates the true size (excluding the entries in the free list).

Complexity: O(n_free()).

Member Data Documentation

◆ free_head

template<typename T >
entry * nngn::static_vector< T >::free_head = {}
private

Pointer to the first entry in the free list.


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