MCPcopy
hub / github.com/keon/algorithms / push

Method push

algorithms/data_structures/priority_queue.py:88–101  ·  view source on GitHub ↗

Insert an item with the given priority. Args: item: The value to insert. priority: Priority value; defaults to the item itself.

(self, item: Any, priority: Any = None)

Source from the content-addressed store, hash-verified

86 return len(self.priority_queue_list)
87
88 def push(self, item: Any, priority: Any = None) -> None:
89 """Insert an item with the given priority.
90
91 Args:
92 item: The value to insert.
93 priority: Priority value; defaults to the item itself.
94 """
95 priority = item if priority is None else priority
96 node = PriorityQueueNode(item, priority)
97 for index, current in enumerate(self.priority_queue_list):
98 if current.priority < node.priority:
99 self.priority_queue_list.insert(index, node)
100 return
101 self.priority_queue_list.append(node)
102
103 def pop(self) -> Any:
104 """Remove and return the item with the lowest priority.

Callers 2

test_priority_queueMethod · 0.95
__init__Method · 0.95

Calls 2

PriorityQueueNodeClass · 0.85
insertMethod · 0.45

Tested by 1

test_priority_queueMethod · 0.76