Classes | Public Member Functions | Protected Attributes
morphio::LoadUnordered< M > Class Template Reference

#include <collection.h>

Classes

class  Iterator
 

Public Member Functions

 LoadUnordered (std::shared_ptr< LoadUnorderedImpl > load_unordered_impl)
 
Iterator begin () const
 
Iterator end () const
 

Protected Attributes

std::shared_ptr< LoadUnorderedImpl > _load_unordered_impl
 

Detailed Description

template<class M>
class morphio::LoadUnordered< M >

An iterable of loop index and morphologies.

When reading from containers, the order in which morphologies are read can have a large impact on the overall time to load those morphologies.

This iterator provides means of reordering loops to optimize the access pattern. Loops such as the following

for(size_t k = 0; k < morphology_names.size; ++k) {
  auto morph = collection.load<M>(morphology_names[k]);
  f(k, morph);
}

can be replaced with

for(auto [k, morph] : collection.load_unordered<M>(morphology_names)) {
  assert(collection.load<M>(morphology_names[k]) == morph);
  f(k, morph);
}

The order in which the morphologies are returned in unspecified, but the loop index k can be used to retrieve the correct state corresponding to iteration k of the original loop.

Note, that it is safe for an LoadUnordered object to outlive its collection. Internally a shallow copy of the original collection is stored inside of and kept alive for the life time of the LoadUnordered object.

Note: This API is 'experimental', meaning it might change in the future.