PartialDifferences

This library contains functions to manage Partial Differences data structure. Partial Differences is an array of value differences over time.

For example: assuming an array [3, 6, 3, 1, 2], partial differences can represent this array as [_, 3, -3, -2, 1].

This data structure allows adding values on an open interval with O(1) complexity.

For example: add +5 to [3, 6, 3, 1, 2] starting from the second element (3), instead of performing [3, 6, 3+5, 1+5, 2+5] partial differences allows performing [_, 3, -3+5, -2, 1]. The original array can be restored by adding values from partial differences.

addToSequence addToSequence(struct PartialDifferences.Sequence sequence, uint256 diff, uint256 month) internal

subtractFromSequence subtractFromSequence(struct PartialDifferences.Sequence sequence, uint256 diff, uint256 month) internal

getAndUpdateValueInSequence getAndUpdateValueInSequence(struct PartialDifferences.Sequence sequence, uint256 month) → uint256 internal

reduceSequence reduceSequence(struct PartialDifferences.Sequence sequence, struct FractionUtils.Fraction reducingCoefficient, uint256 month) internal

addToValue addToValue(struct PartialDifferences.Value sequence, uint256 diff, uint256 month) internal

subtractFromValue subtractFromValue(struct PartialDifferences.Value sequence, uint256 diff, uint256 month) internal

getAndUpdateValue getAndUpdateValue(struct PartialDifferences.Value sequence, uint256 month) → uint256 internal

reduceValue reduceValue(struct PartialDifferences.Value sequence, uint256 amount, uint256 month) → struct FractionUtils.Fraction internal

reduceValueByCoefficient reduceValueByCoefficient(struct PartialDifferences.Value sequence, struct FractionUtils.Fraction reducingCoefficient, uint256 month) internal

reduceValueByCoefficientAndUpdateSum reduceValueByCoefficientAndUpdateSum(struct PartialDifferences.Value sequence, struct PartialDifferences.Value sumSequence, struct FractionUtils.Fraction reducingCoefficient, uint256 month) internal

reduceValueByCoefficientAndUpdateSumIfNeeded reduceValueByCoefficientAndUpdateSumIfNeeded(struct PartialDifferences.Value sequence, struct PartialDifferences.Value sumSequence, struct FractionUtils.Fraction reducingCoefficient, uint256 month, bool hasSumSequence) internal

getValueInSequence getValueInSequence(struct PartialDifferences.Sequence sequence, uint256 month) → uint256 internal

getValuesInSequence getValuesInSequence(struct PartialDifferences.Sequence sequence) → uint256[] values internal

getValue getValue(struct PartialDifferences.Value sequence, uint256 month) → uint256 internal

getValues getValues(struct PartialDifferences.Value sequence) → uint256[] values internal