Class: FastPriorityQueue
- Inherits:
-
Object
- Object
- FastPriorityQueue
- Defined in:
- lib/fast_priority_queue.rb,
lib/fast_priority_queue/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#cmp ⇒ Object
readonly
Returns the value of attribute cmp.
Instance Method Summary collapse
- #_pop_last_element ⇒ Object
- #add(x) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ FastPriorityQueue
constructor
A new instance of FastPriorityQueue.
- #length ⇒ Object
- #pop ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize ⇒ FastPriorityQueue
Returns a new instance of FastPriorityQueue.
8 9 10 11 12 13 14 15 |
# File 'lib/fast_priority_queue.rb', line 8 def initialize @array = [nil] if block_given? @cmp = ->(a,b) { yield a,b } else @cmp = ->(a,b) { a <=> b } end end |
Instance Attribute Details
#cmp ⇒ Object (readonly)
Returns the value of attribute cmp.
6 7 8 |
# File 'lib/fast_priority_queue.rb', line 6 def cmp @cmp end |
Instance Method Details
#_pop_last_element ⇒ Object
37 38 39 40 |
# File 'lib/fast_priority_queue.rb', line 37 def _pop_last_element #TODO: find a way to do this in Rust @array.pop end |
#add(x) ⇒ Object
21 22 23 |
# File 'lib/fast_priority_queue.rb', line 21 def add(x) _add(@array,@cmp,x) end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/fast_priority_queue.rb', line 33 def empty? length == 0 end |
#length ⇒ Object
17 18 19 |
# File 'lib/fast_priority_queue.rb', line 17 def length @array.length - 1 end |
#pop ⇒ Object
29 30 31 |
# File 'lib/fast_priority_queue.rb', line 29 def pop _pop(@array,@cmp) end |
#top ⇒ Object
25 26 27 |
# File 'lib/fast_priority_queue.rb', line 25 def top @array[1] end |