class IO::Event::PriorityHeap
def bubble_up(index)
def bubble_up(index) parent_index = (index - 1) / 2 # watch out, integer division! while index > 0 && @contents[index] < @contents[parent_index] # if the node has a smaller value than its parent, swap these nodes # to uphold the minheap invariant and update the index of the 'current' # node. If the node is already at index 0, we can also stop because that # is the root of the heap. # swap(index, parent_index) @contents[index], @contents[parent_index] = @contents[parent_index], @contents[index] index = parent_index parent_index = (index - 1) / 2 # watch out, integer division! end end