Class: PriorityQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/zipf/misc.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


55
56
57
# File 'lib/zipf/misc.rb', line 55

def empty?
  @queue.empty?
end

#popObject



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