Class: DHeap::Benchmarks::Sorting
- Inherits:
-
ExamplePriorityQueue
- Object
- ExamplePriorityQueue
- DHeap::Benchmarks::Sorting
- 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
Instance Method Summary collapse
-
#<<(score) ⇒ Object
O(n log n).
-
#pop ⇒ Object
O(1).
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)
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 |
#pop ⇒ Object
O(1)
67 68 69 |
# File 'lib/d_heap/benchmarks/implementations.rb', line 67 def pop @a.shift end |