Class: Rx::Util::Heap
- Inherits:
-
Object
- Object
- Rx::Util::Heap
- Defined in:
- lib/rx/util/heap.rb
Instance Method Summary collapse
- #<<(item) ⇒ Object
-
#initialize(items = [], &comparator) ⇒ Heap
constructor
A new instance of Heap.
- #peek ⇒ Object
- #pop ⇒ Object
- #push(item) ⇒ Object
Constructor Details
#initialize(items = [], &comparator) ⇒ Heap
Returns a new instance of Heap.
37 38 39 40 41 |
# File 'lib/rx/util/heap.rb', line 37 def initialize(items = [], &comparator) @heap = items.dup @comparator = block_given? ? comparator : -> (a, b) { a < b } sort! end |
Instance Method Details
#<<(item) ⇒ Object
43 44 45 |
# File 'lib/rx/util/heap.rb', line 43 def <<(item) push(item) end |
#peek ⇒ Object
47 48 49 |
# File 'lib/rx/util/heap.rb', line 47 def peek heap.first end |
#pop ⇒ Object
51 52 53 54 55 |
# File 'lib/rx/util/heap.rb', line 51 def pop item = heap.shift sort! item end |
#push(item) ⇒ Object
57 58 59 60 61 |
# File 'lib/rx/util/heap.rb', line 57 def push(item) heap << item sort! self end |