Sha256: a07bee55db3edd7f51c60cf5668f46828bc8ddf6d4c3f66183cebfb7160c199a
Contents?: true
Size: 1017 Bytes
Versions: 14
Compression:
Stored size: 1017 Bytes
Contents
class Hash def fast_sort_keys keys = self.keys.sort Hash[keys.zip(self.values_at(*keys))] end # TODO write fast sort values def populate_with_keys(min: nil, max: nil, explicit_default_value: 0) start_key = min || self.keys.min end_key = max || self.keys.max result = self.dup (start_key..end_key).each do |k| result[k] = self[k] || explicit_default_value end return result end # def collapse_values_on_modulo(integer, min: nil, max: nil, shift: nil) # raise ArgumentError.new("Modulo integer had better be larger than shift") if integer <= shift.to_i # # result = Hash.new(0) # hash = self.dup.populate_with_keys(min: min, max: max) # hash = hash.reject{|k, v| k < min.to_i} # hash = hash.reject{|k, v| k > max if max.present?} # # hash.each do |k, v| # if k%integer == shift.to_i # result[k] = (k..(k + integer - 1)).map{|i| hash[i].to_i }.sum # end # end # # return result.fast_sort_keys # end end
Version data entries
14 entries across 14 versions & 1 rubygems