![]() This module was written by Nezar Abdennur and is released under the MIT license. There are also additional convenience functions that use PQDict to order objects in a dictionary. The destructive iterators are pq.iterkeys(), pq.itervalues(), and pq.iteritems(). iterkeys (): serve ( customer ) # Customer satisfaction guaranteed :) # queue is now empty keys () ĭestructive iteration methods return generators that pop items out of the heap, which amounts to performing a heapsort: for customer in queue. from pqdict import PQDict # same input signature as dict() pq = PQDict ( a = 3, b = 5, c = 8 ) pq = PQDict ( zip (, )) pq = PQDict (). ![]() Usageīy default, PQDict uses a min-heap, meaning smaller priority Indexed priority queues can be used to drive simulations, priority schedulers, and optimization algorithms, merge of streams of prioritized data, and other applications where priorities of already enqueued items may frequently change. O(log n) updating of an arbitrary element’s priority key ![]() O(1) lookup of an arbitrary element’s priority key This index is synchronized with the heap as the In addition, an internal dictionary or “index” maps elements to their O(log n) removal of the top priority element The queue is implemented as a binary heap (using a python list), which supports the standard: An indexed priority queue does these operations efficiently. A vanilla priority queue lets you insert elements with priorities, and remove or peek at the top priority element.Īn enhancement to the basic priority queue interface is to let you randomly access, insert, remove and/or alter the priority of any existing element in the queue. What is an “indexed” priority queue?Ībstract data structure that allows you to serve or retrieve items in a pqdict.PQDict instances map hashable dictionary keys to comparable priority keys and operate like regular Python dictionaries but with added priority queue functionality. Pqdict provides an indexed priority queue data structure implemented in pure Python as a dict-like class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |