lib/picky/query/combinations/memory.rb in picky-2.7.0 vs lib/picky/query/combinations/memory.rb in picky-3.0.0.pre1

- old
+ new

@@ -1,45 +1,49 @@ -module Query +module Picky - # Combinations are a number of Combination-s. - # - # They are the core of an allocation. - # An allocation consists of a number of combinations. - # - module Combinations # :nodoc:all + module Query - # Memory Combinations contain specific methods for - # calculating score and ids in memory. + # Combinations are a number of Combination-s. # - class Memory < Base + # They are the core of an allocation. + # An allocation consists of a number of combinations. + # + module Combinations # :nodoc:all - # Returns the result ids for the allocation. + # Memory Combinations contain specific methods for + # calculating score and ids in memory. # - # Sorts the ids by size and & through them in the following order (sizes): - # 0. [100_000, 400, 30, 2] - # 1. [2, 30, 400, 100_000] - # 2. (100_000 & (400 & (30 & 2))) # => result - # - # Note: Uses a C-optimized intersection routine (in performant.c) - # for speed and memory efficiency. - # - # Note: In the memory based version we ignore the (amount) needed hint. - # We cannot use the information to speed up the algorithm, unfortunately. - # - def ids _, _ - return [] if @combinations.empty? + class Memory < Base - # Get the ids for each combination. + # Returns the result ids for the allocation. # - id_arrays = @combinations.inject([]) do |total, combination| - total << combination.ids - end - - # Call the optimized C algorithm. + # Sorts the ids by size and & through them in the following order (sizes): + # 0. [100_000, 400, 30, 2] + # 1. [2, 30, 400, 100_000] + # 2. (100_000 & (400 & (30 & 2))) # => result # - # Note: It orders the passed arrays by size. + # Note: Uses a C-optimized intersection routine (in performant.c) + # for speed and memory efficiency. # - Performant::Array.memory_efficient_intersect id_arrays + # Note: In the memory based version we ignore the (amount) needed hint. + # We cannot use the information to speed up the algorithm, unfortunately. + # + def ids _, _ + return [] if @combinations.empty? + + # Get the ids for each combination. + # + id_arrays = @combinations.inject([]) do |total, combination| + total << combination.ids + end + + # Call the optimized C algorithm. + # + # Note: It orders the passed arrays by size. + # + Performant::Array.memory_efficient_intersect id_arrays + end + end end end \ No newline at end of file