1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! Utility functions for Radix Sort operations.
//!
//! This module provides helper functions for common operations used throughout
//! the Radix Sort implementation.
/// Calculates the number of bytes needed to represent a value.
///
/// # Arguments
///
/// * `value` - The value to measure
///
/// # Returns
///
/// The number of bytes required
/// Checks if a slice is already sorted.
///
/// # Arguments
///
/// * `slice` - The slice to check
///
/// # Returns
///
/// `true` if sorted in ascending order, `false` otherwise
///
/// # Examples
///
/// ```rust
/// use universal_radix_sort::utils::is_sorted;
///
/// assert!(is_sorted(&[1, 2, 3, 4, 5]));
/// assert!(!is_sorted(&[1, 3, 2, 4, 5]));
/// ```
/// Checks if a slice is sorted in descending order.
///
/// # Arguments
///
/// * `slice` - The slice to check
///
/// # Returns
///
/// `true` if sorted in descending order, `false` otherwise
/// Reverses a slice in-place.
///
/// # Arguments
///
/// * `slice` - The slice to reverse
///
/// # Examples
///
/// ```rust
/// use universal_radix_sort::utils::reverse_slice;
///
/// let mut data = vec![1, 2, 3, 4, 5];
/// reverse_slice(&mut data);
/// assert_eq!(data, vec![5, 4, 3, 2, 1]);
/// ```
/// Estimates the break-even point where Radix Sort becomes faster than QuickSort.
///
/// # Arguments
///
/// * `element_size` - Size of each element in bytes
///
/// # Returns
///
/// Estimated minimum collection size for Radix Sort to be beneficial
///
/// # Note
///
/// This is a rough estimate. Actual performance depends on many factors including
/// CPU cache, memory bandwidth, and data distribution.