insertion sort a[lo..=hi], starting at d-th character lo & hi, is inclusive
(a: &mut [T], lo: usize, hi: usize, d: usize)
| 23 | /// insertion sort a[lo..=hi], starting at d-th character |
| 24 | /// lo & hi, is inclusive |
| 25 | pub fn sort_dth<T>(a: &mut [T], lo: usize, hi: usize, d: usize) |
| 26 | where |
| 27 | T: AsRef<str>, |
| 28 | { |
| 29 | // i begin with `lo + 1` |
| 30 | for i in lo + 1..=hi { |
| 31 | let mut j = i; |
| 32 | while j > lo && is_less(a[j].as_ref(), a[j - 1].as_ref(), d) { |
| 33 | a.swap(j, j - 1); |
| 34 | j -= 1; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /// is v less than w, starting at d-th character |
| 40 | fn is_less(v: &str, w: &str, d: usize) -> bool { |