Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
/ heapq2 Public archive

extension to Python standard library heapq package

License

Notifications You must be signed in to change notification settings

diffeo/heapq2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

heapq2

Python standard library list.sort() takes an comparison function argument, so heapq should too.

These functions have been extended to take a cmp_lt(a,b) function which returns True if a is less than b:

  • heappush(), heappop(), heapreplace(), heappushpop(), heapify(), nlargest(), nsmallest(), merge()

The default cmp_lt functions as before, using a.lt(b) if available, or falling back to (b >= a).

An 'index=0' argument has been added to heappop() and heapreplace() so that an element other than the head of the heap-queue can be popped.

Other guidance on the Python standard library heapq routines suggested wrapping objects in a tuple with the sort key in the first element and the value in the second, or using a wrapper object that defined lt(), but in maintaining a queue of many millions of elements the object overhead gets problematic and replacing all those wrapper objects with one comparison function is efficient.

About

extension to Python standard library heapq package

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages