Safely move an element into a heap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Giampaolo Rodola'

    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

  • Alexandru Palade

    #2
    Re: Safely move an element into a heap

    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

    --

    >
    >

    Comment

    • Giampaolo Rodola'

      #3
      Re: Safely move an element into a heap

      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]
      >>
      - 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

      Comment

      • castironpi

        #4
        Re: Safely move an element into a heap

        On Sep 4, 6:57 am, "Giampaolo Rodola'" <gne...@gmail.c omwrote:
        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]
        >>
        - 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.

        Comment

        Working...