Method: CompSci::Heap#initialize
- Defined in:
- lib/compsci/heap.rb
#initialize(cmp_val: 1, minheap: false, child_slots: 2) ⇒ Heap
-
defaults to a MaxHeap, with the largest node at the root
-
specify a minheap with minheap: true or cmp_val: -1
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/compsci/heap.rb', line 25 def initialize(cmp_val: 1, minheap: false, child_slots: 2) super(child_slots: child_slots) cmp_val = -1 if minheap case cmp_val when -1, 1 @cmp_val = cmp_val else raise(ArgumentError, "unknown comparison value: #{cmp_val}") end end |