Class: PriorityQueue
- Inherits:
-
Object
- Object
- PriorityQueue
- Defined in:
- lib/zipf/misc.rb
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(a = Array.new) ⇒ PriorityQueue
constructor
have a numerical member named ‘score’.
- #pop ⇒ Object
- #push(i) ⇒ Object
- #sort! ⇒ Object
Constructor Details
#initialize(a = Array.new) ⇒ PriorityQueue
have a numerical member named ‘score’.
37 38 39 40 |
# File 'lib/zipf/misc.rb', line 37 def initialize a=Array.new @queue = Array.new a sort! end |
Instance Method Details
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/zipf/misc.rb', line 55 def empty? @queue.empty? end |
#pop ⇒ Object
46 47 48 |
# File 'lib/zipf/misc.rb', line 46 def pop @queue.pop end |
#push(i) ⇒ Object
50 51 52 53 |
# File 'lib/zipf/misc.rb', line 50 def push i @queue << i sort! end |
#sort! ⇒ Object
42 43 44 |
# File 'lib/zipf/misc.rb', line 42 def sort! @queue.sort_by! { |i| -i.score } end |