GClasses
GClasses::GRandomIndexIterator Class Reference

Detailed Description

This class iterates over all the integer values from 0 to length-1 in random order.

#include <GVec.h>

Public Member Functions

 GRandomIndexIterator (size_t length, GRand &rand)
 General-purpose constructor. This constructor does not call reset(). You should probably call reset() before you call next() for the first time. More...
 
 ~GRandomIndexIterator ()
 
size_t length ()
 Returns the length of the list of indexes. More...
 
bool next (size_t &outIndex)
 If the end of the list has been reached, returns false. Otherwise, sets outIndex to the next index, and returns true. (Note that you should call reset() before the first call to this method. The constructor does not call reset() for you.) More...
 
size_t pos ()
 Returns the current position in the list of indexes. (This might be used, for example, to identify progress.) Note that you need to subtract 1 to obtain the position of the value from the most recent call to "next". More...
 
GRandrand ()
 Returns a reference to the random number generator. More...
 
void reset ()
 Shuffles the order of the indexes, and starts the iterator over at the beginning. More...
 

Protected Attributes

size_t m_length
 
size_t * m_pCur
 
size_t * m_pEnd
 
size_t * m_pIndexes
 
GRandm_rand
 

Constructor & Destructor Documentation

GClasses::GRandomIndexIterator::GRandomIndexIterator ( size_t  length,
GRand rand 
)

General-purpose constructor. This constructor does not call reset(). You should probably call reset() before you call next() for the first time.

GClasses::GRandomIndexIterator::~GRandomIndexIterator ( )

Member Function Documentation

size_t GClasses::GRandomIndexIterator::length ( )
inline

Returns the length of the list of indexes.

bool GClasses::GRandomIndexIterator::next ( size_t &  outIndex)

If the end of the list has been reached, returns false. Otherwise, sets outIndex to the next index, and returns true. (Note that you should call reset() before the first call to this method. The constructor does not call reset() for you.)

size_t GClasses::GRandomIndexIterator::pos ( )
inline

Returns the current position in the list of indexes. (This might be used, for example, to identify progress.) Note that you need to subtract 1 to obtain the position of the value from the most recent call to "next".

GRand& GClasses::GRandomIndexIterator::rand ( )
inline

Returns a reference to the random number generator.

void GClasses::GRandomIndexIterator::reset ( )

Shuffles the order of the indexes, and starts the iterator over at the beginning.

Member Data Documentation

size_t GClasses::GRandomIndexIterator::m_length
protected
size_t* GClasses::GRandomIndexIterator::m_pCur
protected
size_t* GClasses::GRandomIndexIterator::m_pEnd
protected
size_t* GClasses::GRandomIndexIterator::m_pIndexes
protected
GRand& GClasses::GRandomIndexIterator::m_rand
protected