Skip to main content

The GrowVector Class Template Reference

std::vector like container optimized for pushing elements to the back. More...

Declaration

template <class T> class GrowVector<T> { ... }

Included Headers

#include <src/growvector.h>

Public Member Typedefs Index

template <class T>
usingiterator = Iterator< GrowVector, T >
template <class T>
usingconst_iterator = Iterator< const GrowVector, const T >

Private Member Typedefs Index

template <class T>
usingChunkPtr = std::unique_ptr< Chunk >

Public Member Functions Index

template <class T>
iteratorbegin ()

returns an iterator to the beginning More...

template <class T>
const_iteratorbegin () const

returns an iterator to the beginning More...

template <class T>
iteratorend ()

returns an iterator to the end More...

template <class T>
const_iteratorend () const

returns an iterator to the end More...

template <class T>
size_tsize () const

returns the number of elements More...

template <class T>
voidpush_back (T &&t)

adds an element to the end More...

template <class... Args>
voidemplace_back (Args &&...args)

constructs an element in-place at the end More...

template <class T>
voidpop_back ()

removes the last element More...

template <class T>
T &at (size_t i)

access specified element More...

template <class T>
const T &at (size_t i) const

access specified element More...

template <class T>
T &front ()

access the first element More...

template <class T>
const T &front () const

access the first element More...

template <class T>
T &back ()

access the last element More...

template <class T>
const T &back () const

access the last element More...

template <class T>
boolempty () const

checks whether the container is empty More...

template <class T>
voidclear ()

clears the contents More...

Private Member Functions Index

template <class T>
voidmake_room ()

Private Member Attributes Index

template <class T>
std::vector< ChunkPtr >m_chunks

Private Static Attributes Index

template <class T>
static const size_tchunkBits = 4
template <class T>
static const size_tchunkSize = 1 << chunkBits
template <class T>
static const size_tchunkMask = chunkSize-1

Description

std::vector like container optimized for pushing elements to the back.

It differs from std::vector in that it can grow without invalidating pointers to its members just like std::deque and std::list.

It differs from std::deque in that the value can be incomplete just like std::vector.

It differs from std::list in that it does not need to allocate each node separately and provides random access to its members.

It is implemented as a vector of chunks where each chunk is a fixed capacity vector of T.

Definition at line 39 of file growvector.h.

Public Member Typedefs

const_iterator

template <class T>
using GrowVector< T >::const_iterator = Iterator<const GrowVector,const T>

Definition at line 80 of file growvector.h.

iterator

template <class T>
using GrowVector< T >::iterator = Iterator<GrowVector,T>

Definition at line 79 of file growvector.h.

Private Member Typedefs

ChunkPtr

template <class T>
using GrowVector< T >::ChunkPtr = std::unique_ptr<Chunk>

Definition at line 50 of file growvector.h.

50 using ChunkPtr = std::unique_ptr<Chunk>;

Public Member Functions

at()

template <class T>
T & GrowVector< T >::at (size_t i)
inline

access specified element

Definition at line 125 of file growvector.h.

125 T &at(size_t i) { return m_chunks.at(i>>chunkBits)->data.at(i&chunkMask); }

References GrowVector< T >::chunkBits, GrowVector< T >::chunkMask and GrowVector< T >::m_chunks.

at()

template <class T>
const T & GrowVector< T >::at (size_t i)
inline

access specified element

Definition at line 127 of file growvector.h.

127 const T &at(size_t i) const { return m_chunks.at(i>>chunkBits)->data.at(i&chunkMask); }

References GrowVector< T >::chunkBits, GrowVector< T >::chunkMask and GrowVector< T >::m_chunks.

back()

template <class T>
T & GrowVector< T >::back ()
inline

access the last element

Definition at line 135 of file growvector.h.

135 T &back() { return m_chunks.back()->data.back(); }

Reference GrowVector< T >::m_chunks.

Referenced by DocPara::handleHtmlStartTag, DocParser::handleStyleEnter and DocParser::internalValidatingParseDoc.

back()

template <class T>
const T & GrowVector< T >::back ()
inline

access the last element

Definition at line 137 of file growvector.h.

137 const T &back() const { return m_chunks.back()->data.back(); }

Reference GrowVector< T >::m_chunks.

begin()

template <class T>
iterator GrowVector< T >::begin ()
inline

returns an iterator to the beginning

Definition at line 83 of file growvector.h.

83 iterator begin() { return iterator(*this,0); }

begin()

template <class T>
const_iterator GrowVector< T >::begin ()
inline

returns an iterator to the beginning

Definition at line 85 of file growvector.h.

85 const_iterator begin() const { return const_iterator(*this,0); }

clear()

template <class T>
void GrowVector< T >::clear ()
inline

clears the contents

Definition at line 143 of file growvector.h.

143 void clear() { m_chunks.clear(); }

Reference GrowVector< T >::m_chunks.

Referenced by flattenParagraphs and DocNodeList::move_append.

emplace_back()

template <class... Args>
void GrowVector< T >::emplace_back (Args &&... args)
inline

constructs an element in-place at the end

Definition at line 108 of file growvector.h.

108 void emplace_back(Args&&...args)
109 {
110 make_room();
111 m_chunks.back()->data.emplace_back(std::forward<Args>(args)...);
112 }

References GrowVector< T >::m_chunks and GrowVector< T >::make_room.

empty()

end()

template <class T>
iterator GrowVector< T >::end ()
inline

returns an iterator to the end

Definition at line 88 of file growvector.h.

88 iterator end() { return iterator(*this,size()); }

Reference GrowVector< T >::size.

Referenced by DocPara::handleIncludeOperator.

end()

template <class T>
const_iterator GrowVector< T >::end ()
inline

returns an iterator to the end

Definition at line 90 of file growvector.h.

90 const_iterator end() const { return const_iterator(*this,size()); }

Reference GrowVector< T >::size.

front()

template <class T>
T & GrowVector< T >::front ()
inline

access the first element

Definition at line 130 of file growvector.h.

130 T &front() { return m_chunks.front()->data.front(); }

Reference GrowVector< T >::m_chunks.

Referenced by DocHtmlTable::firstRow and DocbookDocVisitor::operator().

front()

template <class T>
const T & GrowVector< T >::front ()
inline

access the first element

Definition at line 132 of file growvector.h.

132 const T &front() const { return m_chunks.front()->data.front(); }

Reference GrowVector< T >::m_chunks.

pop_back()

template <class T>
void GrowVector< T >::pop_back ()
inline

removes the last element

Definition at line 115 of file growvector.h.

115 void pop_back()
116 {
117 m_chunks.back()->data.pop_back();
118 if (m_chunks.back()->data.size()==0) // remove chunk if empty
119 {
120 m_chunks.pop_back();
121 }
122 }

Reference GrowVector< T >::m_chunks.

Referenced by DocPara::handleCommand, DocPara::handleFile, DocPara::handleHtmlStartTag, DocPara::handleXRefItem, DocParser::internalValidatingParseDoc, DocAutoListItem::parse, DocInternal::parse, DocRoot::parse and DocSection::parse.

push_back()

template <class T>
void GrowVector< T >::push_back (T && t)
inline

adds an element to the end

Definition at line 100 of file growvector.h.

100 void push_back(T &&t)
101 {
102 make_room();
103 m_chunks.back()->data.push_back(std::move(t));
104 }

References GrowVector< T >::m_chunks and GrowVector< T >::make_room.

size()

template <class T>
size_t GrowVector< T >::size ()
inline

returns the number of elements

Definition at line 93 of file growvector.h.

93 size_t size() const
94 {
95 return m_chunks.empty() ? 0 : (m_chunks.size()-1)*chunkSize +
96 m_chunks.back()->data.size();
97 }

References GrowVector< T >::chunkSize and GrowVector< T >::m_chunks.

Referenced by GrowVector< T >::end, GrowVector< T >::end, DocPara::handleIncludeOperator, DocHtmlRow::numCells and DocHtmlTable::numRows.

Private Member Functions

make_room()

template <class T>
void GrowVector< T >::make_room ()
inline

Definition at line 146 of file growvector.h.

146 void make_room()
147 {
148 if (m_chunks.empty() ||
149 m_chunks.back()->data.size()==chunkSize) // add new chuck if needed
150 {
151 m_chunks.push_back(std::make_unique<Chunk>());
152 }
153 }

References GrowVector< T >::chunkSize and GrowVector< T >::m_chunks.

Referenced by GrowVector< T >::emplace_back and GrowVector< T >::push_back.

Private Static Attributes

chunkBits

template <class T>
const size_t GrowVector< T >::chunkBits = 4
static

Definition at line 42 of file growvector.h.

42 static const size_t chunkBits = 4; // a chunk holds 2^bits elements

Referenced by GrowVector< T >::at and GrowVector< T >::at.

chunkMask

template <class T>
const size_t GrowVector< T >::chunkMask = chunkSize-1
static

Definition at line 44 of file growvector.h.

44 static const size_t chunkMask = chunkSize-1;

Referenced by GrowVector< T >::at and GrowVector< T >::at.

chunkSize

template <class T>
const size_t GrowVector< T >::chunkSize = 1 << chunkBits
static

Definition at line 43 of file growvector.h.

43 static const size_t chunkSize = 1 << chunkBits;

Referenced by GrowVector< T >::Chunk::Chunk, GrowVector< T >::make_room and GrowVector< T >::size.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.