blob: 1815812e5ed55745b2d91d1b6295b2c71b4680d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <stddef.h>
#include "common.h"
#include "counts.h"
/* rotates left */
void rotate(char *base, size_t size, size_t shift)
{
int dir = 1;
counts[CURRENT].rotate++;
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;
}
}
|