-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
84 lines (62 loc) · 2.54 KB
/
config.py
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
82
83
84
import sys
bsize = int(sys.argv[1])
psize = int(sys.argv[2])
lib_path = 'src/libs.rs'
util_path = 'utils/helper.cpp'
line_number_to_replace = [22, 26, 27, 29, 31, 35, 36, 51, 52, 128]
content = [
"pub const BUNIT: usize = ",
"pub const NSIZE: usize = ",
"pub const LSIZE: usize = ",
"pub const HSIZE: usize = SSIZE * ",
"pub const FRONT: u8 = ",
"pub const ISIZE: usize = ",
"pub const ISQRT: usize = ",
"pub type SQRT = ",
"pub type INDX = ",
"const size_t N_CHUNK = ",
]
with open(lib_path, 'r') as file:
lines = file.readlines()
with open(util_path, 'r') as file:
utils = file.readlines()
for i in range(len(content)):
if i == 0:
lines[line_number_to_replace[i] - 1] = content[i] + str(bsize) + "; // one block has __ chunks\n"
if i == 1:
lines[line_number_to_replace[i] - 1] = content[i] + str(pow(2, psize)) + "; // dbase size\n"
if i == 2:
lines[line_number_to_replace[i] - 1] = content[i] + str(psize // 2) + "; // logarithm sqrt\n"
if i == 3:
lines[line_number_to_replace[i] - 1] = content[i] + str(psize) + "; // hint size\n"
if i == 4:
if psize / 2 > 8:
lines[line_number_to_replace[i] - 1] = content[i] + bin(pow(2, psize // 2)-1)[:-8] + ";\n"
if psize / 2 <= 8:
lines[line_number_to_replace[i] - 1] = content[i] + bin(pow(2, psize // 2)-1) + ";\n"
if i == 5:
if psize / 2 > 8:
lines[line_number_to_replace[i] - 1] = content[i] + "0004; // one indice has __ bytes\n"
else:
lines[line_number_to_replace[i] - 1] = content[i] + "0002; // one indice has __ bytes\n"
if i == 6:
if psize / 2 > 8:
lines[line_number_to_replace[i] - 1] = content[i] + "0002; // one offset has __ bytes\n"
else:
lines[line_number_to_replace[i] - 1] = content[i] + "0001; // one offset has __ bytes\n"
if i == 7:
if psize / 2 > 8:
lines[line_number_to_replace[i] - 1] = content[i] + "u16;\n"
else:
lines[line_number_to_replace[i] - 1] = content[i] + "u8;\n"
if i == 8:
if psize / 2 > 8:
lines[line_number_to_replace[i] - 1] = content[i] + "u32;\n"
else:
lines[line_number_to_replace[i] - 1] = content[i] + "u16;\n"
if i == 9:
utils[line_number_to_replace[i] - 1] = content[i] + str(bsize * 16) + "; // script auto change this\n"
with open(lib_path, 'w') as file:
file.writelines(lines)
with open(util_path, 'w') as file:
file.writelines(utils)