fix(ci): Update pre-commit hooks and apply new black (#4359)

* fix(ci): Update pre-commit hooks and apply new black

* remove empty docstring
This commit is contained in:
Dhruv Manilawala
2021-04-26 11:16:50 +05:30
committed by GitHub
parent 69457357e8
commit 6f21f76696
13 changed files with 26 additions and 27 deletions

View File

@ -32,7 +32,7 @@ class Heap:
return str(self.h)
def parent_index(self, child_idx: int) -> Optional[int]:
""" return the parent index of given child """
"""return the parent index of given child"""
if child_idx > 0:
return (child_idx - 1) // 2
return None
@ -78,7 +78,7 @@ class Heap:
self.max_heapify(violation)
def build_max_heap(self, collection: Iterable[float]) -> None:
""" build max heap from an unsorted array"""
"""build max heap from an unsorted array"""
self.h = list(collection)
self.heap_size = len(self.h)
if self.heap_size > 1:
@ -87,14 +87,14 @@ class Heap:
self.max_heapify(i)
def max(self) -> float:
""" return the max in the heap """
"""return the max in the heap"""
if self.heap_size >= 1:
return self.h[0]
else:
raise Exception("Empty heap")
def extract_max(self) -> float:
""" get and remove max from heap """
"""get and remove max from heap"""
if self.heap_size >= 2:
me = self.h[0]
self.h[0] = self.h.pop(-1)
@ -108,7 +108,7 @@ class Heap:
raise Exception("Empty heap")
def insert(self, value: float) -> None:
""" insert a new value into the max heap """
"""insert a new value into the max heap"""
self.h.append(value)
idx = (self.heap_size - 1) // 2
self.heap_size += 1

View File

@ -21,7 +21,7 @@ class BinaryHeap:
self.__size = 0
def __swap_up(self, i: int) -> None:
""" Swap the element up """
"""Swap the element up"""
temporary = self.__heap[i]
while i // 2 > 0:
if self.__heap[i] > self.__heap[i // 2]:
@ -30,13 +30,13 @@ class BinaryHeap:
i //= 2
def insert(self, value: int) -> None:
""" Insert new element """
"""Insert new element"""
self.__heap.append(value)
self.__size += 1
self.__swap_up(self.__size)
def __swap_down(self, i: int) -> None:
""" Swap the element down """
"""Swap the element down"""
while self.__size >= 2 * i:
if 2 * i + 1 > self.__size:
bigger_child = 2 * i
@ -52,7 +52,7 @@ class BinaryHeap:
i = bigger_child
def pop(self) -> int:
""" Pop the root element """
"""Pop the root element"""
max_value = self.__heap[1]
self.__heap[1] = self.__heap[self.__size]
self.__size -= 1
@ -65,7 +65,7 @@ class BinaryHeap:
return self.__heap[1:]
def __len__(self):
""" Length of the array """
"""Length of the array"""
return self.__size