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 Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows From: Alexander Grund via Boostmailto:boost@lists.boost.org Sent: Thursday, June 15, 2023 3:04 AM To: boost@lists.boost.orgmailto:boost@lists.boost.org Cc: Alexander Grundmailto:alexander.grund@tu-dresden.de 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