29 #ifndef SOLIDUTILS_SORT_HPP 30 #define SOLIDUTILS_SORT_HPP 56 template<
typename K,
typename I>
61 static_assert(std::is_integral<K>::value,
"Must by integral type.");
62 static_assert(std::is_integral<I>::value,
"Must by integral type.");
64 std::vector<size_t> counts(num+1,0);
68 for (
size_t i = 0; i < num; ++i) {
74 std::unique_ptr<I[]> out(
new I[num]);
76 for (
size_t i = 0; i < num; ++i) {
77 out[counts[keys[i]]++] = i;
94 template<
typename K,
typename I,
typename URBG>
100 static_assert(std::is_integral<K>::value,
"Must by integral type.");
101 static_assert(std::is_integral<I>::value,
"Must by integral type.");
103 std::vector<size_t> counts(num+1,0);
107 for (
size_t i = 0; i < num; ++i) {
113 std::unique_ptr<I[]> out(
new I[num]);
115 for (
size_t i = 0; i < num; ++i) {
116 out[counts[keys[i]]++] = i;
121 for (
size_t i = 0; start < num; ++i) {
static std::unique_ptr< I[]> fixedKeys(K const *const keys, size_t const num)
Generate a permutation for a given set of keys. The range of the keys must be limited to [0...
Definition: Sort.hpp:57
static void pseudoShuffle(T *const data, size_t const num, URBG &&rng) noexcept
Re-order the elements in array in a randomly. This is less random than std::shuffle, but is significantly faster for large arrays.
Definition: Random.hpp:143
static std::unique_ptr< I[]> fixedKeysRandom(K const *const keys, size_t const num, URBG &&rng)
Generate a permutation for a given set of keys. The range of the keys must be limited to [0...
Definition: Sort.hpp:95
static void prefixSumExclusive(T *const data, size_t const size) noexcept
Perform a prefix sum on an array.
Definition: VectorMath.hpp:105