12/12/2023 0 Comments Indexed priority queue python![]() ![]() I stuck to the textbook convention, but using the sink/swim nomenclature from Sedgewick et al: the way I like to think of it, an item that is too "heavy" (low-priority) should sink down the tree, while one that is too "light" should float or swim up. * The names of the methods in heapq (sift up/down) refer to the motion of the items being compared to, rather than the item being operated on as is usually done in textbooks (i.e. As a result, PQD also supports: - O(1) lookup of an arbitrary element's priority key - O(log n) removal of an arbitrary element - O(log n) updating of an arbitrary element's priority key The standard heap operations used internally are based on those in the python heapq module (here, called "sink" and "swim").* These operations are extended to maintain the internal dictionary. This index is kept up-to-date when the heap is manipulated. The priority queue is implemented as a binary heap, which supports: - O(1) access to the top priority element - O(log n) removal of the top priority element - O(log n) insertion of a new element In addition, an internal dictionary or "index" maps elements to their position in the heap array. A dict-like heap queue to prioritize hashable objects while providing random access and updatable priorities. Inspired by the Python implementation of the heapq module, which was written by Kevin O'Connor and augmented by Tim Peters and Raymond Hettinger. """ """Priority Queue Dictionary - An indexed priority queue data structure. ![]() IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. As a result, the minimal key is keys]."""Copyright (c) 2012 Nezar Abdennur Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Given the heap pq, the elements will be compared by keys], instead of pq.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |