class StableMarriage::MatchSet
Attributes
max_suitor_preferences[R]
suitees[R]
suitors[R]
Public Class Methods
new()
click to toggle source
# File lib/stable_marriage/match_set.rb, line 8 def initialize @suitors = {} @suitees = {} @max_suitor_preferences = 0 end
Public Instance Methods
add(suitor, suitee, score)
click to toggle source
# File lib/stable_marriage/match_set.rb, line 14 def add(suitor, suitee, score) suitor_prefs = add_suitor_prefs(suitor) suitee_prefs = add_suitee_prefs(suitee) suitor_prefs.sorted_insert(Preference.new(suitee, score)) if suitor_prefs.count > max_suitor_preferences @max_suitor_preferences = suitor_prefs.count end suitee_prefs.sorted_insert(Preference.new(suitor, score)) end
each_suitor_prefs(&block)
click to toggle source
# File lib/stable_marriage/match_set.rb, line 26 def each_suitor_prefs(&block) suitors.each(&block) end
most_preferred(suitee, suitors)
click to toggle source
# File lib/stable_marriage/match_set.rb, line 34 def most_preferred(suitee, suitors) suitees[suitee].detect do |preference| suitors.include?(preference.object) end.object end
suitee_preferred_at(suitor, round)
click to toggle source
# File lib/stable_marriage/match_set.rb, line 30 def suitee_preferred_at(suitor, round) suitors[suitor][round].object end
Private Instance Methods
add_suitee_prefs(object)
click to toggle source
# File lib/stable_marriage/match_set.rb, line 47 def add_suitee_prefs(object) suitees[object] ||= DescendingInsertionSortArray.new suitees[object] end
add_suitor_prefs(object)
click to toggle source
# File lib/stable_marriage/match_set.rb, line 42 def add_suitor_prefs(object) suitors[object] ||= DescendingInsertionSortArray.new suitors[object] end