Class: DHeap::Benchmarks::ExamplePriorityQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/d_heap/benchmarks/implementations.rb

Overview

base class for example priority queues

Direct Known Subclasses

BSearch, FindMin, RbHeap, Sorting

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aObject (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

#clearObject



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

Returns:

  • (Boolean)


23
24
25
# File 'lib/d_heap/benchmarks/implementations.rb', line 23

def empty?
  @a.empty?
end