Skip to content

An object-oriented priority queue with updatable priorities.

License

Unknown and 3 other licenses found

Licenses found

Unknown
LICENSE
BSD-3-Clause
LICENSE-BSD
GPL-3.0
LICENSE-GPL
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

elplatt/python-priorityq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

priorityq

An object-oriented priority queue with updatable priorities.

The priorityq package provides a MappedQueue class implementing an efficient minimum heap. The smallest element can be popped in O(1) time, new elements can be pushed in O(log n) time, and any element can be removed or updated in O(log n) time. The queue cannot contain duplicate elements and an attempt to push an element already in the queue will have no effect.

MappedQueue complements the heapq package from the python standard library, and has slightly different functionality. While MappedQueue is designed for maximum compatibility with heapq, it is an independent implementation. The priorityq package is free and open-source software and is released under multiple licenses (see LICENSE for more info).

Usage

A MappedQueue can be created empty or optionally given an array of initial elements. Calling push() will add an element and calling pop() will remove and return the smallest element.

>>> q = MappedQueue([916, 50, 4609, 493, 237])
>>> q.push(1310)
True
>>> x = [q.pop() for i in range(len(q.h))]
>>> x
[50, 237, 493, 916, 1310, 4609]

Elements can also be updated or removed from anywhere in the queue.

>>> q = MappedQueue([916, 50, 4609, 493, 237])
>>> q.remove(493)
>>> q.update(237, 1117)
>>> x = [q.pop() for i in range(len(q.h))]
>>> x
[50, 916, 1117, 4609]

About

An object-oriented priority queue with updatable priorities.

Resources

License

Unknown and 3 other licenses found

Licenses found

Unknown
LICENSE
BSD-3-Clause
LICENSE-BSD
GPL-3.0
LICENSE-GPL
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages