Module: Kilden::Hashing Private
- Defined in:
- lib/kilden/hashing.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
The frozen rollout hashing (spec §8.3). v1 never evaluates flags locally — /decide does — but the algorithm is pinned now, tested against the platform-generated vectors, so local evaluation can arrive later without an API change or a bucketing flicker.
Constant Summary collapse
- TWO_POW_64 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
2.0**64
Class Method Summary collapse
- .bucket(flag_key, distinct_id) ⇒ Object private
- .fraction(input) ⇒ Object private
- .variant_for(flag_key, distinct_id, variants) ⇒ Object private
Class Method Details
.bucket(flag_key, distinct_id) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/kilden/hashing.rb', line 16 def bucket(flag_key, distinct_id) fraction("#{flag_key}:#{distinct_id}") * 100 end |
.fraction(input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'lib/kilden/hashing.rb', line 30 def fraction(input) Digest::SHA256.digest(input)[0, 8].unpack1("Q>") / TWO_POW_64 end |
.variant_for(flag_key, distinct_id, variants) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 25 26 27 28 |
# File 'lib/kilden/hashing.rb', line 20 def variant_for(flag_key, distinct_id, variants) point = fraction("#{flag_key}:#{distinct_id}:variant") * 100 cumulative = 0.0 variants.each do |variant| cumulative += variant.fetch("rollout_percentage") return variant.fetch("key") if point < cumulative end true end |