summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench.c2
-rw-r--r--common.h1
-rw-r--r--grailsort.c4
-rw-r--r--testcases.c7
-rw-r--r--testcases.h2
5 files changed, 10 insertions, 6 deletions
diff --git a/bench.c b/bench.c
index a5da95f..1317adf 100644
--- a/bench.c
+++ b/bench.c
@@ -44,7 +44,7 @@ int main()
printf("%*lu %*lu ", CMP_WIDTH, counts[CURRENT].compare, MS_WIDTH, timediff_ms(&start, &stop));
print_counts();
- assert_sorted(size, t->cmp);
+ assert_sorted((void*)buffer, size, sizeof(int), t->cmp);
}
printf(" %*zu\n", SIZE_WIDTH, size);
}
diff --git a/common.h b/common.h
index fcdfe3d..7734a77 100644
--- a/common.h
+++ b/common.h
@@ -7,6 +7,7 @@
typedef int (*cmpfun)(const void *, const void *);
typedef void (*sorterfn)(void *, size_t, size_t, cmpfun);
+void assert_sorted(char *, size_t, size_t, cmpfun);
size_t binary_search(const char *, char *, size_t, size_t, cmpfun);
void distribute_buffer(char *, size_t, size_t, size_t, cmpfun);
void swap(char *, char *, size_t);
diff --git a/grailsort.c b/grailsort.c
index 9eff4d6..a39a0b2 100644
--- a/grailsort.c
+++ b/grailsort.c
@@ -96,4 +96,8 @@ void grailsort(void *unsorted, size_t nmel, size_t width, cmpfun cmp)
grailsort(base, bufnmel, width, cmp);
distribute_buffer(base, bufnmel, nmel - bufnmel, width, cmp);
+
+#if 0
+ assert_sorted(base, nmel, width, cmp);
+#endif
}
diff --git a/testcases.c b/testcases.c
index a41cd89..6526d1e 100644
--- a/testcases.c
+++ b/testcases.c
@@ -8,10 +8,11 @@
int buffer[MAX_SIZE];
-void assert_sorted(size_t size, cmpfun cmp)
+void assert_sorted(char *base, size_t nmel, size_t width, cmpfun cmp)
{
- for (size_t i = 1; i < size; i++) {
- if (cmp(buffer + i-1, buffer + i) > 0) abort();
+ for (size_t i = 1; i < nmel; i++) {
+ if (cmp(base, base+width) > 0) abort();
+ base += width;
}
}
diff --git a/testcases.h b/testcases.h
index acb409b..9e1702a 100644
--- a/testcases.h
+++ b/testcases.h
@@ -7,8 +7,6 @@
extern int buffer[MAX_SIZE];
-void assert_sorted(size_t size, cmpfun cmp);
-
typedef void (*testinit)(size_t);
extern const struct testcase {