Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Vector< T, E, A > Class Template Reference

#include <elm/data/Vector.h>

+ Inheritance diagram for Vector< T, E, A >:

Classes

class  Iter
 

Public Types

typedef T t
 
typedef Vector< T, E, A > self_t
 
- Public Types inherited from Equiv< T >
typedef T t
 

Public Member Functions

 Vector (int _cap=8)
 
 Vector (const Vector< T > &vec)
 
 ~Vector (void)
 
const E & equivalence () const
 
E & equivalence ()
 
const A & allocator () const
 
A & allocator ()
 
int capacity (void) const
 
Array< const T > asArray (void) const
 
Array< T > asArray (void)
 
Array< T > detach (void)
 
void grow (int new_cap)
 
void setLength (int new_length)
 
T & addNew (void)
 
int count (void) const
 
bool contains (const T &v) const
 
template<class C >
bool containsAll (const C &items)
 
bool isEmpty (void) const
 
 operator bool (void) const
 
Iter begin (void) const
 
Iter end (void) const
 
template<class C >
bool equals (const C &c) const
 
bool operator== (const Vector< T > &v) const
 
bool operator!= (const Vector< T > &v) const
 
void clear (void)
 
void add (const T &v)
 
template<class C >
void addAll (const C &c)
 
void remove (const T &value)
 
template<class C >
void removeAll (const C &c)
 
void remove (const Iter &i)
 
Vector< T > & operator+= (const T x)
 
Vector< T > & operator-= (const T x)
 
void copy (const Vector &vec)
 
Vector< T > & operator= (const Vector &vec)
 
int length (void) const
 
const T & get (int i) const
 
int indexOf (const T &v, int p=0) const
 
int lastIndexOf (const T &v, int p=-1) const
 
const T & operator[] (int i) const
 
void shrink (int l)
 
void set (int i, const T &v)
 
void set (const Iter &i, const T &v)
 
T & get (int index)
 
T & get (const Iter &i)
 
T & operator[] (int i)
 
T & operator[] (const Iter &i)
 
void insert (int i, const T &v)
 
void insert (const Iter &i, const T &v)
 
void removeAt (int i)
 
void removeAt (const Iter &i)
 
const T & first (void) const
 
const T & last (void) const
 
Iter find (const T &v) const
 
Iter find (const T &v, const Iter &p) const
 
const T & nth (int i) const
 
T & first ()
 
T & last ()
 
void addFirst (const T &v)
 
void addLast (const T &v)
 
void removeFirst (void)
 
void removeLast (void)
 
void addAfter (const Iter &i, const T &v)
 
void addBefore (const Iter &i, const T &v)
 
void removeBefore (const Iter &i)
 
void removeAfter (const Iter &i)
 
const T & top (void) const
 
T & top (void)
 
pop (void)
 
void push (const T &v)
 
void reset (void)
 
Iter operator* (void) const
 
Iter items (void) const
 
- Public Member Functions inherited from Equiv< T >
bool isEqual (const T &v1, const T &v2) const
 
- Public Member Functions inherited from DefaultAllocatorDelegate
t::ptr allocate (t::size size) const
 
void free (t::ptr p) const
 
template<class T >
T * alloc () const
 

Static Public Attributes

static const Vector< T, E, A > null
 
- Static Public Attributes inherited from Equiv< T >
static Equiv< T > def
 

Additional Inherited Members

- Static Public Member Functions inherited from Equiv< T >
static bool equals (const T &v1, const T &v2)
 

Detailed Description

template<class T, class E = Equiv<T>, class A = DefaultAlloc>
class elm::Vector< T, E, A >

This class provides a generic implementation of an extensible vector. It provides fast access to its content using indexes but the addition of new elements may be expensive if the number of elements exceeds the capacity. Therefore, it more efficient with a small number of elements. For bigger arrays, see FragTable.

Performances
  • indexed access – O(1)
  • addition at begin / end – O(1) on average, O(n) if the vector need to be expanded.
  • removal – O(n)
  • find – O(n)
  • memory – 3 pointers
Implemented concepts
Parameters
TType of data stored in the list.
MManager supporting equivalence and allocation.

Member Typedef Documentation

◆ self_t

typedef Vector<T, E, A> self_t

◆ t

typedef T t

Constructor & Destructor Documentation

◆ Vector() [1/2]

Vector ( int  _cap = 8)
inline

Build a new vector.

Parameters
_capCapacity represents the initial and growing size of the fector.

◆ Vector() [2/2]

Vector ( const Vector< T > &  vec)
inline

Build a vector by copying an existing one.

Parameters
vecVector to copy.

◆ ~Vector()

~Vector ( void  )
inline

Delete the vector and all its contained items.

Member Function Documentation

◆ add()

◆ addAfter()

void addAfter ( const Iter i,
const T &  v 
)
inline

◆ addAll()

void addAll ( const C &  c)
inline

Referenced by Nodes::operator=(), and Plugin::Plugin().

◆ addBefore()

void addBefore ( const Iter i,
const T &  v 
)
inline

◆ addFirst()

void addFirst ( const T &  v)
inline

◆ addLast()

void addLast ( const T &  v)
inline

◆ addNew()

T& addNew ( void  )
inline

◆ allocator() [1/2]

A& allocator ( )
inline

◆ allocator() [2/2]

const A& allocator ( ) const
inline

◆ asArray() [1/2]

Array< T > & asArray ( void  )
inline

Return the vector as an array.

Returns
Array corresponding to the vector.
Warning
The array only stays valid (pointing to actual memory) until the corresponding vector is modified or deleted!

◆ asArray() [2/2]

Array< const T > & asArray ( void  ) const
inline

Return the vector as an array.

Returns
Array corresponding to the vector.
Warning
The array only stays valid (pointing to actual memory) until the corresponding vector is modified or deleted!

Referenced by Bag< T >::make().

◆ begin()

Iter begin ( void  ) const
inline

Referenced by ListOption< T >::begin().

◆ capacity()

int capacity ( void  ) const
inline

Get the capacity of the vector.

Returns
Capacity.

Get the capacity of the vector.

Returns
Vector capacity.

◆ clear()

void clear ( void  )
inline

Remove all items from the vector.

Referenced by Nodes::operator=(), and Vector< elm::dtd::AbstractAttribute * >::reset().

◆ contains()

bool contains ( const T &  v) const
inline

Test if the given value is already in the vector.

Parameters
valueValue to look for.
Returns
True if the value is int he vector, false else.

Referenced by Nodes::contains(), Vector< elm::dtd::AbstractAttribute * >::containsAll(), and Manager::displayHelp().

◆ containsAll()

bool containsAll ( const C &  items)
inline

◆ copy()

void copy ( const Vector< T, E, A > &  vec)
inline

Copy the given vector into the current one.

Parameters
vecVector to copy.

Copy the given vector in the current one.

Parameters
vecVector to copy.

Referenced by Vector< elm::dtd::AbstractAttribute * >::operator=(), and Vector< elm::dtd::AbstractAttribute * >::Vector().

◆ count()

◆ detach()

Table< T > detach ( void  )
inline

Detach the buffer from the vector and return it as a table. After this call, the vector stays unusable until a setLength() or a grow() is performed.

Returns
Vector buffer as a table. The caller is responsible for freeing the obtained buffer.

Referenced by Plugin::Plugin().

◆ end()

Iter end ( void  ) const
inline

Referenced by ListOption< T >::end().

◆ equals()

◆ equivalence() [1/2]

E& equivalence ( )
inline

◆ equivalence() [2/2]

const E& equivalence ( ) const
inline

◆ find() [1/2]

Iter find ( const T &  v) const
inline

◆ find() [2/2]

Iter find ( const T &  v,
const Iter p 
) const
inline

◆ first() [1/2]

T& first ( )
inline

◆ first() [2/2]

const T& first ( void  ) const
inline

◆ get() [1/3]

T& get ( const Iter i)
inline

◆ get() [2/3]

T get ( int  index) const
inline

Get an item from the vector.

Parameters
indexIndex of the item to get.
Returns
Item at the given index.
Attention
It is an error to give an index higher or equal than the vector length().

Referenced by Vector< elm::dtd::AbstractAttribute * >::nth(), and Vector< elm::dtd::AbstractAttribute * >::operator[]().

◆ get() [3/3]

T& get ( int  index)
inline

◆ grow()

void grow ( int  new_cap)
inline

Make the capacity of the vector to grow, possibly causing a buffer re-allocation. Notice that the length is unchanged.

Parameters
new_capNew capacity of the vector.

Enlarge the vector with the given capacity.

Parameters
new_capSize for enlarging the vector.

Referenced by Vector< elm::dtd::AbstractAttribute * >::add(), Vector< elm::dtd::AbstractAttribute * >::addNew(), Vector< elm::dtd::AbstractAttribute * >::insert(), and Vector< elm::dtd::AbstractAttribute * >::setLength().

◆ indexOf()

int indexOf ( const T &  v,
int  p = 0 
) const
inline

Compute the first index of the value in the vector.

Parameters
valueValue to look for.
startStart index for looking the value for.
Returns
Index of the value in the vector or -1.
Attention
It is an error to give an index higher or equal than the vector length().

Referenced by Plugger::Plugger(), and Vector< elm::dtd::AbstractAttribute * >::remove().

◆ insert() [1/2]

void insert ( const Iter i,
const T &  v 
)
inline

◆ insert() [2/2]

◆ isEmpty()

bool isEmpty ( void  ) const
inline

Test if vector is empty.

Returns
True if vector is empty, false else.

Referenced by ListOption< T >::operator bool().

◆ items()

◆ last() [1/2]

T& last ( )
inline

◆ last() [2/2]

const T& last ( void  ) const
inline

◆ lastIndexOf()

int lastIndexOf ( const T &  v,
int  p = -1 
) const
inline

Compute the last index of the value in the vector.

Parameters
valueValue to look for.
startStart index for looking the value for.
Returns
Index of the value in the vector or -1.
Attention
It is an error to give an index higher or equal than the vector length().

◆ length()

int length ( void  ) const
inline

Get the number of items in the vector.

Returns
Items number.

Referenced by Vector< T, E, A >::Iter::ended(), and AbstractBlockAllocatorWithGC::totalCount().

◆ nth()

const T& nth ( int  i) const
inline

◆ operator bool()

operator bool ( void  ) const
inline

Same as isEmpty().

◆ operator!=()

bool operator!= ( const Vector< T > &  v) const
inline

◆ operator*()

Iter operator* ( void  ) const
inline

◆ operator+=()

Vector<T>& operator+= ( const T  x)
inline

◆ operator-=()

Vector<T>& operator-= ( const T  x)
inline

◆ operator=()

Vector< T > & operator= ( const Vector< T, E, A > &  vec)
inline

Shortcut to copy().

◆ operator==()

bool operator== ( const Vector< T > &  v) const
inline

◆ operator[]() [1/3]

T& operator[] ( const Iter i)
inline

◆ operator[]() [2/3]

T & operator[] ( int  index)
inline

Same as item(int).

◆ operator[]() [3/3]

T operator[] ( int  index) const
inline

Same as item(int) const.

◆ pop()

◆ push()

◆ remove() [1/2]

void remove ( const Iter i)
inline

◆ remove() [2/2]

◆ removeAfter()

void removeAfter ( const Iter i)
inline

◆ removeAll()

void removeAll ( const C &  c)
inline

◆ removeAt() [1/2]

void removeAt ( const Iter i)
inline

◆ removeAt() [2/2]

void removeAt ( int  index)
inline

Remove the value at the given index. Values past the index are shifted to the left.

Parameters
indexIndex of the value to remove.
Attention
It is an error to give an index higher or equal than the vector length().

Referenced by ListOption< T >::remove(), Vector< elm::dtd::AbstractAttribute * >::remove(), Vector< elm::dtd::AbstractAttribute * >::removeAfter(), Vector< elm::dtd::AbstractAttribute * >::removeBefore(), Vector< elm::dtd::AbstractAttribute * >::removeFirst(), and Vector< elm::dtd::AbstractAttribute * >::removeLast().

◆ removeBefore()

void removeBefore ( const Iter i)
inline

◆ removeFirst()

void removeFirst ( void  )
inline

◆ removeLast()

void removeLast ( void  )
inline

◆ reset()

void reset ( void  )
inline

◆ set() [1/2]

void set ( const Iter i,
const T &  v 
)
inline

◆ set() [2/2]

void set ( int  i,
const T &  v 
)
inline

◆ setLength()

void setLength ( int  new_length)
inline

Change the length of the vector, possibly causing re-allocation of the buffer.

Parameters
new_lengthNew length of the vector.

Set the length of the vector.

Parameters
new_lengthNew length of the vector (must be less or equal to the current length of the vector).

◆ shrink()

void shrink ( int  l)
inline

◆ top() [1/2]

const T top ( void  )
inline

Get the last item of the vector, that is, the top of the stack represented by the vector.

Returns
Last vector item.

◆ top() [2/2]

Member Data Documentation

◆ null

const Vector< T, E, A > null
static

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