Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without heap allocation). More...

#include <prevector.h>

+ Inheritance diagram for prevector< N, T, Size, Diff >:
+ Collaboration diagram for prevector< N, T, Size, Diff >:

Classes

class  const_iterator
 
class  const_reverse_iterator
 
union  direct_or_indirect
 
class  iterator
 
class  reverse_iterator
 

Public Types

typedef Size size_type
 
typedef Diff difference_type
 
typedef T value_type
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 

Public Member Functions

void assign (size_type n, const T &val)
 
template<typename InputIterator >
void assign (InputIterator first, InputIterator last)
 
 prevector ()
 
 prevector (size_type n)
 
 prevector (size_type n, const T &val=T())
 
template<typename InputIterator >
 prevector (InputIterator first, InputIterator last)
 
 prevector (const prevector< N, T, Size, Diff > &other)
 
 prevector (prevector< N, T, Size, Diff > &&other)
 
prevectoroperator= (const prevector< N, T, Size, Diff > &other)
 
prevectoroperator= (prevector< N, T, Size, Diff > &&other)
 
size_type size () const
 
bool empty () const
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
size_t capacity () const
 
T & operator[] (size_type pos)
 
const T & operator[] (size_type pos) const
 
void resize (size_type new_size)
 
void reserve (size_type new_capacity)
 
void shrink_to_fit ()
 
void clear ()
 
iterator insert (iterator pos, const T &value)
 
void insert (iterator pos, size_type count, const T &value)
 
template<typename InputIterator >
void insert (iterator pos, InputIterator first, InputIterator last)
 
void resize_uninitialized (size_type new_size)
 
iterator erase (iterator pos)
 
iterator erase (iterator first, iterator last)
 
void push_back (const T &value)
 
void pop_back ()
 
T & front ()
 
const T & front () const
 
T & back ()
 
const T & back () const
 
void swap (prevector< N, T, Size, Diff > &other)
 
 ~prevector ()
 
bool operator== (const prevector< N, T, Size, Diff > &other) const
 
bool operator!= (const prevector< N, T, Size, Diff > &other) const
 
bool operator< (const prevector< N, T, Size, Diff > &other) const
 
size_t allocated_memory () const
 
value_typedata ()
 
const value_typedata () const
 

Static Public Member Functions

template<typename V >
static void assign_to (const_iterator b, const_iterator e, V &v)
 

Private Member Functions

T * direct_ptr (difference_type pos)
 
const T * direct_ptr (difference_type pos) const
 
T * indirect_ptr (difference_type pos)
 
const T * indirect_ptr (difference_type pos) const
 
bool is_direct () const
 
void change_capacity (size_type new_capacity)
 
T * item_ptr (difference_type pos)
 
const T * item_ptr (difference_type pos) const
 
void fill (T *dst, ptrdiff_t count)
 
void fill (T *dst, ptrdiff_t count, const T &value)
 
template<typename InputIterator >
void fill (T *dst, InputIterator first, InputIterator last)
 
void fill (T *dst, const_iterator first, const_iterator last)
 
void fill (T *dst, const T *src, ptrdiff_t count)
 

Private Attributes

size_type _size
 
union prevector::direct_or_indirect _union
 

Detailed Description

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
class prevector< N, T, Size, Diff >

Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without heap allocation).

The types Size and Diff are used to store element counts, and can be any unsigned + signed type.

Storage layout is either:

  • Direct allocation:
    • Size _size: the number of used elements (between 0 and N)
    • T direct[N]: an array of N elements of type T (only the first _size are initialized).
  • Indirect allocation:
    • Size _size: the number of used elements plus N + 1
    • Size capacity: the number of allocated elements
    • T* indirect: a pointer to an array of capacity elements of type T (only the first _size are initialized).

The data type T must be movable by memmove/realloc(). Once we switch to C++, move constructors can be used instead.

Definition at line 39 of file prevector.h.

Member Typedef Documentation

◆ const_pointer

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
typedef const value_type* prevector< N, T, Size, Diff >::const_pointer

Definition at line 47 of file prevector.h.

◆ const_reference

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
typedef const value_type& prevector< N, T, Size, Diff >::const_reference

Definition at line 45 of file prevector.h.

◆ difference_type

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
typedef Diff prevector< N, T, Size, Diff >::difference_type

Definition at line 42 of file prevector.h.

◆ pointer

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
typedef value_type* prevector< N, T, Size, Diff >::pointer

Definition at line 46 of file prevector.h.

◆ reference

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
typedef value_type& prevector< N, T, Size, Diff >::reference

Definition at line 44 of file prevector.h.

◆ size_type

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
typedef Size prevector< N, T, Size, Diff >::size_type

Definition at line 41 of file prevector.h.

◆ value_type

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
typedef T prevector< N, T, Size, Diff >::value_type

Definition at line 43 of file prevector.h.

Constructor & Destructor Documentation

◆ prevector() [1/6]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( )
inline

Definition at line 266 of file prevector.h.

◆ prevector() [2/6]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( size_type  n)
inlineexplicit

Definition at line 268 of file prevector.h.

References prevector< N, T, Size, Diff >::resize().

◆ prevector() [3/6]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( size_type  n,
const T &  val = T() 
)
inlineexplicit

◆ prevector() [4/6]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
template<typename InputIterator >
prevector< N, T, Size, Diff >::prevector ( InputIterator  first,
InputIterator  last 
)
inline

◆ prevector() [5/6]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( const prevector< N, T, Size, Diff > &  other)
inline

◆ prevector() [6/6]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::prevector ( prevector< N, T, Size, Diff > &&  other)
inline

Definition at line 293 of file prevector.h.

References prevector< N, T, Size, Diff >::swap().

◆ ~prevector()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
prevector< N, T, Size, Diff >::~prevector ( )
inline

Member Function Documentation

◆ allocated_memory()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
size_t prevector< N, T, Size, Diff >::allocated_memory ( ) const
inline

◆ assign() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::assign ( size_type  n,
const T &  val 
)
inline

◆ assign() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
template<typename InputIterator >
void prevector< N, T, Size, Diff >::assign ( InputIterator  first,
InputIterator  last 
)
inline

◆ assign_to()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
template<typename V >
static void prevector< N, T, Size, Diff >::assign_to ( const_iterator  b,
const_iterator  e,
V &  v 
)
inlinestatic

Definition at line 560 of file prevector.h.

References memmove().

Referenced by CScript::GetOp2(), and PrevectorAssignTo().

◆ back() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
T& prevector< N, T, Size, Diff >::back ( )
inline

◆ back() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const T& prevector< N, T, Size, Diff >::back ( ) const
inline

◆ begin() [1/2]

◆ begin() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const_iterator prevector< N, T, Size, Diff >::begin ( ) const
inline

Definition at line 319 of file prevector.h.

References prevector< N, T, Size, Diff >::item_ptr().

◆ capacity()

◆ change_capacity()

◆ clear()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::clear ( )
inline

◆ data() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
value_type* prevector< N, T, Size, Diff >::data ( )
inline

◆ data() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const value_type* prevector< N, T, Size, Diff >::data ( ) const
inline

Definition at line 555 of file prevector.h.

References prevector< N, T, Size, Diff >::item_ptr().

◆ direct_ptr() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
T* prevector< N, T, Size, Diff >::direct_ptr ( difference_type  pos)
inlineprivate

◆ direct_ptr() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const T* prevector< N, T, Size, Diff >::direct_ptr ( difference_type  pos) const
inlineprivate

◆ empty()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::empty ( ) const
inline

Definition at line 314 of file prevector.h.

References prevector< N, T, Size, Diff >::size().

Referenced by CScript::FindAndDelete(), and Serialize_impl().

◆ end() [1/2]

◆ end() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const_iterator prevector< N, T, Size, Diff >::end ( ) const
inline

◆ erase() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
iterator prevector< N, T, Size, Diff >::erase ( iterator  pos)
inline

◆ erase() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
iterator prevector< N, T, Size, Diff >::erase ( iterator  first,
iterator  last 
)
inline

◆ fill() [1/5]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::fill ( T *  dst,
ptrdiff_t  count 
)
inlineprivate

◆ fill() [2/5]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::fill ( T *  dst,
ptrdiff_t  count,
const T &  value 
)
inlineprivate

Definition at line 213 of file prevector.h.

References count.

◆ fill() [3/5]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
template<typename InputIterator >
void prevector< N, T, Size, Diff >::fill ( T *  dst,
InputIterator  first,
InputIterator  last 
)
inlineprivate

Definition at line 220 of file prevector.h.

◆ fill() [4/5]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::fill ( T *  dst,
const_iterator  first,
const_iterator  last 
)
inlineprivate

Definition at line 228 of file prevector.h.

References count, and prevector< N, T, Size, Diff >::fill().

◆ fill() [5/5]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::fill ( T *  dst,
const T *  src,
ptrdiff_t  count 
)
inlineprivate

Definition at line 233 of file prevector.h.

References count, and memmove().

◆ front() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
T& prevector< N, T, Size, Diff >::front ( )
inline

Definition at line 468 of file prevector.h.

References prevector< N, T, Size, Diff >::item_ptr().

◆ front() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const T& prevector< N, T, Size, Diff >::front ( ) const
inline

Definition at line 472 of file prevector.h.

References prevector< N, T, Size, Diff >::item_ptr().

◆ indirect_ptr() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
T* prevector< N, T, Size, Diff >::indirect_ptr ( difference_type  pos)
inlineprivate

◆ indirect_ptr() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const T* prevector< N, T, Size, Diff >::indirect_ptr ( difference_type  pos) const
inlineprivate

◆ insert() [1/3]

◆ insert() [2/3]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::insert ( iterator  pos,
size_type  count,
const T &  value 
)
inline

◆ insert() [3/3]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
template<typename InputIterator >
void prevector< N, T, Size, Diff >::insert ( iterator  pos,
InputIterator  first,
InputIterator  last 
)
inline

◆ is_direct()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::is_direct ( ) const
inlineprivate

◆ item_ptr() [1/2]

◆ item_ptr() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const T* prevector< N, T, Size, Diff >::item_ptr ( difference_type  pos) const
inlineprivate

◆ operator!=()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::operator!= ( const prevector< N, T, Size, Diff > &  other) const
inline

Definition at line 516 of file prevector.h.

◆ operator<()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::operator< ( const prevector< N, T, Size, Diff > &  other) const
inline

◆ operator=() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
prevector& prevector< N, T, Size, Diff >::operator= ( const prevector< N, T, Size, Diff > &  other)
inline

◆ operator=() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
prevector& prevector< N, T, Size, Diff >::operator= ( prevector< N, T, Size, Diff > &&  other)
inline

Definition at line 305 of file prevector.h.

References prevector< N, T, Size, Diff >::swap().

◆ operator==()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
bool prevector< N, T, Size, Diff >::operator== ( const prevector< N, T, Size, Diff > &  other) const
inline

◆ operator[]() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
T& prevector< N, T, Size, Diff >::operator[] ( size_type  pos)
inline

Definition at line 336 of file prevector.h.

References prevector< N, T, Size, Diff >::item_ptr().

◆ operator[]() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const T& prevector< N, T, Size, Diff >::operator[] ( size_type  pos) const
inline

Definition at line 340 of file prevector.h.

References prevector< N, T, Size, Diff >::item_ptr().

◆ pop_back()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::pop_back ( )
inline

◆ push_back()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::push_back ( const T &  value)
inline

◆ rbegin() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
reverse_iterator prevector< N, T, Size, Diff >::rbegin ( )
inline

◆ rbegin() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const_reverse_iterator prevector< N, T, Size, Diff >::rbegin ( ) const
inline

◆ rend() [1/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
reverse_iterator prevector< N, T, Size, Diff >::rend ( )
inline

Definition at line 325 of file prevector.h.

References prevector< N, T, Size, Diff >::item_ptr().

◆ rend() [2/2]

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
const_reverse_iterator prevector< N, T, Size, Diff >::rend ( ) const
inline

Definition at line 326 of file prevector.h.

References prevector< N, T, Size, Diff >::item_ptr().

◆ reserve()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::reserve ( size_type  new_capacity)
inline

◆ resize()

◆ resize_uninitialized()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::resize_uninitialized ( size_type  new_size)
inline

◆ shrink_to_fit()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::shrink_to_fit ( )
inline

◆ size()

◆ swap()

template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
void prevector< N, T, Size, Diff >::swap ( prevector< N, T, Size, Diff > &  other)
inline

Member Data Documentation

◆ _size

◆ _union


The documentation for this class was generated from the following file:
Released under the MIT license