-
Notifications
You must be signed in to change notification settings - Fork 0
/
gray.c
53 lines (42 loc) · 831 Bytes
/
gray.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdint.h>
#include <immintrin.h>
int next_increment(uint64_t *c, int *mods, int n)
{
int k = 0;
(*c)++;
for (k = 0; k < n; k++) {
if (*c % mods[k])
break;
}
if (k == n)
return -1;
return k;
}
int next_increment_bin(uint64_t *c, int n)
{
(*c)++;
*c = *c % (1 << n);
int res = _tzcnt_u64(*c);
if (*c == 0) {
return n - 1;
} else if (res >= n) {
return -1;
}
return res;
}
//int main()
//{
// uint64_t c = 0;
// int i;
// int radices[3] = {2, 4, 3};
//
// i = next_increment(c, radices, 3);
// //i = next_increment_bin(c, 30);
// while (i != -1) {
// printf("%d\n", i);
// i = next_increment(c, radices, 3);
// // i = next_increment_bin(c, 30);
// }
//
//}