devela/data/sort/definition.rs
1// devela::data::sort::definition
2//
3//! Defines and documents [`Sort`].
4//
5
6#[doc = crate::TAG_NAMESPACE!()]
7/// Provides sorting methods for arrays and slices of `T`, some of them *const*.
8///
9/// It implements the following methods for sorting exclusive slices:
10/// [`bubble`][Sort#bubble],
11/// [`counting`][Sort#counting],
12/// [`counting_buf`][Sort#counting_buf],
13/// [`insertion`][Sort#insertion],
14/// [`merge`][Sort#merge],
15/// [`quick_lomuto`][Sort#quick_lomuto],
16/// [`quick_hoare`][Sort#quick_hoare],
17/// [`quick_3way`][Sort#quick_3way],
18/// [`quick_selection`][Sort#quick_selection],
19/// [`quick_shaker`][Sort#quick_shaker].
20///
21/// # Features
22/// When the corresponding feature `_sort_f[32|64]` or `_sort_[iu][8|16|32|64|128]` is enabled,
23/// It implements the following *const* methods for sorting copied arrays of primitives:
24/// `bubble_array`, `insertion_array`, `selection_array`.
25/// In the case of floating-point primitives it uses total ordering.
26///
27/// # Examples
28/// Sort copied arrays of primitives:
29/// ```
30/// # use devela::Sort;
31/// # #[cfg(feature = "_sort_i32")]
32/// # {
33/// let mut arr = [4i32, 7, -5, 1, -13, 0]; // signed primitives
34/// assert_eq![Sort(arr).bubble_array(), [-13, -5, 0, 1, 4, 7]];
35/// assert_eq![Sort(arr).insertion_array(), [-13, -5, 0, 1, 4, 7]];
36/// assert_eq![Sort(arr).selection_array(), [-13, -5, 0, 1, 4, 7]];
37/// # }
38///
39/// # #[cfg(feature = "_sort_u32")]
40/// # {
41/// let mut arr = [4u32, 7, 5, 1, 13, 0]; // unsigned primitives
42/// assert_eq![Sort(arr).bubble_array(), [0, 1, 4, 5, 7, 13]];
43/// assert_eq![Sort(arr).insertion_array(), [0, 1, 4, 5, 7, 13]];
44/// assert_eq![Sort(arr).selection_array(), [0, 1, 4, 5, 7, 13]];
45/// # }
46///
47/// # #[cfg(feature = "_sort_f32")]
48/// # {
49/// let mut arr = [4.01f32, 7.9, -5.4, 1.0, 0.0, -0.0]; // floating-point primitives
50/// assert_eq![Sort(arr).bubble_array(), [-5.4, -0.0, 0.0, 1.0, 4.01, 7.9]];
51/// assert_eq![Sort(arr).insertion_array(), [-5.4, -0.0, 0.0, 1.0, 4.01, 7.9]];
52/// assert_eq![Sort(arr).selection_array(), [-5.4, -0.0, 0.0, 1.0, 4.01, 7.9]];
53/// # }
54/// ```
55///
56/// # Performance
57/// The `_array` suffixed methods calls the [`cswap`] macro using the xor swap
58/// algorithm, except for the floting-point version which uses a temporary variable.
59///
60/// [`cswap`]: crate::cswap
61#[repr(transparent)]
62pub struct Sort<T>(pub T);