Class: Lich::Common::Map::MinHeap

Inherits:
Object
  • Object
show all
Defined in:
documented/common/map/map_dr.rb,
documented/common/map/map_gs.rb

Instance Method Summary collapse

Constructor Details

#initializeMinHeap

Returns a new instance of MinHeap.



810
811
812
# File 'documented/common/map/map_dr.rb', line 810

def initialize
  @heap = []
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


827
828
829
# File 'documented/common/map/map_dr.rb', line 827

def empty?
  @heap.empty?
end

#popObject



819
820
821
822
823
824
825
# File 'documented/common/map/map_dr.rb', line 819

def pop
  return nil if @heap.empty?
  swap(0, @heap.size - 1)
  min = @heap.pop
  bubble_down(0) unless @heap.empty?
  min
end

#push(priority, value) ⇒ Object



814
815
816
817
# File 'documented/common/map/map_dr.rb', line 814

def push(priority, value)
  @heap << [priority, value]
  bubble_up(@heap.size - 1)
end