Sorting methods
le
merge_sort
- Merge sortquick_sort
- Quicksortquick_sort3
- Fancy quicksortle
type le<T> = fn(T, T) -> bool
merge_sort
fn merge_sort<T: copy>(le: le<T>, v: ~[const T]) -> ~[T]
Merge sort. Returns a new vector containing the sorted list.
Has worst case O(n log n) performance, best case O(n), but is not space efficient. This is a stable sort.
quick_sort
fn quick_sort<T: copy>(compare_func: le<T>, arr: ~[mut T])
Quicksort. Sorts a mut vector in place.
Has worst case O(n^2) performance, average case O(n log n). This is an unstable sort.
quick_sort3
fn quick_sort3<T: copy ord eq>(arr: ~[mut T])
Fancy quicksort. Sorts a mut vector in place.
Based on algorithm presented by [Sedgewick and Bentley]/~ (http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf). According to these slides this is the algorithm of choice for 'randomly ordered keys, abstract compare' & 'small number of key values'.
This is an unstable sort.