9 template <
typename TInt>
12 constexpr
static int count = 10;
17 return (
i / exp) % 10;
29 return max_value / exp > 0;
39 template <
typename TInt>
42 constexpr
static int count = 16;
47 return (
i >> (exp * 4)) & 0xF;
59 if(exp == 0) {
return true; }
62 return max_value >= (1 << ((exp - 1) * 4));
72 template <
typename T,
typename TIdExtractor,
typename TInt>
76 TInt mx = TIdExtractor::get_id(arr[0]);
77 for(
const auto&
i: arr)
79 TInt val = TIdExtractor::get_id(
i);
88 template <
typename T,
typename TIdExtractor,
typename TBucket,
typename TInt>
94 int sum[TBucket::count] = {0,};
96 for(
auto arr_index = 0; arr_index < size; arr_index +=1)
98 sum[TBucket::get_index(TIdExtractor::get_id(arr[arr_index]), exp)]+=1;
101 for(
auto sum_index = 1; sum_index < TBucket::count; sum_index +=1)
103 sum[sum_index] += sum[sum_index - 1];
111 std::vector<T> ret = arr;
113 for(
auto arr_index = size - 1; arr_index >= 0; arr_index -=1)
115 auto sum_index = TBucket::get_index(TIdExtractor::get_id(arr[arr_index]), exp);
116 auto target = sum[sum_index] - 1;
117 ret[target] = arr[arr_index];
125 template <
typename T,
typename TIdExtractor,
typename TBucket,
typename TInt>
129 const TInt max_value = get_max<T, TIdExtractor, TInt>(*arr);
131 for(
int exp = TBucket::get_start(); TBucket::should_keep_looping(max_value, exp);
132 exp = TBucket::get_next_value(max_value, exp))
134 *arr = count_sort<T, TIdExtractor, TBucket, TInt>(*arr, exp);
TInt get_max(const std::vector< T > &arr)
void do_inplace_radix_sort(std::vector< T > *arr)
std::vector< T > count_sort(const std::vector< T > &arr, int exp)
int c_sizet_to_int(size_t t)
constexpr static int count
static int get_index(TInt i, int exp)
static int get_next_value(TInt, int exp)
static bool should_keep_looping(TInt max_value, int exp)
static int get_index(TInt i, int exp)
static bool should_keep_looping(TInt max_value, int exp)
constexpr static int count
static int get_next_value(TInt, int exp)