16_ticket_translation.rb
# Returns array where each element is the fields that could match at that index.
Returns array where each element is the fields that could match at that index.
Returns array where each element is the fields that could match at that index .
def fields_matching_indices(valid_for_field, tickets)
  num_fields = tickets.map(&:size).uniq
  raise "inconsistent number of fields #{num_fields}" if num_fields.size != 1
  num_fields = num_fields[0]
  tickets.each_with_object(Array.new(num_fields) { valid_for_field.keys }) { |ticket, match|
    ticket.each_with_index { |v, i|
      match[i] &= valid_for_field.select { |f, rs|
        rs.any? { |r| r.cover?(v) }
      }.keys
    }
  }
end
def fields_matching_indices ( valid_for_field , tickets ) num_fields = tickets . map ( & :size ) . uniq raise "inconsistent number of fields #{num_fields}" if num_fields . size != 1 num_fields = num_fields [ 0 ] tickets . each_with_object ( Array . new ( num_fields ) { valid_for_field . keys } ) { | ticket , match | ticket . each_with_index { | v , i | match [ i ] &= valid_for_field . select { | f , rs | rs . any? { | r | r . cover? ( v ) } } . keys } } end
Returns array where each element is the fields that could match at that index.
Returns array where each element is the fields that could match at that index .
# Using Set(valid_for_field.keys) doesn't seem to make this faster, # and a bitfield is significantly harder to read and not faster enough to make it worth it. # So we'll just go with arrays.
valid_for_field
<not_specific>
tickets
<not_specific>