bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
functions::Odometer Class Reference

#include <Odometer.h>

Collaboration diagram for functions::Odometer:
Collaboration graph

Public Types

typedef std::vector< unsigned intshape
 

Public Member Functions

unsigned int end ()
 
void indices (shape &indices)
 
unsigned int next ()
 
unsigned int next_safe ()
 
 Odometer (shape shape)
 
unsigned int offset ()
 
void reset ()
 
unsigned int set_indices (const shape &indices)
 
unsigned int set_indices (const std::vector< int > &indices)
 

Detailed Description

Map the indices of a N-dimensional array to the offset into memory (i.e., a vector) that matches those indices. This code can be used to step through each element of an N-dim array without using multiplication to compute the offset into the vector that holds the array's data.

Note
The code does use multiplication, but only performs N-1 multiplies for a N dimensional array in set_indices() (called once) and not in next() which will likely be called many times.

reset(): zero internal state next(): move to the next element, incrementing the shape information and returning an offset into a linear vector for that element. Calling next() when the object is at the last element should return one past the last element. calling next() after that should throw an exception. vector<int> indices(): for the given state of the odometer, return the indices that match the offset. offset(): return the offset end(): should return one past the last valid offset - the value returned by next() when it indicates all elements/indices have been visited.

Definition at line 56 of file Odometer.h.

Member Typedef Documentation

◆ shape

typedef std::vector<unsigned int> functions::Odometer::shape

Definition at line 59 of file Odometer.h.

Constructor & Destructor Documentation

◆ Odometer()

functions::Odometer::Odometer ( shape shape)
inlineexplicit

Build an instance of Odometer using the given 'shape'. Each element of the shape vector is the size of the corresponding dimension. E.G., a 10 by 20 by 30 array would be described by a vector of 10,20,30.

Initially, the Odometer object is set to index 0, 0, ..., 0 that matches the offset 0

Definition at line 80 of file Odometer.h.

Member Function Documentation

◆ end()

unsigned int functions::Odometer::end ( )
inline

Return the sentinel value that indicates that the offset (returned by offset()) is at the end of the array. When offset() < end() the values of offset() and indices() are valid elements of the array being indexed. When offset() == end(), the values are no longer valid and the last array element has been visited.

Definition at line 194 of file Odometer.h.

◆ indices()

void functions::Odometer::indices ( shape & indices)
inline

Return the current set of indices. These match the current offset. Both the offset and indices are incremented by the next() method.

To access the ith index, use [i] or .at(i)

Definition at line 174 of file Odometer.h.

◆ next()

unsigned int functions::Odometer::next ( )
inline

Increment the Odometer to the next element and return the offset value. This increments the internal state and returns the offset to that element in a vector of values. Calling indices() after calling this method will return a vector<unsigned int> of the current index value.

Returns
The offset into memory for the next element. Returns a value that matches the one returned by end() when next has been called when the object index is at the last element.

Definition at line 115 of file Odometer.h.

◆ next_safe()

unsigned int functions::Odometer::next_safe ( )

Definition at line 39 of file Odometer.cc.

◆ offset()

unsigned int functions::Odometer::offset ( )
inline

The offset into memory for the current element.

Definition at line 182 of file Odometer.h.

◆ reset()

void functions::Odometer::reset ( )
inline

Reset the internal state. The offset is reset to the 0th element and the indices are reset to 0, 0, ..., 0.

Definition at line 97 of file Odometer.h.

◆ set_indices() [1/2]

unsigned int functions::Odometer::set_indices ( const shape & indices)
inline

Given a set of indices, update offset to match the position in the memory/vector they correspond to given the Odometer's initial shape.

Parameters
indicesIndices of an element
Returns
The position in linear memory of that element

Definition at line 141 of file Odometer.h.

◆ set_indices() [2/2]

unsigned int functions::Odometer::set_indices ( const std::vector< int > & indices)
inline

Definition at line 160 of file Odometer.h.


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