Skip to content

sorted_indices and apply_permutation #200

@Morwenn

Description

@Morwenn

A couple of useful functions would be nice to have:

  • sorted_indices to get a collection of indices corresponding to a sorted permutation of the passed collection. Basically an equivalent to numpy.argsort.
  • apply_permutation to shuffle a collection according to a vector of indices, which would notably allow to apply back the result of sorted_indices to any collection. Basically an equivalent to Boost.Algorithm apply_permutation.

Both of these algorithms somewhat intervene in the implementation of indirect_adapter, so there shouldn't be any big technical difficulty from an implementation point of view.

However sorted_indices would probably better be implemented as a sorter adapter, so that it could work with any sorter and with the flexibility of sorter_facade. The biggest challenge is to modify most of the documentation to relax sorter adapter restrictions so that they don't have to produce sorters. Alternatively I can just give it the interface of a sorter adapter without mentioning it explicitly and shove it in <cpp-sort/utility> without having to make a bigger change today.

apply_permutation can surely use the Boost.Algorithm interface and live in <cpp-sort/utility> without trying to be more than that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions