This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Improve std::sort over std::array<T, N> for small values of N
- From: Morwenn Ed <morwenn29 at hotmail dot fr>
- To: Libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Sun, 2 Aug 2015 21:16:52 +0200
- Subject: Improve std::sort over std::array<T, N> for small values of N
- Authentication-results: sourceware.org; auth=none
I have developed a small library to complete std::sort. Basically, the
idea is to use specific decicated algorithms for a small number of
values when that number of values is known at compile time. You can
find the library here: https://github.com/Morwenn/cpp-sort
When given an std::array, the sort function of the library uses a specific
sorting algorithm (based on sorting networks) for the given number of
values if it has one and falls back to std::sort if it doesn't. I
believe that it could be possible to add an overload to the
implementation of std::sort which would take instances of
std::array<T, N>::iterator and use a specific sorting algorithm
for small values of N. It would incur no runtime overhead and would
allow to sort small arrays for "free" instead of using the general
purpose version of std::sort which sometimes feel overkill for the job.
Would you be interested in such an optimization for libstdc++?