Code example bug in Heap page

June 1, 2011
3:02 a.m.
Hello, I thing there is a bug in the heapq page (http://docs.python.org/library/heapq.html) under the 8.4.2. Priority Queue Implementation Notes Secction. In the code example defines this function def get_top_priority(): while True: priority, count, task = heappop(pq) del task_finder[task] if count is not INVALID: return task I thing the delete must be inside the if statment, because if you have reprioritize task, with lower priority than before, it will delete from task_finder, but the a task will still be in pq heap. Example: add_task(2, 'a') add_task(1,'b') reprioritize(3, 'a') get_top_priority() #print b get_top_priority() #rise Error, but shoud print b Thanks!
5040
Age (days ago)
5040
Last active (days ago)
0 comments
1 participants
participants (1)
-
Nicolas Gleichgerrcht