Re: Interest check: Boost.Algorithm.Statsort — O(n log log n) sorting
Peter Taraba via Boost <[email protected]>
| Newsgroups | gmane.comp.lib.boost.devel |
|---|---|
| Message-ID | <trinity-12d8005c-2833-4c68-bbe0-bd2a3d43d358-1773255579300@3c-app-mailcom-lxa14> |
Hi Rainer,
Great question — and a fair one. You're right that real-world code rarely sorts plain numeric vectors; sorting complex objects by a field is far more common.
I've added projection overloads to statsort that address exactly the pattern you described:
boost::algorithm::statsort(my_vector,
[](const my_complex_type& x) { return x.z; });
The projection must return an arithmetic type, which is then used as the sort key. Both the container and iterator interfaces support it:
// Container overload
boost::algorithm::statsort(my_vector,
[](const my_complex_type& x) { return x.z; });
// Iterator overload
boost::algorithm::statsort(my_vector.begin(), my_vector.end(),
[](const my_complex_type& x) { return x.z; });
The updated code is on GitHub: https://github.com/drpt78/statsort
Does this cover your use case? Happy to hear if there are other patterns I should consider.
Best,
Peter & Claude AI
https://orcid.org/0000-0002-8199-3723
Sent: Wednesday, March 11, 2026 at 5:07 AM
From: "Rainer Deyke via Boost" <[email protected]>
To: [email protected]
Cc: "Rainer Deyke" <[email protected]>
Subject: [boost] Re: Interest check: Boost.Algorithm.Statsort — O(n log log n) sorting
On 3/9/26 23:08, Peter Taraba via Boost wrote:
> Supports any std::is_arithmetic<T> type (int, float, double, etc.)
I don't think I've ever sorted a container of plain numbers in a real
program. However, I have sorted by complex objects by their numeric
attributes fairly often, i.e.:
struct my_complex_type {
std::string name;
int z;
};
std::vector<my_complex_type> my_vector;
std::sort(
my_vector.begin(),
my_vector.end(),
[](auto const &a, auto const &b) { return a.z < b.z; });
Can statsort work with this kind of object?
--
Rainer Deyke - [email protected]
_______________________________________________
Boost mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/[email protected]/message/GK2WPCZU5M7Z2LJIR4F4J2D3XLNMY4LE/
_______________________________________________
Boost mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/[email protected]/message/TIALGAIQ36JSCI4OR3M6ZDKNF3NPWDAJ/