Sha256: 278dc8df61f3cc9f6972bd849f4a8002dbf1e24d7d6813f341cefb28d2f016f5

Contents?: true

Size: 689 Bytes

Versions: 6

Compression:

Stored size: 689 Bytes

Contents

module Picky

  module Generators

    module Weights

      # Uses a logarithmic weight.
      # If for a key k we have x ids, the weight is:
      # w(x): log(x)
      # Special case: If x < 1, then we use 0.
      #
      class Logarithmic < Strategy

        # Sets the weight value.
        #
        # If the size is 0 or one, we would get -Infinity or 0.0.
        # Thus we do not set a value if there is just one. The default, dynamically, is 0.
        #
        # BUT: We need the value, even if 0. To designate that there is a weight!
        #
        def weight_for amount
          return 0 if amount < 1
          Math.log amount
        end

      end

    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
picky-3.6.1 lib/picky/generators/weights/logarithmic.rb
picky-3.6.0 lib/picky/generators/weights/logarithmic.rb
picky-3.5.4 lib/picky/generators/weights/logarithmic.rb
picky-3.5.3 lib/picky/generators/weights/logarithmic.rb
picky-3.5.2 lib/picky/generators/weights/logarithmic.rb
picky-3.5.1 lib/picky/generators/weights/logarithmic.rb