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 --- rotate.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 rotate.c (limited to 'rotate.c') diff --git a/rotate.c b/rotate.c new file mode 100644 index 0000000..5eb7696 --- /dev/null +++ b/rotate.c @@ -0,0 +1,19 @@ +#include + +#include "common.h" + +/* rotates left */ +void rotate(char *base, size_t size, size_t shift) +{ + int dir = 1; + while (shift) { + while (2*shift <= size) { + swap(base, base + dir*shift, shift); + size -= shift; + base += shift*dir; + } + shift = size - shift; + base = dir > 0 ? base + size - shift : base - shift; + dir *= -1; + } +} -- cgit v1.2.3