From 40a6ba5c0a5f544bed9c11dc30b751e05a435b1e Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sun, 26 Oct 2014 23:33:50 -0500 Subject: Split helper functions into their own translation units --- distribute.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 distribute.c (limited to 'distribute.c') diff --git a/distribute.c b/distribute.c new file mode 100644 index 0000000..d2d1eff --- /dev/null +++ b/distribute.c @@ -0,0 +1,18 @@ +#include + +#include "common.h" + +void distribute_buffer(char *base, size_t bufnmel, size_t sortnmel, size_t width, cmpfun cmp) +{ + while (bufnmel && sortnmel) { + char *sorted = base + bufnmel * width; + size_t insertpos = binary_search(base, sorted, sortnmel, width, cmp); + if (insertpos > 0) { + rotate(base, (bufnmel + insertpos) * width, bufnmel * width); + } + + base += (insertpos + 1) * width; + bufnmel -= 1; + sortnmel -= insertpos; + } +} -- cgit v1.2.3