[Python-Dev] heapq (original) (raw)
Jeremy Fincher fincher.8@osu.edu
Sun, 20 Apr 2003 04:56:46 -0400
- Previous message: [Python-Dev] Re: heapq
- Next message: [Python-Dev] heapq
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
I must agree with Agthorr that the interface to heapq could use some work. I wrote a simple wrapper around the heapq functions to give myself a heapq object (with methods like push, pop, etc.) Here's that object:
class heap(list): slots = () def init(self, seq): list.init(self, seq) heapify(self)
def pop(self):
lastelt = list.pop(self)
if self:
returnitem = self[0]
self[0] = lastelt
_siftup(self, 0)
else:
returnitem = lastelt
return returnitem
replace = heapreplace
push = heappush
Is there any possibility of such an interface going into the heapq module? I find it much cleaner and easier to read than the "functions operating on sequences" interface heapq currently offers.
I've got unit tests for the object written, if it is something that will possibly go into the standard library.
Jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD)
iD8DBQE+omDOqkDiu+Bs+JIRAu0wAJ9xpx+7nH0fNiZzJhl34tWUbHN4HgCfZx9G 38IgV4lSY6adYyLEufWG6mk= =NVlh -----END PGP SIGNATURE-----
- Previous message: [Python-Dev] Re: heapq
- Next message: [Python-Dev] heapq
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]