diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2014-10-26 23:33:50 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2014-10-26 23:33:50 -0500 |
commit | 40a6ba5c0a5f544bed9c11dc30b751e05a435b1e (patch) | |
tree | 796861388460ebfe3571ebc0699c3834d6eb83cf /rotate.c | |
parent | 1e3548b039bd6b760ca3fe716c98065735110f58 (diff) |
Split helper functions into their own translation units
Diffstat (limited to 'rotate.c')
-rw-r--r-- | rotate.c | 19 |
1 files changed, 19 insertions, 0 deletions
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 <stddef.h> + +#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; + } +} |