Relacs Numerics Library
0.9.8
|
#include <cyclicarray.h>
Public Types | |
typedef T | value_type |
typedef T * | pointer |
typedef T & | reference |
typedef const T & | const_reference |
typedef int | size_type |
Public Member Functions | |
CyclicArray (void) | |
CyclicArray (int n) | |
CyclicArray (CyclicArray< T > *ca) | |
CyclicArray (const CyclicArray< T > &ca) | |
virtual | ~CyclicArray (void) |
const CyclicArray< T > & | operator= (const CyclicArray< T > &a) |
const CyclicArray< T > & | assign (const CyclicArray< T > &a) |
const CyclicArray< T > & | assign (const CyclicArray< T > *a) |
int | size (void) const |
virtual int | accessibleSize (void) const |
virtual int | minIndex (void) const |
bool | empty (void) const |
virtual void | resize (int n, const T &val=0) |
virtual void | clear (void) |
int | capacity (void) const |
virtual void | reserve (int n) |
void | update (const CyclicArray< T > *a) |
const T & | operator[] (int i) const |
T & | operator[] (int i) |
const T & | at (int i) const |
T & | at (int i) |
const T & | front (void) const |
T & | front (void) |
const T & | back (void) const |
T & | back (void) |
void | push (const T &val) |
T | pop (void) |
int | maxPush (void) const |
T * | pushBuffer (void) |
void | push (int n) |
virtual int | readSize (void) const |
int | readIndex (void) const |
T | read (void) |
T | min (int from, int upto) const |
T | max (int from, int upto) const |
void | minMax (T &min, T &max, int from, int upto) const |
T | minAbs (int from, int upto) const |
T | maxAbs (int from, int upto) const |
numerical_traits< T >::mean_type | mean (int from, int upto) const |
numerical_traits< T > ::variance_type | variance (int from, int upto) const |
numerical_traits< T > ::variance_type | stdev (int from, int upto) const |
numerical_traits< T > ::variance_type | rms (int from, int upto) const |
template<typename S > | |
void | hist (SampleData< S > &h, int from, int upto) const |
template<typename S > | |
void | hist (SampleData< S > &h) const |
const T * | readBuffer (int index, int &maxn) const |
int | saveBinary (ostream &os, int index) const |
int | loadBinary (istream &is, int index) |
Protected Attributes | |
bool | Own |
T * | Buffer |
int | NBuffer |
int | RCycles |
int | R |
int | LCycles |
int | L |
T | Val |
T | Dummy |
Friends | |
template<typename TT > | |
ostream & | operator<< (ostream &str, const CyclicArray< TT > &ca) |
A template defining an one-dimensional cyclic array of data.
This class is very similar to the vector class from the standard template library, in that it is a random access container of objects of type T. The size() of CyclicArray, however, can exceed its capacity(). Data elements below size()-capacity() are therefore not accessible.
typedef T value_type |
The type of object, T, stored in the arry.
typedef T* pointer |
Pointer to the type of object, T, stored in the array.
typedef T& reference |
Reference to the type of object, T, stored in the array.
typedef const T& const_reference |
Const reference to the type of object, T, stored in the array.
typedef int size_type |
The type used for sizes and indices.
CyclicArray | ( | void | ) |
Creates an empty CyclicArray.
CyclicArray | ( | int | n | ) |
Creates an empty array with capacity n data elements.
References CyclicArray< T >::Buffer, CyclicArray< T >::NBuffer, and CyclicArray< T >::Own.
CyclicArray | ( | CyclicArray< T > * | ca | ) |
Creates an CyclicArray with the same size and content as ca that shares the buffer with the one of ca.
CyclicArray | ( | const CyclicArray< T > & | ca | ) |
Copy constructor. Creates an CyclicArray with the same size and content as ca.
References CyclicArray< T >::Buffer, CyclicArray< T >::capacity(), CyclicArray< T >::NBuffer, and CyclicArray< T >::Own.
|
virtual |
The destructor.
const CyclicArray< T > & operator= | ( | const CyclicArray< T > & | a | ) |
Assigns a to *this by copying the content.
const CyclicArray< T > & assign | ( | const CyclicArray< T > & | a | ) |
Assigns a to *this by copying the content.
References CyclicArray< T >::Buffer, CyclicArray< T >::capacity(), CyclicArray< T >::L, CyclicArray< T >::LCycles, CyclicArray< T >::R, CyclicArray< T >::RCycles, and CyclicArray< T >::size().
Referenced by CyclicSampleData< T >::assign().
const CyclicArray< T > & assign | ( | const CyclicArray< T > * | a | ) |
Assigns a to *this by only copying a pointer to the data.
References CyclicArray< T >::Buffer, CyclicArray< T >::L, CyclicArray< T >::LCycles, CyclicArray< T >::NBuffer, CyclicArray< T >::R, CyclicArray< T >::RCycles, and CyclicArray< T >::Val.
int size | ( | void | ) | const |
The size of the array, i.e. the total number of added data elements. Can be larger than capacity()!
Referenced by CyclicArray< T >::assign().
|
virtual |
The number of data elements that are actually stored in the array and therefore are accessible. Less or equal than capacity() and size()!
|
virtual |
The index of the first accessible data element.
Reimplemented in CyclicSampleData< T >.
Referenced by CyclicSampleData< T >::minIndex().
bool empty | ( | void | ) | const |
True if the array does not contain any data elements, i.e. size() equals zero.
|
virtual |
Resize the array to n data elements such that the size() of the array equals n. Data values are preserved and new data values are initialized with val. The capacity is not changed! If, however, the capacity() of the array is zero, then memory for n data elements is allocated and initialized with val.
Reimplemented in CyclicSampleData< T >.
Referenced by CyclicSampleData< T >::resize().
|
virtual |
Resize the array to zero length. The capacity() remains unchanged.
int capacity | ( | void | ) | const |
The capacity of the array, i.e. the number of data elements for which memory has been allocated.
Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::CyclicArray().
|
virtual |
If n is less than or equal to capacity(), this call has no effect. Otherwise, it is a request for allocation of additional memory. If the request is successful, then capacity() is greater than or equal to n and the ownership is transferred to this; otherwise, capacity() is unchanged. In either case, size() is unchanged and the content of the array is preserved.
Reimplemented in CyclicSampleData< T >.
Referenced by CyclicSampleData< T >::reserve().
void update | ( | const CyclicArray< T > * | a | ) |
Copy the data indices from a to this.
References CyclicArray< T >::R, and CyclicArray< T >::RCycles.
|
inline |
Returns a const reference to the data element at index i. No range checking is performed.
References relacs::minIndex().
|
inline |
Returns a reference to the data element at index i. No range checking is performed.
References relacs::minIndex().
const T & at | ( | int | i | ) | const |
Returns a const reference to the data element at index i. If i is an invalid index a reference to a variable set to zero is returned.
References relacs::minIndex().
T & at | ( | int | i | ) |
Returns a reference to the data element at index i. If i is an invalid index a reference to a variable set to zero is returned.
References relacs::minIndex().
const T & front | ( | void | ) | const |
Returns a const reference to the first data element. If the array is empty or the first element is not accesible a reference to a variable set to zero is returned.
References relacs::minIndex().
T & front | ( | void | ) |
Returns a reference to the first data element. If the array is empty or the first element is not accesible a reference to a variable set to zero is returned.
References relacs::minIndex().
const T & back | ( | void | ) | const |
Returns a const reference to the last data element. If the array is empty a reference to a variable set to zero is returned.
T & back | ( | void | ) |
Returns a reference to the last data element. If the array is empty a reference to a variable set to zero is returned.
|
inline |
Add val as a new element to the array.
|
inline |
Remove the last element of the array and return its value.
int maxPush | ( | void | ) | const |
Maximum number of data elements allowed to be added to the buffer at once.
void push | ( | int | n | ) |
Tell CyclicArray that n data elements have been added to pushBuffer().
|
virtual |
The number of data elements available to be read from the array.
int readIndex | ( | void | ) | const |
The index of the data element to be read next from the array.
|
inline |
Return value of the first to be read data element and increment read index.
T min | ( | int | from, |
int | upto | ||
) | const |
Return the minimum value of the array between index from inclusively and index upto exclusively.
References relacs::minIndex().
Referenced by CyclicSampleData< T >::min().
T max | ( | int | from, |
int | upto | ||
) | const |
Return the maximum value of the array between index from inclusively and index upto exclusively.
References relacs::minIndex().
Referenced by CyclicSampleData< T >::max().
void minMax | ( | T & | min, |
T & | max, | ||
int | from, | ||
int | upto | ||
) | const |
Return the minimum and maximum value, min and max, of the array between index from inclusively and index upto exclusively.
References relacs::min(), and relacs::minIndex().
Referenced by CyclicSampleData< T >::minMax().
T minAbs | ( | int | from, |
int | upto | ||
) | const |
Return the minimum absolute value of the array between index from inclusively and index upto exclusively.
References relacs::minIndex().
Referenced by CyclicSampleData< T >::minAbs().
T maxAbs | ( | int | from, |
int | upto | ||
) | const |
Return the maximum absolute value of the array between index from inclusively and index upto exclusively.
References relacs::minIndex().
Referenced by CyclicSampleData< T >::maxAbs().
numerical_traits< T >::mean_type mean | ( | int | from, |
int | upto | ||
) | const |
Return the mean value of the array between index from inclusively and index upto exclusively.
References relacs::mean(), and relacs::minIndex().
Referenced by CyclicSampleData< T >::mean().
numerical_traits< T >::variance_type variance | ( | int | from, |
int | upto | ||
) | const |
Return the variance of the array between index from inclusively and index upto exclusively.
References relacs::mean(), and relacs::minIndex().
Referenced by CyclicSampleData< T >::variance().
numerical_traits< T >::variance_type stdev | ( | int | from, |
int | upto | ||
) | const |
Return the standard deviation of the array between index from inclusively and index upto exclusively.
References relacs::mean(), relacs::minIndex(), and relacs::sqrt().
Referenced by CyclicSampleData< T >::stdev().
numerical_traits< T >::variance_type rms | ( | int | from, |
int | upto | ||
) | const |
Return the root-mean-square of the array between index from inclusively and index upto exclusively.
References relacs::minIndex(), and relacs::sqrt().
Referenced by CyclicSampleData< T >::rms().
void hist | ( | SampleData< S > & | h, |
int | from, | ||
int | upto | ||
) | const |
Compute histogram h of all data elements between index from inclusively and index upto exclusively.
References relacs::minIndex(), SampleData< T >::rangeFront(), SampleData< T >::size(), and SampleData< T >::stepsize().
Referenced by CyclicSampleData< T >::hist().
void hist | ( | SampleData< S > & | h | ) | const |
Compute histogram h of all data elements currently stored in the array.
References SampleData< T >::rangeFront(), SampleData< T >::size(), and SampleData< T >::stepsize().
const T * readBuffer | ( | int | index, |
int & | maxn | ||
) | const |
References relacs::minIndex().
int saveBinary | ( | ostream & | os, |
int | index | ||
) | const |
Save binary data to stream os starting at index index upto size().
References relacs::minIndex().
int loadBinary | ( | istream & | is, |
int | index | ||
) |
Load binary data from stream is from index index on.
|
friend |
|
protected |
true
in case this owns the buffer.
Referenced by CyclicArray< T >::CyclicArray().
|
protected |
The data buffer.
Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::CyclicArray().
|
protected |
Number of elements the data buffer can hold.
Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::CyclicArray().
|
protected |
The number of cycles the writing process ("right index") filled the buffer.
Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::update().
|
protected |
The index into the buffer where to append data.
Referenced by CyclicArray< T >::assign(), and CyclicArray< T >::update().
|
protected |
The number of cycles the reading process ("left index") filled the buffer.
Referenced by CyclicArray< T >::assign().
|
protected |
The index into the buffer where to read data.
Referenced by CyclicArray< T >::assign().
|
protected |
Value storage for pop().
Referenced by CyclicArray< T >::assign().
|
mutableprotected |
Dummy return value for invalid elements.