diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2014-06-29 12:45:30 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2014-06-29 12:45:30 -0500 |
commit | 111c49dac18a92523c0516da006049ab8a63df3d (patch) | |
tree | 1eb98ed4fd754063db20b4ae0723228cbc547b57 | |
parent | 0de853d851d68c57689c44812447d20b83ab5caa (diff) |
Don't roll a b block if it doesn't make sense to
This added a pathological case where each iteration we'd roll a b block
into place, just to have to do a giant rotate to move all the accumulated
b blocks over to make room for the a block that should have been inserted
next.
-rw-r--r-- | wikisort.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -96,18 +96,14 @@ static size_t roll(struct blockarray *a, struct blockarray *b, size_t bwidth, size_t width, char **mina, cmpfun cmp) { size_t iters = 0; - char *prevb; - - do { + while (b->blocks && cmp(b->base , *mina + bwidth - width) < 0) { swap(a->base, b->base, bwidth); if (*mina == a->base) *mina = b->base; - prevb = a->base; a->base += bwidth; b->base += bwidth; b->blocks--; iters++; - } while (b->blocks && cmp(prevb + bwidth - width, *mina) < 0); - + } return iters; } |