Class: DHeap::Benchmarks::ExamplePriorityQueue
- Inherits:
-
Object
- Object
- DHeap::Benchmarks::ExamplePriorityQueue
- Defined in:
- lib/d_heap/benchmarks/implementations.rb
Overview
base class for example priority queues
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
Instance Method Summary collapse
- #clear ⇒ Object
- #dbg(msg) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(count = nil, &block) ⇒ ExamplePriorityQueue
constructor
quick initialization by simply sorting the array once.
Constructor Details
#initialize(count = nil, &block) ⇒ ExamplePriorityQueue
quick initialization by simply sorting the array once.
12 13 14 15 16 17 |
# File 'lib/d_heap/benchmarks/implementations.rb', line 12 def initialize(count = nil, &block) @a = [] return unless count count.times {|i| @a << block.call(i) } @a.sort! end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
9 10 11 |
# File 'lib/d_heap/benchmarks/implementations.rb', line 9 def a @a end |
Instance Method Details
#clear ⇒ Object
19 20 21 |
# File 'lib/d_heap/benchmarks/implementations.rb', line 19 def clear @a.clear end |
#dbg(msg) ⇒ Object
28 29 30 |
# File 'lib/d_heap/benchmarks/implementations.rb', line 28 def dbg(msg) puts "%20s: %p, %p" % [msg, @a.first, (@a[1..-1] || []).each_slice(2).to_a] end |
#empty? ⇒ Boolean
23 24 25 |
# File 'lib/d_heap/benchmarks/implementations.rb', line 23 def empty? @a.empty? end |