Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ciphers/xor_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class XORCipher:
def __init__(self, key: int = 0):
def __init__(self, key: int = 0) -> None:
"""
simple constructor that receives a key or uses
default key = 0
Expand Down
2 changes: 1 addition & 1 deletion computer_vision/harris_corner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class HarrisCorner:
def __init__(self, k: float, window_size: int):
def __init__(self, k: float, window_size: int) -> None:
"""
k : is an empirically determined constant in [0.04,0.06]
window_size : neighbourhoods considered
Expand Down
6 changes: 4 additions & 2 deletions data_compression/huffman.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class Letter:
def __init__(self, letter: str, freq: int):
def __init__(self, letter: str, freq: int) -> None:
self.letter: str = letter
self.freq: int = freq
self.bitstring: dict[str, str] = {}
Expand All @@ -14,7 +14,9 @@ def __repr__(self) -> str:


class TreeNode:
def __init__(self, freq: int, left: Letter | TreeNode, right: Letter | TreeNode):
def __init__(
self, freq: int, left: Letter | TreeNode, right: Letter | TreeNode
) -> None:
self.freq: int = freq
self.left: Letter | TreeNode = left
self.right: Letter | TreeNode = right
Expand Down
2 changes: 1 addition & 1 deletion data_structures/binary_tree/segment_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class SegmentTree:
def __init__(self, a):
def __init__(self, a) -> None:
self.A = a
self.N = len(self.A)
self.st = [0] * (
Expand Down
6 changes: 3 additions & 3 deletions data_structures/binary_tree/segment_tree_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@


class SegmentTreeNode:
def __init__(self, start, end, val, left=None, right=None):
def __init__(self, start, end, val, left=None, right=None) -> None:
self.start = start
self.end = end
self.val = val
self.mid = (start + end) // 2
self.left = left
self.right = right

def __repr__(self):
def __repr__(self) -> str:
return f"SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})"


Expand Down Expand Up @@ -127,7 +127,7 @@ class SegmentTree:
>>>
"""

def __init__(self, collection: Sequence, function):
def __init__(self, collection: Sequence, function) -> None:
self.collection = collection
self.fn = function
if self.collection:
Expand Down
2 changes: 1 addition & 1 deletion data_structures/binary_tree/treap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Node:
Treap is a binary tree by value and heap by priority
"""

def __init__(self, value: int | None = None):
def __init__(self, value: int | None = None) -> None:
self.value = value
self.prior = random()
self.left: Node | None = None
Expand Down
2 changes: 1 addition & 1 deletion data_structures/hashing/double_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DoubleHash(HashTable):
Hash Table example with open addressing and Double Hash
"""

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def __hash_function_2(self, value, data):
Expand Down
2 changes: 1 addition & 1 deletion data_structures/hashing/hash_table_with_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class HashTableWithLinkedList(HashTable):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def _set_value(self, key, data):
Expand Down
2 changes: 1 addition & 1 deletion data_structures/hashing/quadratic_probing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class QuadraticProbing(HashTable):
Basic Hash Table example with open addressing using Quadratic Probing
"""

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

def _collision_resolution(self, key, data=None): # noqa: ARG002
Expand Down
6 changes: 3 additions & 3 deletions data_structures/heap/binomial_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Node:
- link to left, right and parent nodes
"""

def __init__(self, val):
def __init__(self, val) -> None:
self.val = val
# Number of nodes in left subtree
self.left_tree_size = 0
Expand Down Expand Up @@ -123,7 +123,7 @@ class BinomialHeap:
[17, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 34]
"""

def __init__(self, bottom_root=None, min_node=None, heap_size=0):
def __init__(self, bottom_root=None, min_node=None, heap_size=0) -> None:
self.size = heap_size
self.bottom_root = bottom_root
self.min_node = min_node
Expand Down Expand Up @@ -384,7 +384,7 @@ def __traversal(self, curr_node, preorder, level=0):
else:
preorder.append(("#", level))

def __str__(self):
def __str__(self) -> str:
"""
Overwriting str for a pre-order print of nodes in heap;
Performance is poor, so use only for small examples
Expand Down
4 changes: 2 additions & 2 deletions data_structures/heap/max_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BinaryHeap:
2
"""

def __init__(self):
def __init__(self) -> None:
self.__heap = [0]
self.__size = 0

Expand Down Expand Up @@ -63,7 +63,7 @@ def pop(self) -> int:
def get_list(self):
return self.__heap[1:]

def __len__(self):
def __len__(self) -> int:
"""Length of the array"""
return self.__size

Expand Down
6 changes: 3 additions & 3 deletions data_structures/heap/min_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@


class Node:
def __init__(self, name, val):
def __init__(self, name, val) -> None:
self.name = name
self.val = val

def __str__(self):
def __str__(self) -> str:
return f"{self.__class__.__name__}({self.name}, {self.val})"

def __lt__(self, other):
Expand All @@ -31,7 +31,7 @@ class MinHeap:
-17
"""

def __init__(self, array):
def __init__(self, array) -> None:
self.idx_of_element = {}
self.heap_dict = {}
self.heap = self.build_heap(array)
Expand Down
6 changes: 3 additions & 3 deletions data_structures/linked_list/deque_doubly.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class _DoublyLinkedBase:
class _Node:
__slots__ = "_data", "_next", "_prev"

def __init__(self, link_p, element, link_n):
def __init__(self, link_p, element, link_n) -> None:
self._prev = link_p
self._data = element
self._next = link_n
Expand All @@ -24,14 +24,14 @@ def has_next_and_prev(self):
f" Prev -> {self._prev is not None}, Next -> {self._next is not None}"
)

def __init__(self):
def __init__(self) -> None:
self._header = self._Node(None, None, None)
self._trailer = self._Node(None, None, None)
self._header._next = self._trailer
self._trailer._prev = self._header
self._size = 0

def __len__(self):
def __len__(self) -> int:
return self._size

def is_empty(self):
Expand Down
10 changes: 5 additions & 5 deletions data_structures/linked_list/doubly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@


class Node:
def __init__(self, data: Any):
def __init__(self, data: Any) -> None:
self.data = data
self.previous: Node | None = None
self.next: Node | None = None

def __str__(self):
def __str__(self) -> str:
return f"{self.data}"


class DoublyLinkedList:
def __init__(self):
def __init__(self) -> None:
self.head: Node | None = None
self.tail: Node | None = None

Expand All @@ -36,7 +36,7 @@ def __iter__(self):
yield node.data
node = node.next

def __str__(self):
def __str__(self) -> str:
"""
>>> linked_list = DoublyLinkedList()
>>> linked_list.insert_at_tail('a')
Expand All @@ -47,7 +47,7 @@ def __str__(self):
"""
return "->".join([str(item) for item in self])

def __len__(self):
def __len__(self) -> int:
"""
>>> linked_list = DoublyLinkedList()
>>> for i in range(0, 5):
Expand Down
6 changes: 3 additions & 3 deletions data_structures/linked_list/doubly_linked_list_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __str__(self) -> str:


class LinkedListIterator:
def __init__(self, head):
def __init__(self, head) -> None:
self.current = head

def __iter__(self):
Expand All @@ -46,15 +46,15 @@ class LinkedList:
head: Node | None = None # First node in list
tail: Node | None = None # Last node in list

def __str__(self):
def __str__(self) -> str:
current = self.head
nodes = []
while current is not None:
nodes.append(current.data)
current = current.next
return " ".join(str(node) for node in nodes)

def __contains__(self, value: DataType):
def __contains__(self, value: DataType) -> bool:
current = self.head
while current:
if current.data == value:
Expand Down
4 changes: 2 additions & 2 deletions data_structures/linked_list/from_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


class Node:
def __init__(self, data=None):
def __init__(self, data=None) -> None:
self.data = data
self.next = None

def __repr__(self):
def __repr__(self) -> str:
"""Returns a visual representation of the node and all its following nodes."""
string_rep = ""
temp = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(self, data: int) -> None:


class LinkedList:
def __init__(self):
def __init__(self) -> None:
self.head = None

def push(self, new_data: int) -> int:
Expand Down
2 changes: 1 addition & 1 deletion data_structures/linked_list/singly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __repr__(self) -> str:


class LinkedList:
def __init__(self):
def __init__(self) -> None:
"""
Create and initialize LinkedList class instance.
>>> linked_list = LinkedList()
Expand Down
4 changes: 2 additions & 2 deletions data_structures/linked_list/skip_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class Node[KT, VT]:
def __init__(self, key: KT | str = "root", value: VT | None = None):
def __init__(self, key: KT | str = "root", value: VT | None = None) -> None:
self.key = key
self.value = value
self.forward: list[Node[KT, VT]] = []
Expand Down Expand Up @@ -50,7 +50,7 @@ def level(self) -> int:


class SkipList[KT, VT]:
def __init__(self, p: float = 0.5, max_level: int = 16):
def __init__(self, p: float = 0.5, max_level: int = 16) -> None:
self.head: Node[KT, VT] = Node[KT, VT]()
self.level = 0
self.p = p
Expand Down
2 changes: 1 addition & 1 deletion data_structures/queues/circular_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class CircularQueue:
"""Circular FIFO queue with a fixed capacity"""

def __init__(self, n: int):
def __init__(self, n: int) -> None:
self.n = n
self.array = [None] * self.n
self.front = 0 # index of the first element
Expand Down
4 changes: 2 additions & 2 deletions data_structures/queues/priority_queue_using_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FixedPriorityQueue:
Priority 2: []
""" # noqa: E501

def __init__(self):
def __init__(self) -> None:
self.queues = [
[],
[],
Expand Down Expand Up @@ -146,7 +146,7 @@ class ElementPriorityQueue:
[]
"""

def __init__(self):
def __init__(self) -> None:
self.queue = []

def enqueue(self, data: int) -> None:
Expand Down
4 changes: 2 additions & 2 deletions data_structures/queues/queue_on_pseudo_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@


class Queue:
def __init__(self):
def __init__(self) -> None:
self.stack = []
self.length = 0

def __str__(self):
def __str__(self) -> str:
printed = "<" + str(self.stack)[1:-1] + ">"
return printed

Expand Down
2 changes: 1 addition & 1 deletion data_structures/stacks/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Stack[T]:
https://en.wikipedia.org/wiki/Stack_(abstract_data_type)
"""

def __init__(self, limit: int = 10):
def __init__(self, limit: int = 10) -> None:
self.stack: list[T] = []
self.limit = limit

Expand Down
2 changes: 1 addition & 1 deletion data_structures/stacks/stack_with_doubly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class Node[T]:
def __init__(self, data: T):
def __init__(self, data: T) -> None:
self.data = data # Assign data
self.next: Node[T] | None = None # Initialize next as null
self.prev: Node[T] | None = None # Initialize prev as null
Expand Down
2 changes: 1 addition & 1 deletion data_structures/stacks/stack_with_singly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class Node[T]:
def __init__(self, data: T):
def __init__(self, data: T) -> None:
self.data = data
self.next: Node[T] | None = None

Expand Down
2 changes: 1 addition & 1 deletion digital_image_processing/dithering/burkes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Burkes:
* This implementation get RGB image and converts it to greyscale in runtime.
"""

def __init__(self, input_img, threshold: int):
def __init__(self, input_img, threshold: int) -> None:
self.min_threshold = 0
# max greyscale value for #FFFFFF
self.max_threshold = int(self.get_greyscale(255, 255, 255))
Expand Down
Loading
Loading