[英]How to update priority of an entry in a PriorityQueue?
I am using我在用
from queue import PriorityQueue
pq = PriorityQueue()
pq.put((3, "Harry"))
pq.put((4, "Harry"))
pq.put((2, "Mary"))
This now creates two entries of "Harry".这现在创建了两个“Harry”条目。 Am I supposed to remove all keys one by one (for searching) and then do a put to update the value?我是否应该一一删除所有键(用于搜索),然后执行 put 以更新值?
The python documentation for PriorityQueue
doesn't have a direct method to search a value inside Queue
objects. PriorityQueue
的python 文档没有在Queue
对象中搜索值的直接方法。
Edit: The PriorityQueue
is implemented as a binary heap so changing the priority in the elements it won't update the binary tree as Jim Mischel said:编辑: PriorityQueue
是作为二叉堆实现的,因此更改元素中的优先级不会像Jim Mischel所说的那样更新二叉树:
Changing the node's priority results in a potentially invalid heap.更改节点的优先级会导致可能无效的堆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.