diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2014-08-23 21:26:20 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2014-08-23 22:34:18 -0500 |
commit | a05cbbdb939924ce04b7668225d486ae9609c2bb (patch) | |
tree | d1206748cdd060cb37cfb84850b004d14fdb3a03 | |
parent | 77801ff0202e96fa3a22bdfbdb6a82641f3b179b (diff) |
Use binary search in merge
-rw-r--r-- | grailsort.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/grailsort.c b/grailsort.c index ac0bf20..a585b2b 100644 --- a/grailsort.c +++ b/grailsort.c @@ -20,10 +20,9 @@ void merge(char *buf, char *base, size_t anmel, size_t bnmel, size_t width, cmpf char *a = buf; char *b = base + anmel * width; - while (anmel && cmp(base, b) <= 0) { - anmel -= 1; - base += width; - } + size_t skip = binary_search(b, base, anmel, width, cmp); + anmel -= skip; + base += skip * width; swap(base, a, anmel * width); |