MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / push

Method push

numpy_ml/utils/data_structures.py:96–125  ·  view source on GitHub ↗

Add a new (key, value) pair with priority `priority` to the queue. Notes ----- If the queue is at capacity and `priority` exceeds the priority of the item with the largest/smallest priority currently in the queue, replace the current queue item with

(self, key, priority, val=None)

Source from the content-addressed store, hash-verified

94 return iter(self._pq)
95
96 def push(self, key, priority, val=None):
97 """
98 Add a new (key, value) pair with priority `priority` to the queue.
99
100 Notes
101 -----
102 If the queue is at capacity and `priority` exceeds the priority of the
103 item with the largest/smallest priority currently in the queue, replace
104 the current queue item with (`key`, `val`).
105
106 Parameters
107 ----------
108 key : hashable object
109 The key to insert into the queue.
110 priority : comparable
111 The priority for the `key`, `val` pair.
112 val : object
113 The value associated with `key`. Default is None.
114 """
115 if self.heap_order == "max":
116 priority = -1 * priority
117
118 item = PQNode(key=key, val=val, priority=priority, entry_id=self._entry_counter)
119 heapq.heappush(self._pq, item)
120
121 self._count += 1
122 self._entry_counter += 1
123
124 while self._count > self.capacity:
125 self.pop()
126
127 def pop(self):
128 """

Callers 1

_knnMethod · 0.80

Calls 2

popMethod · 0.95
PQNodeClass · 0.85

Tested by

no test coverage detected