MCPcopy Create free account
hub / github.com/douchuan/algorithm / sort_dth

Function sort_dth

src/sort/insert.rs:25–37  ·  view source on GitHub ↗

insertion sort a[lo..=hi], starting at d-th character lo & hi, is inclusive

(a: &mut [T], lo: usize, hi: usize, d: usize)

Source from the content-addressed store, hash-verified

23/// insertion sort a[lo..=hi], starting at d-th character
24/// lo & hi, is inclusive
25pub fn sort_dth<T>(a: &mut [T], lo: usize, hi: usize, d: usize)
26where
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
40fn is_less(v: &str, w: &str, d: usize) -> bool {

Callers 3

do_sortMethod · 0.85
do_sortMethod · 0.85
insert_sort_dthFunction · 0.85

Calls 1

is_lessFunction · 0.85

Tested by 1

insert_sort_dthFunction · 0.68