Base Python script for working with ranks added
This commit is contained in:
46
get_function_len.py
Normal file
46
get_function_len.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import lzma
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def get_rank_file_object(args_count, rank_ind):
|
||||
base_name = "base_{}_rank_{}.txt".format(args_count, rank_ind)
|
||||
if os.path.exists(base_name):
|
||||
return open(base_name, 'rb')
|
||||
elif os.path.exists(base_name + ".xz"):
|
||||
return lzma.open(base_name + ".xz", 'rb')
|
||||
else:
|
||||
print("No results file for {} arguments rank {}".format(args_count, rank_ind))
|
||||
sys.exit(1)
|
||||
|
||||
def is_function_exists(function_number, file_object):
|
||||
file_object.seek(function_number // 8)
|
||||
result_byte = ord(file_object.read(1))
|
||||
return (result_byte >> (7 - function_number % 8)) % 2 == 1
|
||||
|
||||
|
||||
def function_values_to_number(values):
|
||||
assert set(values).issubset({'0','1'})
|
||||
res = 0
|
||||
for ch in values:
|
||||
res *= 2
|
||||
if ch == '1':
|
||||
res += 1
|
||||
return res
|
||||
|
||||
|
||||
def main():
|
||||
args_count = {
|
||||
8: 3,
|
||||
16: 4,
|
||||
32: 5,
|
||||
}[len(sys.argv[1])]
|
||||
function_number = function_values_to_number(sys.argv[1])
|
||||
print("Function number is {}".format(function_number))
|
||||
for rank_ind in range(1, 10):
|
||||
if is_function_exists(function_number, get_rank_file_object(args_count, rank_ind)):
|
||||
print("Result len is {}".format(rank_ind))
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user