HermesCommon  3.0
Hermes::Array< TYPE > Class Template Reference

Public Member Functions

 Array (int initial_page_count=0)
 
 Array (Array &array)
 
void copy (const Array &array)
 Makes this array to hold a copy of another one.
 
void free ()
 Removes all elements from the array.
 
void set_append_only (bool append_only)
 
int add (TYPE item)
 Wrapper function for std::vector::add() for compatibility purposes.
 
TYPE * add ()
 
void remove (int id)
 
int first (int idx=0)
 
int next (int idx=0)
 
int last (int idx=INT_MAX)
 
int prev (int idx=INT_MAX)
 
bool exists (int idx)
 Checks whether an element exists at position idx.
 
TYPE * skip_slot ()
 
int get_size () const
 
int get_num_items () const
 
TYPE & get (int id) const
 
TYPE & operator[] (int id) const
 

Protected Attributes

TYPE ** pages
 
int * unused
 
unsigned int page_count
 
unsigned int size
 
unsigned int nitems
 
unsigned int unused_size
 
unsigned int nunused
 
bool append_only
 

Detailed Description

template<class TYPE>
class Hermes::Array< TYPE >

Definition at line 43 of file array.h.

Member Function Documentation

template<class TYPE >
TYPE* Hermes::Array< TYPE >::add ( )
inline

Adds a new_ item to the array: either it is appended at the end or an unused item is reused.

Returns
A reference to the newly allocated item of the array. The item is assigned an id and its used flag is set to 1.

Definition at line 138 of file array.h.

Referenced by Hermes::Array< TYPE >::add().

template<class TYPE >
int Hermes::Array< TYPE >::first ( int  idx = 0)
inline

Get the first index that is present and is equal to or greater than the passed idx. Typically used to begin an iteration over all indices present in the array.

Parameters
[in]idxOptional, default value 0 (finds the first present index).
Returns
  • First index present in the array that is equal or greater than the passed idx (if found),
  • INVALID_IDX (if not found).

Definition at line 188 of file array.h.

template<class TYPE >
int Hermes::Array< TYPE >::last ( int  idx = INT_MAX)
inline

Get the last index present in the array that is equal to or less than the passed idx. Typically used to begin a reverse iteration over all indices present in the array.

Parameters
[in]idxOptional, default value (Word_t) -1 (finds the last index present in the array).
Returns
  • Last index present in the array that is equal or less than the passed idx (if found),
  • INVALID_IDX (if not found).

Definition at line 222 of file array.h.

template<class TYPE >
int Hermes::Array< TYPE >::next ( int  idx = 0)
inline

Get the first index that is present and is greater than the passed idx. Typically used to continue an iteration over all indices present in the array.

Parameters
[in]idxIndex whose succesor we want to find. Optional, default value 0.
Returns
  • First idx present in the array that is greater than the passed idx (if found),
  • INVALID_IDX (if not found).

Definition at line 205 of file array.h.

template<class TYPE >
int Hermes::Array< TYPE >::prev ( int  idx = INT_MAX)
inline

Get the last index present in the array that is less than the passed idx. Typically used to continue a reverse iteration over all indices present in the array.

Parameters
[in]idxIndex whose predecessor we want to find. Optional, default value (Word_t) -1.
Returns
  • Last index present in the array that is less than the passed idx (if found),
  • INVALID_IDX (if not found).

Definition at line 240 of file array.h.

template<class TYPE >
void Hermes::Array< TYPE >::remove ( int  id)
inline

Removes the given item from the array, ie., marks it as unused. Note that the array is never physically shrinked. This should not be a problem, since meshes tend to grow rather than become smaller.

Parameters
id[in] Item id number.

Definition at line 167 of file array.h.

template<class TYPE >
void Hermes::Array< TYPE >::set_append_only ( bool  append_only)
inline

Sets or resets the append-only mode. In append-only mode new elements are only added to the end of the array. This can be useful eg. when refining all elements of a mesh in which case the newly added elements must not be processed again by the for-loop. Normally this option should be off.

Definition at line 121 of file array.h.

template<class TYPE >
TYPE* Hermes::Array< TYPE >::skip_slot ( )
inline

Adds an unused item at the end of the array and skips its ID forever. This is a special-purpose function used to create empty element slots.

Definition at line 261 of file array.h.

Member Data Documentation

template<class TYPE >
TYPE** Hermes::Array< TYPE >::pages
protected
Todo:
standard array for maximum access speed

Definition at line 47 of file array.h.

Referenced by Hermes::Array< TYPE >::add(), Hermes::Array< TYPE >::copy(), and Hermes::Array< TYPE >::skip_slot().


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