Template Function brille::apply_permutation

Function Documentation

template<typename ObjItr, typename PermItr>
void brille::apply_permutation(ObjItr objects, ObjItr end, PermItr indices)

Apply a permutation to a random access iterable object.

For a permutation held in one random access iterable object of length N comprised of the integers (0,N] in some order, and a second iterable containing N objects, find the permuted iterable such that

permuted_object_iterable[i] = object_iterable[index_iterable[i]]

for all i by swapping elements in place and using the permutation iterable as a scratch workspace.

Upon completion the permutation iterable will be ordered 0:N-1.

Parameters
  • objects: An iterator pointing to the first element of the object iterable

  • end: An iterator pointing to the end of the object iterable

  • indices: An iterator pointing to the first element of the permutation iterable