Return the item with the largest/smallest (depending on ``self.heap_order``) priority *without* removing it from the queue. Notes ----- In contrast to :meth:`pop`, this operation is O(1). Returns ------- item : :class:`PQNode` instan
(self)
| 146 | return item |
| 147 | |
| 148 | def peek(self): |
| 149 | """ |
| 150 | Return the item with the largest/smallest (depending on |
| 151 | ``self.heap_order``) priority *without* removing it from the queue. |
| 152 | |
| 153 | Notes |
| 154 | ----- |
| 155 | In contrast to :meth:`pop`, this operation is O(1). |
| 156 | |
| 157 | Returns |
| 158 | ------- |
| 159 | item : :class:`PQNode` instance or None |
| 160 | Item with the largest/smallest priority, depending on |
| 161 | ``self.heap_order``. |
| 162 | """ |
| 163 | item = None |
| 164 | if self._count > 0: |
| 165 | item = copy(self._pq[0].to_dict()) |
| 166 | if self.heap_order == "max": |
| 167 | item["priority"] = -1 * item["priority"] |
| 168 | return item |
| 169 | |
| 170 | |
| 171 | ####################################################################### |