From f747e3b530f57d8aa4db07a86f52bac7c85f6512 Mon Sep 17 00:00:00 2001 From: Rhinemann Date: Sun, 25 Jun 2023 22:33:52 +0300 Subject: [PATCH] Optimised reverse method (I have proofs of speed). --- bitutilities.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bitutilities.py b/bitutilities.py index e9aa54d..064ed3b 100644 --- a/bitutilities.py +++ b/bitutilities.py @@ -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)