stdlib: implement qsort() as an introsort

This commit is contained in:
Alex Lyon
2018-05-13 02:51:54 -07:00
parent 0cabecd5b5
commit aa21e5fc3f
3 changed files with 233 additions and 2 deletions
+10 -1
View File
@@ -16,6 +16,8 @@ use rand::{Rng, SeedableRng, XorShiftRng};
use errno::*;
use platform::types::*;
mod sort;
#[global_allocator]
static ALLOCATOR: ralloc::Allocator = ralloc::Allocator;
@@ -388,7 +390,14 @@ pub extern "C" fn qsort(
width: size_t,
compar: Option<extern "C" fn(*const c_void, *const c_void) -> c_int>,
) {
unimplemented!()
if let Some(comp) = compar {
// XXX: check width too? not specified
if nel > 0 {
// XXX: maybe try to do mergesort/timsort first and fallback to introsort if memory
// allocation fails? not sure what is ideal
sort::introsort(base as *mut c_char, nel, width, comp);
}
}
}
#[no_mangle]