|
|
@@ -1,4 +1,5 @@ |
|
|
|
class AlgoDatValue: |
|
|
|
"""A class representing a value with statistics.""" |
|
|
|
|
|
|
|
memory = 0 |
|
|
|
read = 0 |
|
|
@@ -12,7 +13,6 @@ class AlgoDatValue: |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def summary(): |
|
|
|
print("*** Summary ***") |
|
|
|
print(f"Memory: {AlgoDatValue.memory}") |
|
|
|
print(f"Read: {AlgoDatValue.read}") |
|
|
|
print(f"Write: {AlgoDatValue.write}") |
|
|
@@ -23,7 +23,6 @@ class AlgoDatValue: |
|
|
|
print(f"Div: {AlgoDatValue.div_operation}") |
|
|
|
print(f"Bit: {AlgoDatValue.bit_operation}") |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, value): |
|
|
|
AlgoDatValue.memory += 1 |
|
|
|
AlgoDatValue.write += 1 |
|
|
@@ -228,8 +227,14 @@ class AlgoDatValue: |
|
|
|
def __round__(self, n=0): |
|
|
|
return round(self.value, n) |
|
|
|
|
|
|
|
def __setattr__(self, name, value): |
|
|
|
if name == "value": |
|
|
|
AlgoDatValue.write += 1 |
|
|
|
self.__dict__[name] = value |
|
|
|
|
|
|
|
|
|
|
|
class AlgoDatArray: |
|
|
|
"""A class representing an array of AlgoDatValue objects.""" |
|
|
|
|
|
|
|
def __init__(self, size): |
|
|
|
self.size = size |
|
|
@@ -263,10 +268,49 @@ class AlgoDatArray: |
|
|
|
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: |
|
|
|
l = list(map(int, file.read().split())) |
|
|
|
a = AlgoDatArray(len(l)) |
|
|
|
for i in range(len(l)): |
|
|
|
a.set(i, AlgoDatValue(l[i])) |
|
|
|
return a |
|
|
|
return a |