StochHMM  v0.34
Flexible Hidden Markov Model C++ Library and Application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes
StochHMM::sparseArray< T > Class Template Reference

#include <sparseArray.h>

List of all members.

Public Member Functions

 sparseArray ()
 sparseArray (size_t sz)
 sparseArray (const sparseArray &val)
void clear ()
 Removes all the elements from the array.
void reserve (size_t)
 Reserved memory for at least n elements in the array;.
void resize (size_t)
 Resize the sparseArray to n;.
size_t elements ()
 Returns the number of elements stored in the array.
size_t size ()
 Returns the size of the sparseArray.
T & operator[] (size_t)
const T & operator[] (size_t) const
T & at (size_t pos)
T & back ()
const T & back () const
bool operator== (const sparseArray &rhs)
bool operator!= (const sparseArray &rhs)
sparseArrayoperator= (const sparseArray &rhs)
bool defined (size_t pos)
void insert (size_t pos, T &val)
void push_back (T &)
 Pushes the element on to the array.
void erase (size_t pos)
void pop_back (size_t pos)

Private Attributes

dynamic_bitset flag
std::vector< T > array

Detailed Description

template<typename T>
class StochHMM::sparseArray< T >

SparseArray is a template class that stores the values in a sparse array The values in the array are indexed by a dynamic bitset. For example, to get the value at iterator 5, we need to convert that iterator to the iterator of the std::vector array. This is essentially the number of values that are stored before the value at the 5th position.

SparseArray uses std::vector. This means that it will incure an increased cost of inserting and deleting values.

Definition at line 29 of file sparseArray.h.


Constructor & Destructor Documentation

template<typename T>
StochHMM::sparseArray< T >::sparseArray ( )
template<typename T>
StochHMM::sparseArray< T >::sparseArray ( size_t  sz)
inline

Definition at line 32 of file sparseArray.h.

:flag(sz){};
template<typename T>
StochHMM::sparseArray< T >::sparseArray ( const sparseArray< T > &  val)
inline

Definition at line 33 of file sparseArray.h.

:flag(val.flag), array(val.array){};

Member Function Documentation

template<typename T>
T& StochHMM::sparseArray< T >::at ( size_t  pos)
inline

Definition at line 50 of file sparseArray.h.

{};
template<typename T>
T& StochHMM::sparseArray< T >::back ( )
template<typename T>
const T& StochHMM::sparseArray< T >::back ( ) const
template<typename T >
void StochHMM::sparseArray< T >::clear ( )

Removes all the elements from the array.

Definition at line 81 of file sparseArray.h.

{
array.clear();
return;
}
template<typename T>
bool StochHMM::sparseArray< T >::defined ( size_t  pos)
inline

Return whether an element is defined at position

Returns:
true if element is defined at position
false if element is not defined at position

Definition at line 64 of file sparseArray.h.

Referenced by StochHMM::ExDefSequence::_parseAbsDef(), StochHMM::ExDefSequence::_parseWeightDef(), StochHMM::ExDefSequence::defined(), StochHMM::ExDefSequence::getAbsState(), StochHMM::ExDefSequence::getWeight(), StochHMM::ExDefSequence::isAbsolute(), StochHMM::ExDefSequence::isWeighted(), and StochHMM::ExDefSequence::print().

{return flag[pos];}
template<typename T>
size_t StochHMM::sparseArray< T >::elements ( )
inline

Returns the number of elements stored in the array.

Definition at line 41 of file sparseArray.h.

{return flag.count();};
template<typename T>
void StochHMM::sparseArray< T >::erase ( size_t  pos)
template<typename T>
void StochHMM::sparseArray< T >::insert ( size_t  pos,
T &  val 
)

Insert an element at the position in the array

Parameters:
posPosition within the array to insert value
referenceto value to insert

Definition at line 126 of file sparseArray.h.

{
flag.insert(pos, 1);
flag.set(pos);
size_t array_iter = flag.count_before(pos);
array.insert(array.begin()+array_iter,val);
return;
}
template<typename T>
bool StochHMM::sparseArray< T >::operator!= ( const sparseArray< T > &  rhs)
template<typename T>
sparseArray& StochHMM::sparseArray< T >::operator= ( const sparseArray< T > &  rhs)
template<typename T>
bool StochHMM::sparseArray< T >::operator== ( const sparseArray< T > &  rhs)
template<typename T >
T & StochHMM::sparseArray< T >::operator[] ( size_t  pos)

Returns reference to object at position *If the position is beyond the length, the sparse array will get extended. *If it is defined it will return a reference to the position *If it is not defined and within the current length of the sparseArray and after all the currently set values , it will get added to the end of the array *If it is not defined and within the current lenght of the sparseArray and before other currently set values, then it will get inserted into the array

Definition at line 142 of file sparseArray.h.

{
//Increase size of flags if necessary
if (flag.size() <= pos){
flag.resize(pos);
}
//if called on defined data then return reference
if (defined(pos)){
return array[flag.count_before(pos)];
}
//if called on undefined data then that value will be added as set and returned
//with default value of type
//If position is beyond the last set position then we can simply add it to
//the array
if (flag.find_last() < pos){
flag.set(pos);
array.resize(array.size()+1);
return array.back();
}
//Otherwise, we need to insert the position into the array
//Uses default constructor of typename T
flag.set(pos);
size_t array_iter = flag.count_before(pos);
array.insert(array.begin()+array_iter,T());
return array[array_iter];
}
template<typename T >
const T & StochHMM::sparseArray< T >::operator[] ( size_t  pos) const

Returns reference to object at position *If it is defined it will return a reference to the position

Definition at line 177 of file sparseArray.h.

{
//if called on defined data then return reference
if (defined(pos)){
return array[flag.count_before(pos)];
}
}
template<typename T>
void StochHMM::sparseArray< T >::pop_back ( size_t  pos)
template<typename T>
void StochHMM::sparseArray< T >::push_back ( T &  val)

Pushes the element on to the array.

Definition at line 116 of file sparseArray.h.

{
flag.push_back(true);
array.push_back(val);
return;
}
template<typename T >
void StochHMM::sparseArray< T >::reserve ( size_t  n)

Reserved memory for at least n elements in the array;.

Definition at line 89 of file sparseArray.h.

{
array.reserve(n);
return;
}
template<typename T >
void StochHMM::sparseArray< T >::resize ( size_t  n)

Resize the sparseArray to n;.

Definition at line 97 of file sparseArray.h.

{
//Increasing size only affect increase in flag size
if (n >= flag.size()){
}
// Decrease size- need to also delete items from the array
else{
//# of values to keep is equal to bits set in flag
size_t sz = flag.count();
//Resize array to values needed
array.resize(sz);
}
return;
}
template<typename T>
size_t StochHMM::sparseArray< T >::size ( void  )
inline

Returns the size of the sparseArray.

Definition at line 44 of file sparseArray.h.

Referenced by StochHMM::ExDefSequence::print().

{return flag.size();}

Member Data Documentation

template<typename T>
std::vector<T> StochHMM::sparseArray< T >::array
private

Definition at line 76 of file sparseArray.h.

template<typename T>
dynamic_bitset StochHMM::sparseArray< T >::flag
private

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