class MatchReduce::Index
The Index
holds all the aggregators, the reverse lookup data structure, and the ability to retrieve aggregators based on a pattern
Attributes
aggregators[R]
any[R]
lookup[R]
record[R]
Public Class Methods
new(aggregators = [], any: ANY)
click to toggle source
# File lib/match_reduce/index.rb, line 22 def initialize(aggregators = [], any: ANY) @any = any @aggregators = Aggregator.array(aggregators).uniq(&:name) @lookup = {} all_keys = @aggregators.flat_map(&:keys) @record = HashMath::Record.new(all_keys, any) @aggregators.map do |aggregator| aggregator.patterns.each do |pattern| normalized_pattern = record.make!(pattern) get(normalized_pattern) << aggregator end end freeze end
Public Instance Methods
find(pattern)
click to toggle source
# File lib/match_reduce/index.rb, line 41 def find(pattern) lookup.fetch(pattern, []) end
Private Instance Methods
get(normalized_pattern)
click to toggle source
# File lib/match_reduce/index.rb, line 49 def get(normalized_pattern) lookup[normalized_pattern] ||= Set.new end