MeVisLab Toolbox Reference
ml::WEMVector< T, fixedBufferSize > Class Template Reference

Dynamic templated vector. More...

#include <WEMVector.h>

Public Member Functions

 WEMVector (unsigned int init=0)
 Standard constructor.
 
 WEMVector (WEMVector &&other) noexcept
 
WEMVectoroperator= (WEMVector &&other) noexcept
 
virtual ~WEMVector ()
 Standard destructor.
 
unsigned int num () const
 Returns the number of elements in this vector.
 
Tat (unsigned int pos) const
 Returns the element at the given position or returns NULL if out of range.
 
Tfirst ()
 Returns the first element.
 
const Tfirst () const
 Returns the first element.
 
Tlast ()
 Returns the last element.
 
const Tlast () const
 Returns the last element.
 
virtual unsigned int append (T *elem)
 Appends the given element to back of this vector.
 
virtual void swap (unsigned int p1, unsigned int p2)
 Swaps the two elements given by their indices in this vector.
 
virtual void clear ()
 Clears all internal pointers.
 
virtual void deleteAt (unsigned int pos)
 Deletes the element at the given position.
 
virtual void deleteLast ()
 Deletes the last element of this vector.
 
virtual int remove (T *elem)
 Deletes the element given by its pointer.
 
virtual int lookup (T *elem) const
 Searches for the given element in this vector and returns its position.
 
virtual int removeUnSwapped (T *elem)
 Deletes the element given by its pointer. Keeps the order of the elements!
 
virtual void destroy ()
 Deletes all elements in this vector.
 
virtual void replace (T *elem, unsigned int pos)
 Replaces the given position with the given element.
 
void reserve (unsigned int init)
 Reserves init elements, copies old ones if existing.
 

Protected Member Functions

virtual void expand ()
 Grow vector, add extra block of size BLOCKSIZE.
 
virtual unsigned int appendUnsafe (T *elem)
 Append element to back of vector, don't check on element being non-NULL.
 

Detailed Description

template<class T, int fixedBufferSize = 32>
class ml::WEMVector< T, fixedBufferSize >

Dynamic templated vector.

For speed and better memory handling, the vector is an array within an array. This allows for quick expanding. An initial internal buffer with 32 pointers avoids an allocation on small vectors.

Definition at line 27 of file WEMVector.h.

Constructor & Destructor Documentation

◆ WEMVector() [1/2]

template<class T , int fixedBufferSize>
ml::WEMVector< T, fixedBufferSize >::WEMVector ( unsigned int init = 0)

Standard constructor.

Definition at line 98 of file WEMVector.h.

References mlrange_cast(), and T.

◆ WEMVector() [2/2]

template<class T , int fixedBufferSize>
ml::WEMVector< T, fixedBufferSize >::WEMVector ( WEMVector< T, fixedBufferSize > && other)
noexcept

Definition at line 111 of file WEMVector.h.

References mlrange_cast().

◆ ~WEMVector()

template<class T , int fixedBufferSize>
ml::WEMVector< T, fixedBufferSize >::~WEMVector ( )
virtual

Standard destructor.

Definition at line 144 of file WEMVector.h.

Member Function Documentation

◆ append()

template<class T , int fixedBufferSize>
unsigned int ml::WEMVector< T, fixedBufferSize >::append ( T * elem)
virtual

Appends the given element to back of this vector.

Definition at line 188 of file WEMVector.h.

References mlrange_cast().

◆ appendUnsafe()

template<class T , int fixedBufferSize>
unsigned int ml::WEMVector< T, fixedBufferSize >::appendUnsafe ( T * elem)
protectedvirtual

Append element to back of vector, don't check on element being non-NULL.

Don't use this function directly!!

Definition at line 205 of file WEMVector.h.

References mlrange_cast().

Referenced by ml::WEMHeap< T >::insert(), and ml::WEMHeap< T >::insert().

◆ at()

template<class T , int fixedBufferSize = 32>
T * ml::WEMVector< T, fixedBufferSize >::at ( unsigned int pos) const
inline

Returns the element at the given position or returns NULL if out of range.

Definition at line 41 of file WEMVector.h.

◆ clear()

template<class T , int fixedBufferSize>
void ml::WEMVector< T, fixedBufferSize >::clear ( )
virtual

Clears all internal pointers.

This does not delete the elements in the vector!

Reimplemented in ml::WEMHeap< T >.

Definition at line 152 of file WEMVector.h.

References mlrange_cast().

Referenced by ml::WEMHeap< T >::clear().

◆ deleteAt()

template<class T , int fixedBufferSize>
void ml::WEMVector< T, fixedBufferSize >::deleteAt ( unsigned int pos)
virtual

Deletes the element at the given position.

Definition at line 243 of file WEMVector.h.

◆ deleteLast()

template<class T , int fixedBufferSize>
void ml::WEMVector< T, fixedBufferSize >::deleteLast ( )
virtual

Deletes the last element of this vector.

Definition at line 255 of file WEMVector.h.

◆ destroy()

template<class T , int fixedBufferSize>
void ml::WEMVector< T, fixedBufferSize >::destroy ( )
virtual

Deletes all elements in this vector.

This does not reset the number of elements!!

Reimplemented in ml::WEMContainer< T >.

Definition at line 168 of file WEMVector.h.

References mlrange_cast().

◆ expand()

template<class T , int fixedBufferSize>
void ml::WEMVector< T, fixedBufferSize >::expand ( )
protectedvirtual

Grow vector, add extra block of size BLOCKSIZE.

Definition at line 180 of file WEMVector.h.

◆ first() [1/2]

template<class T , int fixedBufferSize = 32>
T * ml::WEMVector< T, fixedBufferSize >::first ( )
inline

Returns the first element.

Definition at line 43 of file WEMVector.h.

Referenced by ml::WEMHeap< T >::root().

◆ first() [2/2]

template<class T , int fixedBufferSize = 32>
const T * ml::WEMVector< T, fixedBufferSize >::first ( ) const
inline

Returns the first element.

Definition at line 45 of file WEMVector.h.

References ml::WEMVector< T, fixedBufferSize >::first().

Referenced by ml::WEMVector< T, fixedBufferSize >::first().

◆ last() [1/2]

template<class T , int fixedBufferSize = 32>
T * ml::WEMVector< T, fixedBufferSize >::last ( )
inline

Returns the last element.

Definition at line 47 of file WEMVector.h.

◆ last() [2/2]

template<class T , int fixedBufferSize = 32>
const T * ml::WEMVector< T, fixedBufferSize >::last ( ) const
inline

Returns the last element.

Definition at line 49 of file WEMVector.h.

References ml::WEMVector< T, fixedBufferSize >::last().

Referenced by ml::WEMVector< T, fixedBufferSize >::last().

◆ lookup()

template<class T , int fixedBufferSize>
int ml::WEMVector< T, fixedBufferSize >::lookup ( T * elem) const
virtual

Searches for the given element in this vector and returns its position.

Definition at line 266 of file WEMVector.h.

References mlrange_cast().

◆ num()

template<class T , int fixedBufferSize = 32>
unsigned int ml::WEMVector< T, fixedBufferSize >::num ( ) const
inline

Returns the number of elements in this vector.

Definition at line 39 of file WEMVector.h.

◆ operator=()

template<class T , int fixedBufferSize>
WEMVector< T, fixedBufferSize > & ml::WEMVector< T, fixedBufferSize >::operator= ( WEMVector< T, fixedBufferSize > && other)
noexcept

Definition at line 117 of file WEMVector.h.

References mlrange_cast().

◆ remove()

template<class T , int fixedBufferSize>
int ml::WEMVector< T, fixedBufferSize >::remove ( T * elem)
virtual

Deletes the element given by its pointer.

Definition at line 283 of file WEMVector.h.

References mlrange_cast().

◆ removeUnSwapped()

template<class T , int fixedBufferSize>
int ml::WEMVector< T, fixedBufferSize >::removeUnSwapped ( T * elem)
virtual

Deletes the element given by its pointer. Keeps the order of the elements!

Definition at line 296 of file WEMVector.h.

References mlrange_cast().

◆ replace()

template<class T , int fixedBufferSize>
void ml::WEMVector< T, fixedBufferSize >::replace ( T * elem,
unsigned int pos )
virtual

Replaces the given position with the given element.

Definition at line 219 of file WEMVector.h.

References mlrange_cast().

◆ reserve()

template<class T , int fixedBufferSize>
void ml::WEMVector< T, fixedBufferSize >::reserve ( unsigned int init)

Reserves init elements, copies old ones if existing.

Definition at line 313 of file WEMVector.h.

References mlrange_cast(), and T.

◆ swap()

template<class T , int fixedBufferSize>
void ml::WEMVector< T, fixedBufferSize >::swap ( unsigned int p1,
unsigned int p2 )
virtual

Swaps the two elements given by their indices in this vector.

Reimplemented in ml::WEMContainer< T >, and ml::WEMHeap< T >.

Definition at line 227 of file WEMVector.h.

References mlrange_cast(), and T.

Referenced by ml::WEMHeap< T >::swap().


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