diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2014-06-29 00:24:29 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2014-06-29 12:10:20 -0500 |
commit | c1dfffd07c9cad2e545a3b8a8208c50588494ced (patch) | |
tree | 7d4193c529e7cf40bbe8b855142ac223bd730f1c /wikisort.c | |
parent | ca78dc5f62fb0fea4f13ca17584a2084aaa92189 (diff) |
Add wikisort optimizations for some common cases
Diffstat (limited to 'wikisort.c')
-rw-r--r-- | wikisort.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -182,6 +182,15 @@ void wikisort(void *unsorted, size_t nmel, size_t width, cmpfun cmp) wikisort( base, nmel - b.blocks * bnmel, width, cmp); wikisort(b.base, b.blocks * bnmel, width, cmp); + /* if already sorted, nothing to do */ + if (cmp(b.base - width, b.base) <= 0) return; + + /* if blocks in b are all less than those in a, just need a rotate */ + if (cmp(base + (nmel - 1) * width, base) <= 0) { + rotate(base, nmel, width, a.blocks * bnmel + bufnmel); + return; + } + size_t nmel_pend_a = 0, nmel_pend_b = 0; char *mina = a.base, *penda; while (a.blocks) { |