Class: MapReduce::SortKey

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

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

Raises:

  • (ArgumentError)


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