Skip to content

Commit

Permalink
fix: remove max from allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed Jul 30, 2024
1 parent 05b5fde commit 516c89a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
6 changes: 1 addition & 5 deletions docs/model.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Evaluation Model

* Version: `2.0.0`
* Version: `2.1.1`
* Created: 2024-02-02
* Last Modified: -
* Author: Brian Giori (@bgiori)
Expand Down Expand Up @@ -133,10 +133,6 @@ An allocation defines a `max`, `range`, and the `distribution` of variants withi

```kotlin
data class EvaluationAllocation(
// The max for the allocation range. This number is used to modulo the hash
// to compare with the range.
val max: Int = 100,

// The distribution range [0, max). That is the possibles values are [0, max-1].
// E.g. with max 100, [0, 49] is 50% allocation
val range: List<Int>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import kotlinx.serialization.Serializable

@Serializable
data class EvaluationAllocation(
// The max for the allocation range. This number is used to modulo the hash
// to compare with the range.
val max: Int = 100,

// The distribution range [0, max). That is the possibles values are [0, max-1].
// E.g. with max 100, [0, 49] is 50% allocation
val range: List<Int>,

// The distribution of variants if allocated.
val distributions: List<EvaluationDistribution>
val distributions: List<EvaluationDistribution>,
)
2 changes: 1 addition & 1 deletion evaluation-core/src/commonMain/kotlin/EvaluationEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class EvaluationEngineImpl(private val log: Logger? = null) : EvaluationEngine {
val hash = getHash(keyToHash)
// Iterate over allocations. If the value falls within the range, check the distribution.
for (allocation in segment.bucket.allocations) {
val allocationValue = hash % allocation.max
val allocationValue = hash % 100
val allocationStart = allocation.range[0]
val allocationEnd = allocation.range[1]
if (allocationValue in allocationStart until allocationEnd) {
Expand Down

0 comments on commit 516c89a

Please sign in to comment.