Class: Lich::Common::Map::MinHeap
- Inherits:
-
Object
- Object
- Lich::Common::Map::MinHeap
- Defined in:
- documented/common/map/map_dr.rb,
documented/common/map/map_gs.rb
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize ⇒ MinHeap
constructor
A new instance of MinHeap.
- #pop ⇒ Object
- #push(priority, value) ⇒ Object
Constructor Details
#initialize ⇒ MinHeap
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
827 828 829 |
# File 'documented/common/map/map_dr.rb', line 827 def empty? @heap.empty? end |
#pop ⇒ Object
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 |