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

Method sort

src/strings/quick3.rs:54–64  ·  view source on GitHub ↗

Rearranges the array of strings in ascending order.

(a: &mut [T])

Source from the content-addressed store, hash-verified

52{
53 /// Rearranges the array of strings in ascending order.
54 pub fn sort(a: &mut [T]) {
55 // Randomization.
56 // As with any quicksort, it is generally worthwhile to
57 // shuffle the array beforehand or to use a random paritioning
58 // item by swapping the first item with a random one. The primary
59 // reason to do so is to protect against worst-case performance
60 // in the case that the array is already sorted or nearly sorted.
61 common::util::shuffle(a);
62 let n = a.len();
63 Self::do_sort(a, 0, n.saturating_sub(1), 0);
64 }
65
66 /// 3-way string quicksort a[lo..hi] starting at d-th character
67 fn do_sort(a: &mut [T], lo: usize, hi: usize, d: usize) {

Callers

nothing calls this directly

Calls 3

shuffleFunction · 0.85
do_sortFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected