Optimised reverse method (I have proofs of speed).
This commit is contained in:
parent
f508ca51c8
commit
f747e3b530
|
@ -4,7 +4,7 @@ from collections import deque
|
|||
class BasicRegister:
|
||||
"""The BasicRegister represents a hardware register capable of manipulating multiple bits at a time.
|
||||
|
||||
:param list[bool] memory: The bits stored inside the register.
|
||||
:param deque[bool] memory: The bits stored inside the register.
|
||||
"""
|
||||
|
||||
def __init__(self, memory: list[bool]):
|
||||
|
@ -15,7 +15,8 @@ class BasicRegister:
|
|||
return f"Memory: {[int(value) for value in self.memory]}"
|
||||
|
||||
def reverse(self):
|
||||
self.memory = [not value for value in self.memory]
|
||||
for i, value in enumerate(self.memory):
|
||||
self.memory[i] = not value
|
||||
|
||||
def left_shift(self, digit_to_fill: bool = False, steps_shifted: int = 1) -> deque[bool]:
|
||||
self.memory.extend([digit_to_fill] * steps_shifted)
|
||||
|
|
Loading…
Reference in New Issue