Class: MapReduce::SortKey
- Inherits:
-
Object
- Object
- MapReduce::SortKey
- Includes:
- Comparable
- Defined in:
- lib/map_reduce/priority_queue.rb
Overview
Since LazyPriorityQueue is using <= and >=, but not <=>, it does not support sorting array keys. Therefore we wrap the keys in SortKey, which provides those operators. See bugs.ruby-lang.org/issues/5574
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(object) ⇒ SortKey
constructor
A new instance of SortKey.
Constructor Details
#initialize(object) ⇒ SortKey
Returns a new instance of SortKey.
11 12 13 |
# File 'lib/map_reduce/priority_queue.rb', line 11 def initialize(object) @object = object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
9 10 11 |
# File 'lib/map_reduce/priority_queue.rb', line 9 def object @object end |
Instance Method Details
#<=>(other) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/map_reduce/priority_queue.rb', line 15 def <=>(other) res = object <=> other.object raise(ArgumentError, "Unable to compare #{@object.inspect} with #{other.object.inspect}") if res.nil? res end |