Class: DHeap::Benchmarks::Sorting

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

Overview

Re-sorting after each insert: this both naive and performs the worst.

Instance Attribute Summary

Attributes inherited from ExamplePriorityQueue

#a

Instance Method Summary collapse

Methods inherited from ExamplePriorityQueue

#clear, #dbg, #empty?, #initialize

Constructor Details

This class inherits a constructor from DHeap::Benchmarks::ExamplePriorityQueue

Instance Method Details

#<<(score) ⇒ Object

O(n log n)

Raises:

  • (ArgumentError)


60
61
62
63
64
# File 'lib/d_heap/benchmarks/implementations.rb', line 60

def <<(score)
  raise ArgumentError unless score
  @a.push score
  @a.sort!
end

#popObject

O(1)



67
68
69
# File 'lib/d_heap/benchmarks/implementations.rb', line 67

def pop
  @a.shift
end