Class: DispatchQueue::Heap
- Inherits:
-
Object
- Object
- DispatchQueue::Heap
- Defined in:
- lib/dispatch_queue_rb/internal/heap.rb
Instance Method Summary collapse
- #count ⇒ Object (also: #size, #length)
- #elements ⇒ Object
- #empty? ⇒ Boolean
- #head ⇒ Object
-
#initialize(&compare) ⇒ Heap
constructor
A new instance of Heap.
- #pop ⇒ Object
- #push(elt) ⇒ Object
Constructor Details
#initialize(&compare) ⇒ Heap
Returns a new instance of Heap.
13 14 15 16 |
# File 'lib/dispatch_queue_rb/internal/heap.rb', line 13 def initialize( &compare ) @heap = [] @compare = compare end |
Instance Method Details
#count ⇒ Object Also known as: size, length
35 36 37 |
# File 'lib/dispatch_queue_rb/internal/heap.rb', line 35 def count @heap.count end |
#elements ⇒ Object
46 47 48 |
# File 'lib/dispatch_queue_rb/internal/heap.rb', line 46 def elements @heap end |
#empty? ⇒ Boolean
42 43 44 |
# File 'lib/dispatch_queue_rb/internal/heap.rb', line 42 def empty? @heap.empty? end |
#head ⇒ Object
31 32 33 |
# File 'lib/dispatch_queue_rb/internal/heap.rb', line 31 def head() @heap.first end |
#pop ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/dispatch_queue_rb/internal/heap.rb', line 23 def pop() head = @heap.first tail = @heap.pop() @heap[0] = tail if !@heap.empty? _sift_down( 0 ) head end |
#push(elt) ⇒ Object
18 19 20 21 |
# File 'lib/dispatch_queue_rb/internal/heap.rb', line 18 def push( elt ) @heap.push( elt ) _sift_up( @heap.count - 1 ) end |