Skip to content

Commit 4743aca

Browse files
committed
chore: Fix failing tests
1 parent 29eb341 commit 4743aca

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Diff for: other/number_container_system.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
A number container system that uses binary search to
3-
delete and insert values into arrays with O(n logn)
2+
A number container system that uses binary search to
3+
delete and insert values into arrays with O(n logn)
44
write times and O(1) read times.
55
66
This container system holds integers at indexes.
@@ -11,7 +11,7 @@
1111

1212

1313
class NumberContainer:
14-
def __init__(self):
14+
def __init__(self) -> None:
1515
# Holds number as the key and returns list of indexes where the number is
1616
# The list of indexes is a sorted array in ascending order
1717
self.numbermap: dict[int, list[int]] = {}
@@ -42,13 +42,15 @@ def binary_search_delete(self, array: list[int], item: int) -> list[int]:
4242
low = mid + 1
4343
else:
4444
high = mid - 1
45-
raise ValueError("The item is not in the array, and therefore cannot be deleted")
45+
raise ValueError(
46+
"The item is not in the array, and therefore cannot be deleted"
47+
)
4648

4749
def binary_search_insert(self, array: list[int], index: int) -> list[int]:
4850
"""
4951
Inserts the index into the sorted array
5052
at the correct position
51-
53+
5254
>>> NumberContainer().binary_search_insert([1,2,3], 2)
5355
[1, 2, 2, 3]
5456
>>> NumberContainer().binary_search_insert([0,1,3], 2)
@@ -60,7 +62,8 @@ def binary_search_insert(self, array: list[int], index: int) -> list[int]:
6062
while low <= high:
6163
mid = (low + high) // 2
6264
if array[mid] == index:
63-
# If the item already exists in the array, insert it after the existing item
65+
# If the item already exists in the array,
66+
# insert it after the existing item
6467
array.insert(mid + 1, index)
6568
return array
6669
elif array[mid] < index:
@@ -93,7 +96,7 @@ def change(self, index: int, number: int) -> None:
9396
self.indexmap[index] = number
9497

9598
# Number not seen before or empty so insert number value
96-
if not number in self.numbermap:
99+
if number not in self.numbermap:
97100
self.numbermap[number] = [index]
98101

99102
# Here we need to perform a binary search insertion in order to insert
@@ -121,7 +124,8 @@ def find(self, number: int) -> int:
121124
"""
122125
# Simply return the 0th index (smallest) of the indexes found (or -1)
123126
return self.numbermap.get(number, [-1])[0]
124-
127+
128+
125129
if __name__ == "__main__":
126130
import doctest
127131

0 commit comments

Comments
 (0)