diff --git a/cs/algorithms/__init__.py b/cs/algorithms/__init__.py index 7ad0cf6..fe4100b 100644 --- a/cs/algorithms/__init__.py +++ b/cs/algorithms/__init__.py @@ -34,8 +34,8 @@ "breadth_first_search", "bubble_sort", "bucket_sort", - "build_suffix_array", "build_optimal_bst", + "build_suffix_array", "connected_components", "depth_first_search", "dfs_traversal", diff --git a/cs/algorithms/string/sais.py b/cs/algorithms/string/sais.py index 37be748..1d90358 100644 --- a/cs/algorithms/string/sais.py +++ b/cs/algorithms/string/sais.py @@ -209,10 +209,8 @@ def get_suffix_annotations(text: list[int]) -> tuple[list[SuffixType], list[int] lms_suffixes: list[int] = [] suffix_marks = [SuffixType.S] * len(text) for k in range(len(text) - 1, 0, -1): - if ( - text[k - 1] > text[k] - or text[k - 1] == text[k] - and suffix_marks[k] is SuffixType.L + if text[k - 1] > text[k] or ( + text[k - 1] == text[k] and suffix_marks[k] is SuffixType.L ): suffix_marks[k - 1] = SuffixType.L if suffix_marks[k] is SuffixType.S: diff --git a/cs/structures/__init__.py b/cs/structures/__init__.py index fbf2a6d..1391f12 100644 --- a/cs/structures/__init__.py +++ b/cs/structures/__init__.py @@ -29,6 +29,7 @@ from .trie import Trie __all__ = ( + "RMQ", "ApproxDistanceOracle", "ApproxFiniteMetricOracle", "BinaryHeap", @@ -53,7 +54,6 @@ "Node", "PrecomputedRMQ", "Queue", - "RMQ", "RedBlackTree", "RedBlackTreeNode", "RobinHood", diff --git a/cs/structures/heap/fibonacci_heap.py b/cs/structures/heap/fibonacci_heap.py index d82e8e5..f6cc6d6 100644 --- a/cs/structures/heap/fibonacci_heap.py +++ b/cs/structures/heap/fibonacci_heap.py @@ -349,8 +349,7 @@ def dequeue(self) -> tuple[T, float]: # reparent operation that merged two different trees of equal # priority, we need to make sure that the min pointer points to # the root-level one. - if curr <= self.top: - self.top = curr + self.top = min(self.top, curr) if not self.allow_duplicates: del self.elem_to_entry[min_elem.value] return return_val diff --git a/cs/structures/tree/red_black_tree.py b/cs/structures/tree/red_black_tree.py index 4bb751c..3061c0b 100644 --- a/cs/structures/tree/red_black_tree.py +++ b/cs/structures/tree/red_black_tree.py @@ -134,9 +134,11 @@ def _check_coloring(node: RedBlackTreeNode[T] | None) -> bool: """ return node is None or ( node.color is Color.BLACK - or self.color(node.left) is self.color(node.right) is Color.BLACK - and _check_coloring(node.left) - and _check_coloring(node.right) + or ( + self.color(node.left) is self.color(node.right) is Color.BLACK + and _check_coloring(node.left) + and _check_coloring(node.right) + ) ) def _black_height(node: RedBlackTreeNode[T] | None) -> int: diff --git a/explore/rmq.py b/explore/rmq.py index c01398a..2640717 100644 --- a/explore/rmq.py +++ b/explore/rmq.py @@ -20,7 +20,7 @@ def construct_rmq(rmq_type: str, data: list[int]) -> RMQ: def print_arr_with_index(data: list[int], low: int) -> str: result = f"\nIndex | Data\n{'-' * 15}\n" for i, value in enumerate(data): - result += f"{low+i if low else i:5d} | {value}\n" + result += f"{low + i if low else i:5d} | {value}\n" return result @@ -71,7 +71,7 @@ def run_tests(minimum: int, maximum: int, num_builds: int, num_queries: int) -> assert data[ours] == data[theirs], ( "Error: query produced the wrong answer:\n\n" f"Query: Low: {low}, High: {high}\n" - f"{print_arr_with_index(data[low: high], low)}\n" + f"{print_arr_with_index(data[low:high], low)}\n" f"Solution Index: {ours}, Your Index: {theirs}\n\n" f"Val at index {ours}: {data[ours]}, " f"Val at index {theirs}: {data[theirs]}" diff --git a/utils/ruff_ignore.py b/utils/ruff_ignore.py index 2a7eea8..b2b3e8f 100644 --- a/utils/ruff_ignore.py +++ b/utils/ruff_ignore.py @@ -23,7 +23,7 @@ def main() -> None: error_messages[error_code] = error_message for error_code, error_message in sorted(error_messages.items()): spaces = 8 - len(error_code) - print(f'"{error_code}",{' ' * spaces}# {error_message}') + print(f'"{error_code}",{" " * spaces}# {error_message}') def extract_details(ruff_error_line: str) -> tuple[Path, int, int, str]: