From a05cbbdb939924ce04b7668225d486ae9609c2bb Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sat, 23 Aug 2014 21:26:20 -0500 Subject: Use binary search in merge --- grailsort.c | 7 +++---- 1 file 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); -- cgit v1.2.3