#include <dai/index.h>
Public Member Functions | |
IndexFor () | |
Default constructor. | |
IndexFor (const VarSet &indexVars, const VarSet &forVars) | |
Construct IndexFor object from indexVars and forVars. | |
IndexFor & | reset () |
Resets the state. | |
operator size_t () const | |
Conversion to size_t: returns linear index of the current state of indexVars. | |
IndexFor & | operator++ () |
Increments the current state of forVars (prefix). | |
void | operator++ (int) |
Increments the current state of forVars (postfix). | |
bool | valid () const |
Returns true if the current state is valid. | |
Private Attributes | |
long | _index |
The current linear index corresponding to the state of indexVars. | |
std::vector< long > | _sum |
For each variable in forVars, the amount of change in _index. | |
std::vector< size_t > | _state |
For each variable in forVars, the current state. | |
std::vector< size_t > | _ranges |
For each variable in forVars, its number of possible values. |
The class IndexFor is an important tool for indexing Factor entries. Its usage can best be explained by an example. Assume indexVars, forVars are both VarSet 's. Then the following code:
IndexFor i( indexVars, forVars ); size_t iter = 0; for( ; i.valid(); i++, iter++ ) { cout << "State of forVars: " << calcState( forVars, iter ) << "; "; cout << "state of indexVars: " << calcState( indexVars, size_t(i) ) << endl; }
(size_t)i
equals the linear index of the corresponding state of indexVars, where the variables in indexVars that are not in forVars assume their zero'th value. dai::IndexFor::IndexFor | ( | ) | [inline] |
Default constructor.
Construct IndexFor object from indexVars and forVars.
IndexFor& dai::IndexFor::reset | ( | ) | [inline] |
Resets the state.
dai::IndexFor::operator size_t | ( | ) | const [inline] |
Conversion to size_t:
returns linear index of the current state of indexVars.
IndexFor& dai::IndexFor::operator++ | ( | ) | [inline] |
Increments the current state of forVars (prefix).
void dai::IndexFor::operator++ | ( | int | ) | [inline] |
Increments the current state of forVars (postfix).
bool dai::IndexFor::valid | ( | ) | const [inline] |
Returns true
if the current state is valid.
long dai::IndexFor::_index [private] |
The current linear index corresponding to the state of indexVars.
std::vector<long> dai::IndexFor::_sum [private] |
For each variable in forVars, the amount of change in _index.
std::vector<size_t> dai::IndexFor::_state [private] |
For each variable in forVars, the current state.
std::vector<size_t> dai::IndexFor::_ranges [private] |
For each variable in forVars, its number of possible values.