diff options
Diffstat (limited to 'distribute.c')
-rw-r--r-- | distribute.c | 18 |
1 files changed, 18 insertions, 0 deletions
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 <stddef.h> + +#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; + } +} |