mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
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:
parent
69457357e8
commit
6f21f76696
2
.github/workflows/pre-commit.yml
vendored
2
.github/workflows/pre-commit.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
|||||||
~/.cache/pip
|
~/.cache/pip
|
||||||
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
|
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v2
|
||||||
- uses: psf/black@20.8b1
|
- uses: psf/black@21.4b0
|
||||||
- name: Install pre-commit
|
- name: Install pre-commit
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
|
@ -13,17 +13,17 @@ repos:
|
|||||||
)$
|
)$
|
||||||
- id: requirements-txt-fixer
|
- id: requirements-txt-fixer
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 20.8b1
|
rev: 21.4b0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
- repo: https://github.com/PyCQA/isort
|
- repo: https://github.com/PyCQA/isort
|
||||||
rev: 5.7.0
|
rev: 5.8.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
args:
|
args:
|
||||||
- --profile=black
|
- --profile=black
|
||||||
- repo: https://gitlab.com/pycqa/flake8
|
- repo: https://gitlab.com/pycqa/flake8
|
||||||
rev: 3.9.0
|
rev: 3.9.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
args:
|
args:
|
||||||
|
@ -150,7 +150,7 @@ class BinarySearchTree:
|
|||||||
self.inorder(arr, node.right)
|
self.inorder(arr, node.right)
|
||||||
|
|
||||||
def find_kth_smallest(self, k: int, node: Node) -> int:
|
def find_kth_smallest(self, k: int, node: Node) -> int:
|
||||||
"""Return the kth smallest element in a binary search tree """
|
"""Return the kth smallest element in a binary search tree"""
|
||||||
arr = []
|
arr = []
|
||||||
self.inorder(arr, node) # append all values to list using inorder traversal
|
self.inorder(arr, node) # append all values to list using inorder traversal
|
||||||
return arr[k - 1]
|
return arr[k - 1]
|
||||||
|
@ -32,7 +32,7 @@ class Heap:
|
|||||||
return str(self.h)
|
return str(self.h)
|
||||||
|
|
||||||
def parent_index(self, child_idx: int) -> Optional[int]:
|
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:
|
if child_idx > 0:
|
||||||
return (child_idx - 1) // 2
|
return (child_idx - 1) // 2
|
||||||
return None
|
return None
|
||||||
@ -78,7 +78,7 @@ class Heap:
|
|||||||
self.max_heapify(violation)
|
self.max_heapify(violation)
|
||||||
|
|
||||||
def build_max_heap(self, collection: Iterable[float]) -> None:
|
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.h = list(collection)
|
||||||
self.heap_size = len(self.h)
|
self.heap_size = len(self.h)
|
||||||
if self.heap_size > 1:
|
if self.heap_size > 1:
|
||||||
@ -87,14 +87,14 @@ class Heap:
|
|||||||
self.max_heapify(i)
|
self.max_heapify(i)
|
||||||
|
|
||||||
def max(self) -> float:
|
def max(self) -> float:
|
||||||
""" return the max in the heap """
|
"""return the max in the heap"""
|
||||||
if self.heap_size >= 1:
|
if self.heap_size >= 1:
|
||||||
return self.h[0]
|
return self.h[0]
|
||||||
else:
|
else:
|
||||||
raise Exception("Empty heap")
|
raise Exception("Empty heap")
|
||||||
|
|
||||||
def extract_max(self) -> float:
|
def extract_max(self) -> float:
|
||||||
""" get and remove max from heap """
|
"""get and remove max from heap"""
|
||||||
if self.heap_size >= 2:
|
if self.heap_size >= 2:
|
||||||
me = self.h[0]
|
me = self.h[0]
|
||||||
self.h[0] = self.h.pop(-1)
|
self.h[0] = self.h.pop(-1)
|
||||||
@ -108,7 +108,7 @@ class Heap:
|
|||||||
raise Exception("Empty heap")
|
raise Exception("Empty heap")
|
||||||
|
|
||||||
def insert(self, value: float) -> None:
|
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)
|
self.h.append(value)
|
||||||
idx = (self.heap_size - 1) // 2
|
idx = (self.heap_size - 1) // 2
|
||||||
self.heap_size += 1
|
self.heap_size += 1
|
||||||
|
@ -21,7 +21,7 @@ class BinaryHeap:
|
|||||||
self.__size = 0
|
self.__size = 0
|
||||||
|
|
||||||
def __swap_up(self, i: int) -> None:
|
def __swap_up(self, i: int) -> None:
|
||||||
""" Swap the element up """
|
"""Swap the element up"""
|
||||||
temporary = self.__heap[i]
|
temporary = self.__heap[i]
|
||||||
while i // 2 > 0:
|
while i // 2 > 0:
|
||||||
if self.__heap[i] > self.__heap[i // 2]:
|
if self.__heap[i] > self.__heap[i // 2]:
|
||||||
@ -30,13 +30,13 @@ class BinaryHeap:
|
|||||||
i //= 2
|
i //= 2
|
||||||
|
|
||||||
def insert(self, value: int) -> None:
|
def insert(self, value: int) -> None:
|
||||||
""" Insert new element """
|
"""Insert new element"""
|
||||||
self.__heap.append(value)
|
self.__heap.append(value)
|
||||||
self.__size += 1
|
self.__size += 1
|
||||||
self.__swap_up(self.__size)
|
self.__swap_up(self.__size)
|
||||||
|
|
||||||
def __swap_down(self, i: int) -> None:
|
def __swap_down(self, i: int) -> None:
|
||||||
""" Swap the element down """
|
"""Swap the element down"""
|
||||||
while self.__size >= 2 * i:
|
while self.__size >= 2 * i:
|
||||||
if 2 * i + 1 > self.__size:
|
if 2 * i + 1 > self.__size:
|
||||||
bigger_child = 2 * i
|
bigger_child = 2 * i
|
||||||
@ -52,7 +52,7 @@ class BinaryHeap:
|
|||||||
i = bigger_child
|
i = bigger_child
|
||||||
|
|
||||||
def pop(self) -> int:
|
def pop(self) -> int:
|
||||||
""" Pop the root element """
|
"""Pop the root element"""
|
||||||
max_value = self.__heap[1]
|
max_value = self.__heap[1]
|
||||||
self.__heap[1] = self.__heap[self.__size]
|
self.__heap[1] = self.__heap[self.__size]
|
||||||
self.__size -= 1
|
self.__size -= 1
|
||||||
@ -65,7 +65,7 @@ class BinaryHeap:
|
|||||||
return self.__heap[1:]
|
return self.__heap[1:]
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
""" Length of the array """
|
"""Length of the array"""
|
||||||
return self.__size
|
return self.__size
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ Operations:
|
|||||||
|
|
||||||
|
|
||||||
class _DoublyLinkedBase:
|
class _DoublyLinkedBase:
|
||||||
""" A Private class (to be inherited) """
|
"""A Private class (to be inherited)"""
|
||||||
|
|
||||||
class _Node:
|
class _Node:
|
||||||
__slots__ = "_prev", "_data", "_next"
|
__slots__ = "_prev", "_data", "_next"
|
||||||
|
@ -22,28 +22,28 @@ class Stack:
|
|||||||
return str(self.stack)
|
return str(self.stack)
|
||||||
|
|
||||||
def push(self, data):
|
def push(self, data):
|
||||||
""" Push an element to the top of the stack."""
|
"""Push an element to the top of the stack."""
|
||||||
if len(self.stack) >= self.limit:
|
if len(self.stack) >= self.limit:
|
||||||
raise StackOverflowError
|
raise StackOverflowError
|
||||||
self.stack.append(data)
|
self.stack.append(data)
|
||||||
|
|
||||||
def pop(self):
|
def pop(self):
|
||||||
""" Pop an element off of the top of the stack."""
|
"""Pop an element off of the top of the stack."""
|
||||||
return self.stack.pop()
|
return self.stack.pop()
|
||||||
|
|
||||||
def peek(self):
|
def peek(self):
|
||||||
""" Peek at the top-most element of the stack."""
|
"""Peek at the top-most element of the stack."""
|
||||||
return self.stack[-1]
|
return self.stack[-1]
|
||||||
|
|
||||||
def is_empty(self) -> bool:
|
def is_empty(self) -> bool:
|
||||||
""" Check if a stack is empty."""
|
"""Check if a stack is empty."""
|
||||||
return not bool(self.stack)
|
return not bool(self.stack)
|
||||||
|
|
||||||
def is_full(self) -> bool:
|
def is_full(self) -> bool:
|
||||||
return self.size() == self.limit
|
return self.size() == self.limit
|
||||||
|
|
||||||
def size(self) -> int:
|
def size(self) -> int:
|
||||||
""" Return the size of the stack."""
|
"""Return the size of the stack."""
|
||||||
return len(self.stack)
|
return len(self.stack)
|
||||||
|
|
||||||
def __contains__(self, item) -> bool:
|
def __contains__(self, item) -> bool:
|
||||||
|
@ -19,7 +19,7 @@ def make_sepia(img, factor: int):
|
|||||||
return 0.2126 * red + 0.587 * green + 0.114 * blue
|
return 0.2126 * red + 0.587 * green + 0.114 * blue
|
||||||
|
|
||||||
def normalize(value):
|
def normalize(value):
|
||||||
""" Helper function to normalize R/G/B value -> return 255 if value > 255"""
|
"""Helper function to normalize R/G/B value -> return 255 if value > 255"""
|
||||||
return min(value, 255)
|
return min(value, 255)
|
||||||
|
|
||||||
for i in range(pixel_h):
|
for i in range(pixel_h):
|
||||||
|
@ -94,7 +94,6 @@ def not32(i):
|
|||||||
|
|
||||||
|
|
||||||
def sum32(a, b):
|
def sum32(a, b):
|
||||||
""""""
|
|
||||||
return (a + b) % 2 ** 32
|
return (a + b) % 2 ** 32
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ def valid_input(
|
|||||||
|
|
||||||
# Main Function
|
# Main Function
|
||||||
def main():
|
def main():
|
||||||
""" This function starts execution phase """
|
"""This function starts execution phase"""
|
||||||
while True:
|
while True:
|
||||||
print(" Linear Discriminant Analysis ".center(50, "*"))
|
print(" Linear Discriminant Analysis ".center(50, "*"))
|
||||||
print("*" * 50, "\n")
|
print("*" * 50, "\n")
|
||||||
|
@ -88,7 +88,7 @@ def run_linear_regression(data_x, data_y):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" Driver function """
|
"""Driver function"""
|
||||||
data = collect_dataset()
|
data = collect_dataset()
|
||||||
|
|
||||||
len_data = data.shape[0]
|
len_data = data.shape[0]
|
||||||
|
@ -7,7 +7,7 @@ class Dice:
|
|||||||
NUM_SIDES = 6
|
NUM_SIDES = 6
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Initialize a six sided dice """
|
"""Initialize a six sided dice"""
|
||||||
self.sides = list(range(1, Dice.NUM_SIDES + 1))
|
self.sides = list(range(1, Dice.NUM_SIDES + 1))
|
||||||
|
|
||||||
def roll(self):
|
def roll(self):
|
||||||
|
@ -4,7 +4,7 @@ from collections import deque
|
|||||||
|
|
||||||
|
|
||||||
class LRUCache:
|
class LRUCache:
|
||||||
""" Page Replacement Algorithm, Least Recently Used (LRU) Caching."""
|
"""Page Replacement Algorithm, Least Recently Used (LRU) Caching."""
|
||||||
|
|
||||||
dq_store = object() # Cache store of keys
|
dq_store = object() # Cache store of keys
|
||||||
key_reference_map = object() # References of the keys in cache
|
key_reference_map = object() # References of the keys in cache
|
||||||
|
Loading…
Reference in New Issue
Block a user