Boost logo

Boost :

From: David Bien (davidbien_at_[hidden])
Date: 2023-06-15 17:59:52


A couple of things.

  1. It seems you are initializing the indices of the Permutation <ret> return twice – first to 0 and then to the position in iota(). An optimization would be to first declare an empty Permutation and then reserve() the count of elements you want and then call iota().
  2. In my former codebase I had a similar indirect_sort() that accepted an input array of indices instead of generating them inside the method. This allows a “select and then indirect_sort this set of indices” which is what I generally used.
  3. (this less important but just an aside) I also implemented two other types of indirect sort in my old code base due to necessity. A “pointer to element” sort – this allows sorting on post-iterator-access elements – allowing sorting of elements stored in non-indexable iterators. Also an “offset sort” which is more or less like the pointer-to-element sort but allowed sorting of sub-fields of elements (though thinking about it now I don’t remember how I did this and I no longer have access to the code). I used the “pointer to element” sort the most of the time – the size of an 64bit index and a pointer are usually the same so no loss in terms of storage – the return is a set of sorted pointer-to-elements.
bien

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Alexander Grund via Boost<mailto:boost_at_[hidden]>
Sent: Thursday, June 15, 2023 3:04 AM
To: boost_at_[hidden]<mailto:boost_at_[hidden]>
Cc: Alexander Grund<mailto:alexander.grund_at_[hidden]>
Subject: Re: [boost] Adding 'indirect_sort' to boost::algorithm

> So you are adding a building block to have such a "cosort".
> You're just missing a way to apply that reordering to several
> (random-access) collections.

There already is: Basically you first do an indirect sort and then use
`boost::algorithm::apply_permutation` on each collection with the result
permutation.
See the test case and documentation of indirect_sort.

Alex


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk