Skip to content

Commit a318f8d

Browse files
committed
description
1 parent 0285cb2 commit a318f8d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

libcxx/include/__algorithm/radix_sort.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010
#ifndef _LIBCPP___ALGORITHM_RADIX_SORT_H
1111
#define _LIBCPP___ALGORITHM_RADIX_SORT_H
1212

13+
// This is an implementation of classic LSD radix sort algorithm, running in linear time and using `O(max(N, M))`
14+
// additional memory, where `N` is size of an input range, `M` — maximum value of
15+
// a radix of the sorted integer type. Type of the radix and its maximum value are determined at compile time
16+
// based on type returned by function `__radix`. The default radix is uint8.
17+
18+
// The algorithm is equivalent to several consecutive calls of counting sort for each
19+
// radix of the sorted numbers from low to high byte.
20+
// The algorithm uses a temporary buffer of size equal to size of the input range. Each `i`-th pass
21+
// of the algorithm sorts values by `i`-th radix and moves values to the temporary buffer (for each even `i`, counted
22+
// from zero), or moves them back to the initial range (for each odd `i`). It there is only one radix in sorted integers
23+
// (e.g. int8), than sorted values are placed to the buffer, and then moved back to the initial range.
24+
25+
// The implementation also has several optimizations:
26+
// - the counters for the counting sort are calculated in one pass for all radices;
27+
// - if all values of a radix are the same, we do not sort that radix, and just move items to the buffer;
28+
// - if two consecutive radices satisfies condition above, we do nothing for these two radices.
29+
1330
#include <__algorithm/copy.h>
1431
#include <__algorithm/for_each.h>
1532
#include <__bit/countl.h>

0 commit comments

Comments
 (0)