473,472 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Heap class for heapq module

Hi!

I filed a patch for a Heap class to be integrated into the heapq module (in
addition the the currently available functions). The main features are support
for iteration and for the standard keyword arguments of sort() and sorted():
key, cmp, reverse.

http://sourceforge.net/tracker/index...70&atid=305470

I wrote it because I believe that it makes the API of that module much simpler
for beginners and more consistent for general purpose use. Currently, it has a
set of special purpose list functions that must be used in the right way to
achieve what is needed. The main problems with these functions are:

1) They don't support heap iteration. This is contrary to the obvious paradigm
shift Python did in the last years. Iteration is considered difficult to
integrate into the current module as the list that the functions operate on is
open to modification between heapq calls. A Heap class eliminates this
problem. It can provide iteration in a consistent way, both for destructive
iteration as for clone iteration.

2) They don't support sort arguments. They only support min heaps. Usage as
max heaps needs special treatment of the list items, such as a wrapper class.
I suspect such a class to be part of every Python programmer's personal tool
box, which already makes a good case for better support in the stdlib. Also,
beginners often do not have such a wrapper class and have to figure out how to
write it or search for it (and must know what they have to search for). Again,
a Heap class can easily support the standard keyword arguments as it wraps the
heap list.

I hope for integration of the Heap class in the stdlib heap module, but I'd
also like to hear a fruitful discussion on this list to get the patch ready
for integration. I know, it currently misses documentation and tests, but I'm
ready to add them once the patch is actually considered for integration.

Stefan
Jul 18 '05 #1
0 1411

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not...
17
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
1
by: nrhayyal | last post by:
hi all, i am working on C++ on AIX machine. i am running one of my module which is built using 10+ user built libraries. i am getting St9bad_alloc exception. i came to know that this exception...
3
by: toton | last post by:
Operator overloading has a sort syntax rather than member function call for stack based memory allocation. like complex<int> c1,c2,c3; c3= c1+c2; How the same can be applied to heap based...
7
by: 7stud | last post by:
My book says that in a heap, a value at position i will be smaller than the values at positions 2*i and 2*i + 1. To test that, I ran this program: ---------- from heapq import * from random...
1
by: Davy | last post by:
Hi all, I have a dictionary with n elements, and I want to get the m(m<=n) keys with the largest values. For example, I have dic that includes n=4 elements, I want m=2 keys have the largest...
4
by: Giampaolo Rodola' | last post by:
Hi, I'm trying to implement an asynchronous scheduler for asyncore to call functions at a later time without blocking the main loop. The logic behind it consists in: - adding the scheduled...
3
by: Giampaolo Rodola' | last post by:
Hi, I wanted to know if does exist a safe way to, given a heap, move an arbitrary element to the first position of the heap. Something like: --- Giampaolo...
14
by: AlarV | last post by:
Hello everyone, here is my problem. I have to make a dynamic priority queue,which is a heap, and my book isn't helpful at all, so I have no clues on how to create it.. I read something like a static...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.