|
|
|
|
|
|
|
|
class AlgoDatValue: |
|
|
class AlgoDatValue: |
|
|
|
|
|
"""A class representing a value with statistics.""" |
|
|
|
|
|
|
|
|
memory = 0 |
|
|
memory = 0 |
|
|
read = 0 |
|
|
read = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def summary(): |
|
|
def summary(): |
|
|
print("*** Summary ***") |
|
|
|
|
|
print(f"Memory: {AlgoDatValue.memory}") |
|
|
print(f"Memory: {AlgoDatValue.memory}") |
|
|
print(f"Read: {AlgoDatValue.read}") |
|
|
print(f"Read: {AlgoDatValue.read}") |
|
|
print(f"Write: {AlgoDatValue.write}") |
|
|
print(f"Write: {AlgoDatValue.write}") |
|
|
|
|
|
|
|
|
print(f"Div: {AlgoDatValue.div_operation}") |
|
|
print(f"Div: {AlgoDatValue.div_operation}") |
|
|
print(f"Bit: {AlgoDatValue.bit_operation}") |
|
|
print(f"Bit: {AlgoDatValue.bit_operation}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, value): |
|
|
def __init__(self, value): |
|
|
AlgoDatValue.memory += 1 |
|
|
AlgoDatValue.memory += 1 |
|
|
AlgoDatValue.write += 1 |
|
|
AlgoDatValue.write += 1 |
|
|
|
|
|
|
|
|
def __round__(self, n=0): |
|
|
def __round__(self, n=0): |
|
|
return round(self.value, n) |
|
|
return round(self.value, n) |
|
|
|
|
|
|
|
|
|
|
|
def __setattr__(self, name, value): |
|
|
|
|
|
if name == "value": |
|
|
|
|
|
AlgoDatValue.write += 1 |
|
|
|
|
|
self.__dict__[name] = value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AlgoDatArray: |
|
|
class AlgoDatArray: |
|
|
|
|
|
"""A class representing an array of AlgoDatValue objects.""" |
|
|
|
|
|
|
|
|
def __init__(self, size): |
|
|
def __init__(self, size): |
|
|
self.size = size |
|
|
self.size = size |
|
|
|
|
|
|
|
|
self.array[index] = value |
|
|
self.array[index] = value |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ReadIntSequence(filename): |
|
|
|
|
|
|
|
|
class MinusInf: |
|
|
|
|
|
"""A class representing negative infinity.""" |
|
|
|
|
|
|
|
|
|
|
|
def __gt__(self, other): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def __ge__(self): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def __lt__(self, other): |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def __le__(self, other): |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def __eq__(self, other): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Inf: |
|
|
|
|
|
"""A class representing positive infinity.""" |
|
|
|
|
|
|
|
|
|
|
|
def __gt__(self, other): |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def __ge__(self): |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def __lt__(self, other): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def __le__(self, other): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def __eq__(self, other): |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_int_sequence(filename: str) -> AlgoDatArray: |
|
|
|
|
|
"""Reads a sequence of integers from a file and returns an AlgoDatArray object.""" |
|
|
with open(filename, "r") as file: |
|
|
with open(filename, "r") as file: |
|
|
l = list(map(int, file.read().split())) |
|
|
l = list(map(int, file.read().split())) |
|
|
a = AlgoDatArray(len(l)) |
|
|
a = AlgoDatArray(len(l)) |
|
|
for i in range(len(l)): |
|
|
for i in range(len(l)): |
|
|
a.set(i, AlgoDatValue(l[i])) |
|
|
a.set(i, AlgoDatValue(l[i])) |
|
|
return a |
|
|
|
|
|
|
|
|
return a |