-
Notifications
You must be signed in to change notification settings - Fork 0
/
Base.h
81 lines (61 loc) · 1.23 KB
/
Base.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef _BASE_H_
#define _BASE_H_
#include <math.h>
#include <stdio.h>
const int BSIZE = 16;
inline int getDepth(int i) {
int a=0;
int b=i-1;
while (b > 0) {b = b >> 1; a++;}
return a+1;
}
static int mylog2[1<<16];
inline int fflog2(int i) {
int res = -1;
if (i >> 16) {
res += 16;
i >>= 16;
} else i &= 0xffff;
if (i >> 8) {
res += 8;
i >>= 8;
} else i &= 0xff;
if (i >> 4) {
res += 4;
i >>= 4;
} else i &= 0xf;
for (; i; i >>= 1) res++;
return res;
}
inline int cflog2(int i) {
int res = 0;
i--;
if (i >> 16) {
res += 16;
i >>= 16;
} else i &= 0xffff;
for (; i; i >>= 1) res++;
return res;
}
inline int superfflog2(int i) {
if (i >> 16) {
return 16 + mylog2[i>>16];
} else {
return mylog2[i];
}
}
inline void initlog2() {
int i;
for (i = 0; i <= 0xffff; i++) {
int j = i, k = -1;
while (j) {j >>= 1; k++;}
mylog2[i] = k;
//if (mylog2[i] != check(i)) printf("(%d %d) ", mylog2[i], check(i));
}
//for (int i = 0; i <= 0xffff; i++) printf("(%d %d) ", mylog2[i], check(i)); printf("\n");
}
//#define max(x, y) (((x) > (y))?(x) : (y))
//#define min(x, y) (((x) < (y))?(x) : (y))
//#define max(x, y) (((x) > (y))?(x) : (y))
//#define min(x, y) (((x) < (y))?(x) : (y))
#endif