MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __init__

Method __init__

data_structures/heap/heap_generic.py:10–19  ·  view source on GitHub ↗
(self, key: Callable | None = None)

Source from the content-addressed store, hash-verified

8 """
9
10 def __init__(self, key: Callable | None = None) -> None:
11 # Stores actual heap items.
12 self.arr: list = []
13 # Stores indexes of each item for supporting updates and deletion.
14 self.pos_map: dict = {}
15 # Stores current size of heap.
16 self.size = 0
17 # Stores function used to evaluate the score of an item on which basis ordering
18 # will be done.
19 self.key = key or (lambda x: x)
20
21 def _parent(self, i: int) -> int | None:
22 """Returns parent index of given index if exists else None"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected