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’.
38 39 40 41 |
# File 'lib/zipf/misc.rb', line 38 def initialize a=Array.new @queue = Array.new a sort! end |
Instance Method Details
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/zipf/misc.rb', line 56 def empty? @queue.empty? end |
#pop ⇒ Object
47 48 49 |
# File 'lib/zipf/misc.rb', line 47 def pop @queue.pop end |
#push(i) ⇒ Object
51 52 53 54 |
# File 'lib/zipf/misc.rb', line 51 def push i @queue << i sort! end |
#sort! ⇒ Object
43 44 45 |
# File 'lib/zipf/misc.rb', line 43 def sort! @queue.sort_by! { |i| -i.score } end |