-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_map.py
executable file
·50 lines (43 loc) · 1.26 KB
/
hash_map.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
#!/usr/bin/python
import pickle
words = pickle.load( open( "sortedWords.p", "rb" ) )
SMALL_MAP_SIZE = 63
LARGE_MAP_SIZE = 16383
# Write a cpp file for the maps and arrays
file = open("word_maps.cpp", "w")
file.write("#include \"word_maps.hpp\"\n")
# Write the small map
file.write("std::map<std::string, int> byteme::short_map = {")
i = 0
while i < SMALL_MAP_SIZE:
file.write("{\"" + words[i] + "\"," + str(i + 1) + "},")
i += 1
file.write("{\"" + words[i] + "\"," + str(i + 1) + "}};\n")
i += 1
# Write the large map
j = 0
file.write("std::map<std::string, int> byteme::long_map = {")
while j < LARGE_MAP_SIZE:
file.write("{\"" + words[i] + "\"," + str(j + 1) + "},")
i += 1
j += 1
file.write("{\"" + words[i] + "\"," + str(j + 1) + "}};\n")
# Write the small array
i = 0
short_size = (1 << 6)
file.write("const std::string byteme::short_decode_array[%d] = {" % short_size)
while i < SMALL_MAP_SIZE:
file.write("\"" + words[i] + "\",")
i += 1
file.write("\"" + words[i] + "\"};\n")
i+= 1
# Write the large array
j = 0
long_size = (1 << 14)
file.write("const std::string byteme::long_decode_array[%d] = {" % long_size)
while j < LARGE_MAP_SIZE:
file.write("\"" + words[i] + "\",")
i += 1
j += 1
file.write("\"" + words[i] + "\"};")
file.close()