RepastHPC  2.3.1
Public Member Functions | List of all members
repast::RandomAccess< I > Class Template Reference

Given an iterator and a number of elements, creates a data structure that allows efficient access to those elements. More...

#include <Random.h>

Public Member Functions

 RandomAccess (I beginning, int size)
 Constructs a RandomAccess instance for this iterator. More...
 
get (int index)
 Gets the element at the specified index. More...
 

Detailed Description

template<typename I>
class repast::RandomAccess< I >

Given an iterator and a number of elements, creates a data structure that allows efficient access to those elements.

Is only valid as long as the iterator is valid.

The basic implementation creates a vector of ordered pairs linking an integer and an iterator pointing to an element in the original iteration set. To find the nth element, the algorithm searches backwards through the list of 'landmarks', finds the highest landmark lower than n, chooses the iterator associated with that landmark, and steps forward until n is reached, adding new landmarks if appropriate. So given landmarks:

0 - pointer to element 0 100 - pointer to element 100 200 - pointer to element 200

if the request for element 438 is given, the algorithm will search backward and find landmark 200; it will then step forward, adding landmarks for 300 and 400, until element 438 is reached and returned.

Assuming that requests are evenly distributed, optimum interval for landmarks is the square root of the size of the list, and performance for the algorithm will be in log(size) time.

Note that other implementations are possible- for example, checking if enough memory would allow a completely indexed list. A long-term possibility is allowing the user to specify (for example, specify that the algorithm with lowest memory cost be used even though memory is initially available, perhaps because other routines will be filling that memory while this object is in use).

Constructor & Destructor Documentation

◆ RandomAccess()

template<typename I >
repast::RandomAccess< I >::RandomAccess ( beginning,
int  size 
)
inline

Constructs a RandomAccess instance for this iterator.

Parameters
beginning
size

Member Function Documentation

◆ get()

template<typename I >
I repast::RandomAccess< I >::get ( int  index)
inline

Gets the element at the specified index.

Parameters
index

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