class WeighedDistribution::InterimWeightsSumsTable

@!visibility private

Constants

Entry
  • interim_weights_sum (Numeric) - sum of weights of this {Entry} and all previous {Entry}es.

  • value (Object)

Public Class Methods

new(values_and_weights) click to toggle source

@param [Array<(Object, Numeric)>] values_and_weights

# File lib/weighed_distribution.rb, line 121
def initialize(values_and_weights)
  interim_weights_sum = 0
  @entries = values_and_weights.map do |value, weight|
    interim_weights_sum += weight
    Entry.new(value, interim_weights_sum)
  end
end

Public Instance Methods

[](index) click to toggle source

@param [Integer] index @return [Entry, nil] {Entry} if index < {#size} and nil otherwise.

If index < 0 then resultant {Entry#interim_weights_sum} = 0.
# File lib/weighed_distribution.rb, line 132
def [](index)
  if index < 0 then
    Entry.new([], 0)
  else
    @entries[index]
  end
end
last_index() click to toggle source

@return [Integer]

# File lib/weighed_distribution.rb, line 141
def last_index
  size - 1
end
size() click to toggle source

@return [Integer]

# File lib/weighed_distribution.rb, line 146
def size
  @entries.size
end