lib/picky/query/combinations.rb in picky-0.9.3 vs lib/picky/query/combinations.rb in picky-0.9.4

- old
+ new

@@ -1,36 +1,34 @@ module Query # Combinations are a number of Combination-s. # - # They are, in effect, the core of an allocation. + # They are the core of an allocation. # class Combinations - attr_reader :type, :combinations + attr_reader :combinations delegate :empty?, :to => :@combinations - def initialize type, combinations = [] - @type = type # TODO Remove. + def initialize combinations = [] @combinations = combinations end def hash @combinations.hash end # Uses user specific weights to calculate a score for the combinations. # def calculate_score weights - @score ||= sum_score - @score + add_score(weights) # TODO Ok to just cache the weights? + total_score + weighted_score(weights) end - def sum_score + def total_score @combinations.sum &:weight end - def add_score weights + def weighted_score weights weights.score @combinations end # Gets all ids for the allocations. # @@ -56,23 +54,21 @@ # # TODO Move into the memory_efficient_intersect such that # this precondition for a fast algorithm is always given. # id_arrays.sort! { |this_array, that_array| this_array.size <=> that_array.size } - + # Call the optimized C algorithm. # Performant::Array.memory_efficient_intersect id_arrays end - + + # Wrap the combinations into an allocation with the result_type # - # - def pack_into_allocation - allocation = Allocation.new self - allocation.result_type = @type.result_type # TODO Rewrite. - allocation + def pack_into_allocation result_type + Allocation.new self, result_type end - + # Filters the tokens and identifiers such that only identifiers # that are passed in, remain, including their tokens. # # Note: This method is not totally independent of the calculate_ids one. # Since identifiers are only nullified, we need to not include the \ No newline at end of file