summaryrefslogtreecommitdiffstats
path: root/src/mergesort.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mergesort.c')
-rw-r--r--src/mergesort.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/mergesort.c b/src/mergesort.c
index 053e702..aa05f8e 100644
--- a/src/mergesort.c
+++ b/src/mergesort.c
@@ -23,11 +23,11 @@ int merge_sort(struct stream * const src, struct stream * const dest)
try_s((ret = stream_shallow_copy(src, dest)), err);
if (src->n > 1) {
- src->split(src, tmp, tmp + 2); /* split stream in half */
+ split(src, tmp, tmp + 2); /* split stream in half */
merge_sort(tmp, tmp + 1); /* recurse-sort first half */
merge_sort(tmp + 2, tmp + 3); /* recurse-sort second half */
merge(dest, tmp + 1, tmp + 3); /* merge the two halves back */
- dest->rewind(dest);
+ stream_rewind(dest);
/* you can't spell -funroll-loops without fun, wee~! */
stream_close(tmp);
@@ -49,17 +49,19 @@ static int merge(struct stream * const dest, struct stream * const A, struct str
int ret = 0;
struct entry_l *a;
struct entry_l *b;
+ struct entry_l a_store;
+ struct entry_l b_store;
- a = A->get(A);
- b = B->get(B);
+ a = A->get(A, &a_store);
+ b = B->get(B, &b_store);
while (a || b) {
- if (a && (!b || is_less_equal(a->val, b->val))) {
+ if (a && (!b || is_less_equal(a_store.val, b_store.val))) {
dest->put(dest, a);
- a = A->get(A);
+ a = A->get(A, &a_store);
} else {
dest->put(dest, b);
- b = B->get(B);
+ b = B->get(B, &b_store);
}
}