* and (long)i is equal to the linear index of the corresponding
* state of indexVars, where the variables in indexVars that are
* not in forVars assume their zero'th value.
- * \idea Optimize all indices as follows: keep a cache of all (or only
- * relatively small) indices that have been computed (use a hash). Then,
+ * \idea Optimize all indices as follows: keep a cache of all (or only
+ * relatively small) indices that have been computed (use a hash). Then,
* instead of computing on the fly, use the precomputed ones.
*/
class IndexFor {
/// For each variable in forVars, the current state
std::vector<size_t> _count;
-
+
/// For each variable in forVars, its number of possible values
std::vector<size_t> _dims;
public:
/// Default constructor
- IndexFor() {
- _index = -1;
+ IndexFor() {
+ _index = -1;
}
/// Constructor
}
/// Conversion to long
- operator long () const {
- return( _index );
+ operator long () const {
+ return( _index );
}
/// Pre-increment operator
i++;
}
- if( i == _count.size() )
+ if( i == _count.size() )
_index = -1;
}
return( *this );
MultiFor( const std::vector<size_t> &d ) : _dims(d), _states(d.size(),0), _state(0) {}
/// Return linear state
- operator size_t() const {
+ operator size_t() const {
assert( valid() );
return( _state );
}
Permute( const std::vector<size_t> &d, const std::vector<size_t> &sigma ) : _dims(d), _sigma(sigma) {
assert( _dims.size() == _sigma.size() );
}
-
+
/// Construct from vector of variables
Permute( const std::vector<Var> &vars ) : _dims(vars.size()), _sigma(vars.size()) {
VarSet vs( vars.begin(), vars.end(), vars.size() );
/// Calculates a permuted linear index.
/** Converts the linear index li to a vector index
- * corresponding with the dimensions in _dims, permutes it according to sigma,
+ * corresponding with the dimensions in _dims, permutes it according to sigma,
* and converts it back to a linear index according to the permuted dimensions.
*/
size_t convert_linear_index( size_t li ) const {
long state;
states_type states;
-
+
public:
/// Default constructor
State() : state(0), states() {}
}
/// Return linear state
- operator size_t() const {
+ operator size_t() const {
assert( valid() );
return( state );
}
for( VarSet::const_iterator v = vs.begin(); v != vs.end(); v++ ) {
states_type::const_iterator entry = states.find( *v );
if( entry != states.end() )
- vs_state += entry->second * prod;
+ vs_state += entry->second * prod;
prod *= v->states();
}
return vs_state;
state = -1;
}
}
-
+
/// Postfix increment operator
void operator++( int ) {
- operator++();
+ operator++();
}
/// Returns true if the current state is valid