artdaq_core  v3_05_10
artdaq::QuickVec< TT_ > Struct Template Reference

A QuickVec behaves like a std::vector, but does no initialization of its data, making it faster at the cost of having to ensure that uninitialized data is not read. More...

#include <artdaq-core/Core/QuickVec.hh>

Public Types

typedef TT_ * iterator
 Iterator is pointer-to-member type.
 
typedef const TT_ * const_iterator
 const_iterator is const-pointer-to-member type
 
typedef TT_ & reference
 reference is reference-to-member tpye
 
typedef const TT_ & const_reference
 const_reference is const-reference-to-member type
 
typedef TT_ value_type
 value_type is member type
 
typedef ptrdiff_t difference_type
 difference_type is ptrdiff_t
 
typedef size_t size_type
 size_type is size_t
 

Public Member Functions

 QuickVec (size_t sz)
 Allocates a QuickVec object, doing no initialization of allocated memory. More...
 
 QuickVec (size_t sz, TT_ val)
 Allocates a QuickVec object, initializing each element to the given value. More...
 
virtual ~QuickVec () noexcept
 Destructor calls free on data.
 
 QuickVec (std::vector< TT_ > &other)
 Copies the contents of a std::vector into a new QuickVec object. More...
 
void clear ()
 Sets the size to 0. QuickVec does not reinitialize memory, so no further action will be taken.
 
 QuickVec (const QuickVec &other)
 Copy Constructor. More...
 
QuickVec< TT_ > & operator= (const QuickVec &other)
 Copy assignment operator. More...
 
TT_ & operator[] (int idx)
 Returns a reference to a given element. More...
 
const TT_ & operator[] (int idx) const
 Returns a const reference to a given element. More...
 
size_t size () const
 Accesses the current size of the QuickVec. More...
 
size_t capacity () const
 Accesses the current capacity of the QuickVec. More...
 
iterator begin ()
 Gets an iterator to the beginning of the QuickVec. More...
 
const_iterator begin () const
 Gets a const_iterator to the beginning of the QuickVec. More...
 
iterator end ()
 Gets an iterator to the end of the QuickVec. More...
 
const_iterator end () const
 Gets a const_iterator to the end of the QuickVec. More...
 
void reserve (size_t size)
 Allocates memory for the QuickVec so that its capacity is at least size. More...
 
void resize (size_t size)
 Resizes the QuickVec. More...
 
void resizeWithCushion (size_t size, double growthFactor=1.3)
 Resizes the QuickVec and requests additional capacity. More...
 
void resize (size_t size, TT_ val)
 Resizes the QuickVec, initializes new elements with val. More...
 
iterator insert (const_iterator position, size_t nn, const TT_ &val)
 Inserts an element into the QuickVec. More...
 
iterator insert (const_iterator position, const_iterator first, const_iterator last)
 Inserts a range of elements into the QuickVec. More...
 
iterator erase (const_iterator first, const_iterator last)
 Erases elements in given range from the QuickVec. More...
 
void swap (QuickVec &other) noexcept
 Exchanges references to two QuickVec objects. More...
 
void push_back (const value_type &val)
 Adds a value to the QuickVec, resizing if necessary (adds 10% capacity) More...
 

Static Public Member Functions

static short Class_Version ()
 Returns the current version of the template code \ *. More...
 

Detailed Description

template<typename TT_>
struct artdaq::QuickVec< TT_ >

A QuickVec behaves like a std::vector, but does no initialization of its data, making it faster at the cost of having to ensure that uninitialized data is not read.

Template Parameters
TT_The data type stored in the QuickVec

Definition at line 87 of file QuickVec.hh.

Constructor & Destructor Documentation

template<typename TT_ >
artdaq::QuickVec< TT_ >::QuickVec ( size_t  sz)
inline

Allocates a QuickVec object, doing no initialization of allocated memory.

Parameters
szSize of QuickVec object to allocate

Definition at line 345 of file QuickVec.hh.

template<typename TT_>
artdaq::QuickVec< TT_ >::QuickVec ( size_t  sz,
TT_  val 
)
inline

Allocates a QuickVec object, initializing each element to the given value.

Parameters
szSize of QuickVec object to allocate
valValue with which to initialize elements

Definition at line 354 of file QuickVec.hh.

template<typename TT_>
artdaq::QuickVec< TT_ >::QuickVec ( std::vector< TT_ > &  other)
inline

Copies the contents of a std::vector into a new QuickVec object.

Parameters
otherThe vector to copy

Definition at line 119 of file QuickVec.hh.

template<typename TT_>
artdaq::QuickVec< TT_ >::QuickVec ( const QuickVec< TT_ > &  other)
inline

Copy Constructor.

Parameters
otherQuickVec to copy

Definition at line 138 of file QuickVec.hh.

Member Function Documentation

template<typename TT_ >
QuickVec< TT_ >::iterator artdaq::QuickVec< TT_ >::begin ( )
inline

Gets an iterator to the beginning of the QuickVec.

Returns
An iterator to the beginning of the QuickVec

Definition at line 393 of file QuickVec.hh.

template<typename TT_ >
QuickVec< TT_ >::const_iterator artdaq::QuickVec< TT_ >::begin ( ) const
inline

Gets a const_iterator to the beginning of the QuickVec.

Returns
A const_iterator to the beginning of the QuickVec

Definition at line 396 of file QuickVec.hh.

template<typename TT_ >
size_t artdaq::QuickVec< TT_ >::capacity ( ) const
inline

Accesses the current capacity of the QuickVec.

Returns
The current capacity of the QuickVec

Accesses the current capcity of the QuickVec. Like a vector, the capacity of a QuickVec object is defined as the maximum size it can hold before it must reallocate more memory.

Definition at line 390 of file QuickVec.hh.

template<typename TT_>
static short artdaq::QuickVec< TT_ >::Class_Version ( )
inlinestatic

Returns the current version of the template code \ *.

\ *

Returns
The current version of the QuickVec \ * \ * Class_Version() MUST be updated every time private member data change. \

Definition at line 333 of file QuickVec.hh.

template<typename TT_ >
QuickVec< TT_ >::iterator artdaq::QuickVec< TT_ >::end ( )
inline

Gets an iterator to the end of the QuickVec.

Returns
An iterator to the end of the QuickVec

Definition at line 399 of file QuickVec.hh.

template<typename TT_ >
QuickVec< TT_ >::const_iterator artdaq::QuickVec< TT_ >::end ( ) const
inline

Gets a const_iterator to the end of the QuickVec.

Returns
A const_iterator to the end of the QuickVec

Definition at line 402 of file QuickVec.hh.

template<typename TT_ >
QuickVec< TT_ >::iterator artdaq::QuickVec< TT_ >::erase ( const_iterator  first,
const_iterator  last 
)
inline

Erases elements in given range from the QuickVec.

Parameters
firstFirst element to erase
lastLast element to erase
Returns
iterator to first element after erase range

Erases elements in given range from the QuickVec. Note that since the underlying data structure resembles a std::vector, erase operations are very inefficient! (O(n))

Definition at line 512 of file QuickVec.hh.

template<typename TT_>
QuickVec< TT_ >::iterator artdaq::QuickVec< TT_ >::insert ( const_iterator  position,
size_t  nn,
const TT_ &  val 
)
inline

Inserts an element into the QuickVec.

Parameters
positionPosition at which to isnert
nnNumber of copies of val to insert
valValue to insert
Returns
Iterator to first inserted element

Inserts an element (or copies thereof) into the QuickVec. Note that since the underlying data structure resembles a std::vector, insert operations are very inefficient!

Definition at line 475 of file QuickVec.hh.

template<typename TT_>
QuickVec< TT_ >::iterator artdaq::QuickVec< TT_ >::insert ( const_iterator  position,
const_iterator  first,
const_iterator  last 
)
inline

Inserts a range of elements into the QuickVec.

Parameters
positionPosition at which to insert
firstconst_iterator to first element to insert
lastconst_iterator to last element to insert
Returns
Iterator to first inserted element

Inserts elements into the QuickVec. Note that since the underlying data structure resembles a std::vector, insert operations are very inefficient!

Definition at line 493 of file QuickVec.hh.

template<typename TT_>
QuickVec<TT_>& artdaq::QuickVec< TT_ >::operator= ( const QuickVec< TT_ > &  other)
inline

Copy assignment operator.

Parameters
otherQuickVec to copy
Returns
Reference to new QuickVec object

Definition at line 152 of file QuickVec.hh.

template<typename TT_ >
TT_ & artdaq::QuickVec< TT_ >::operator[] ( int  idx)
inline

Returns a reference to a given element.

Parameters
idxElement to return
Returns
Reference to element

Definition at line 373 of file QuickVec.hh.

template<typename TT_ >
const TT_ & artdaq::QuickVec< TT_ >::operator[] ( int  idx) const
inline

Returns a const reference to a given element.

Parameters
idxElement to return
Returns
const reference to element

Definition at line 380 of file QuickVec.hh.

template<typename TT_ >
void artdaq::QuickVec< TT_ >::push_back ( const value_type val)
inline

Adds a value to the QuickVec, resizing if necessary (adds 10% capacity)

Parameters
valValue to add to the QuickVec

Definition at line 538 of file QuickVec.hh.

template<typename TT_ >
void artdaq::QuickVec< TT_ >::reserve ( size_t  size)
inline

Allocates memory for the QuickVec so that its capacity is at least size.

Parameters
sizeThe new capacity of the QuickVec

Allocates memory for the QuickVec so that its capacity is at least size. If the QuickVec is already at or above size in capacity, no allocation is performed.

Definition at line 405 of file QuickVec.hh.

template<typename TT_ >
void artdaq::QuickVec< TT_ >::resize ( size_t  size)
inline

Resizes the QuickVec.

Parameters
sizeNew size of the QuickVec

If size is smaller than the current size of the QuickVec, then it will change its size_ parameter (no reallocation, capacity does not change). If size is greater than the capacity of the QuickVec, a reallocation will occur.

Definition at line 420 of file QuickVec.hh.

template<typename TT_>
void artdaq::QuickVec< TT_ >::resize ( size_t  size,
TT_  val 
)
inline

Resizes the QuickVec, initializes new elements with val.

Parameters
sizeNew size of the QuickVec
valValue with which to initialize elements

Definition at line 463 of file QuickVec.hh.

template<typename TT_ >
void artdaq::QuickVec< TT_ >::resizeWithCushion ( size_t  size,
double  growthFactor = 1.3 
)
inline

Resizes the QuickVec and requests additional capacity.

Parameters
sizeNew size of the QuickVec
growthFactorFactor to use when allocating additional capacity

This method updates the size of the QuickVec. If the new size is within the current capacity, no realloction takes place. If not, then the reallocation reserves additional capacity as a cushion against future needs to reallocate, based on the specified growth factor.

Definition at line 438 of file QuickVec.hh.

template<typename TT_ >
size_t artdaq::QuickVec< TT_ >::size ( ) const
inline

Accesses the current size of the QuickVec.

Returns
The current size of the QuickVec

Definition at line 387 of file QuickVec.hh.

template<typename TT_ >
void artdaq::QuickVec< TT_ >::swap ( QuickVec< TT_ > &  other)
inlinenoexcept

Exchanges references to two QuickVec objects.

Parameters
otherOther QuickVec to swap with

Definition at line 528 of file QuickVec.hh.


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