473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Safely move an element into a heap

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:
>>heap = [0,3,6,8,10]
heapq.move_to_first_position(heap, 4)
heap = [10, 0,3,6,8]

--- Giampaolo
http://code.google.com/p/pyftpdlib/
Sep 4 '08 #1
3 1211
I'm not sure what you expect as an answer, but if you mean the heap as
in the data structure, you can not just arbitrarily move one key where
you want as it will destroy the heap property.
Giampaolo Rodola' wrote:
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:
>>heap = [0,3,6,8,10]
>>heapq.move_to_first_position(heap, 4)
>>heap = [10, 0,3,6,8]


--- Giampaolo
http://code.google.com/p/pyftpdlib/
--
http://mail.python.org/mailman/listinfo/python-list

Sep 4 '08 #2
On 4 Set, 13:49, Alexandru Palade <alexandru.pal...@sellerengine.com>
wrote:
I'm not sure what you expect as an answer, but if you mean the heap as
in the data structure, you can not just arbitrarily move one key where
you want as it will destroy the heap property.

Giampaolo Rodola' wrote:
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:
*>>heap = [0,3,6,8,10]
*>>heapq.move_to_first_position(heap, 4)
*>>heap = [10, 0,3,6,8]
--- Giampaolo
http://code.google.com/p/pyftpdlib/
--
http://mail.python.org/mailman/listinfo/python-list- Nascondi testo citato

- Mostra testo citato -
Could I be able to do that if every element I want to move will have
the value of 0 which is the smallest value I can have into my heap?
What I'm trying to do is implementing a timeout: sometimes I want a
given event which was scheduled to happen within X seconds to happen
immediately.
--- Giampaolo
http://code.google.com/p/pyftpdlib/
Sep 4 '08 #3
On Sep 4, 6:57*am, "Giampaolo Rodola'" <gne...@gmail.comwrote:
On 4 Set, 13:49, Alexandru Palade <alexandru.pal...@sellerengine.com>
wrote:
I'm not sure what you expect as an answer, but if you mean the heap as
in the data structure, you can not just arbitrarily move one key where
you want as it will destroy the heap property.
Giampaolo Rodola' wrote:
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:
*>>heap = [0,3,6,8,10]
*>>heapq.move_to_first_position(heap, 4)
*>>heap = [10, 0,3,6,8]
--- Giampaolo
>http://code.google.com/p/pyftpdlib/
--
>http://mail.python.org/mailman/listi...-list-Nascondi testo citato
- Mostra testo citato -

Could I be able to do that if every element I want to move will have
the value of 0 which is the smallest value I can have into my heap?
What I'm trying to do is implementing a timeout: sometimes I want a
given event which was scheduled to happen within X seconds to happen
immediately.

--- Giampaolohttp://code.google.com/p/pyftpdlib/
Change its timeout to -1 and reheapify. Or maintain 'zeroes' in a
separate structure.
Sep 4 '08 #4

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

Similar topics

11
by: Richard Thompson | last post by:
I've got a memory overwrite problem, and it looks as if a vector has been moved, even though I haven't inserted or deleted any elements in it. Is this possible? In other words, are there any...
2
by: Samuel Barber | last post by:
Consider a struct that resembles this: struct mystruct { byte myarray; // ...other stuff... } i.e. a struct that contains at least one reference/pointer.
3
by: Mike Spertus | last post by:
Is there a way to get an approximate stackpointer into an int in C#? The following works, but is unsafe and adds a new variable to the stackframe: int i = (int)(&i); It seems like it should...
6
by: viki | last post by:
I have vector 'vec' of integers which was made into valid heap using std::make_heap(). Then we change value of a single element vec, like: vec = new_value; Now this makes vec not a valid...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.