Skip to content

Commit 8658b99

Browse files
committed
minimize diff
1 parent 9e21868 commit 8658b99

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/models/feature_snapshot.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
use std::io::Cursor;
15-
16-
use murmur3::murmur3_32;
1714

1815
use crate::entity::Entity;
1916
use crate::metering::{MeteringRecorderSender, MeteringSubject};
@@ -24,6 +21,10 @@ use crate::segment_evaluation::TargetingRules;
2421

2522
use crate::errors::Result;
2623

24+
use std::io::Cursor;
25+
26+
use murmur3::murmur3_32;
27+
2728
/// Provides a snapshot of a [`Feature`].
2829
#[derive(Debug)]
2930
pub struct FeatureSnapshot {
@@ -98,6 +99,16 @@ impl FeatureSnapshot {
9899
}
99100
}
100101

102+
fn calculate_normalized_hash(data: &str) -> u32 {
103+
let hash = murmur3_32(&mut Cursor::new(data), 0).expect("Cannot hash the value.");
104+
(f64::from(hash) / f64::from(u32::MAX) * 100.0) as u32
105+
}
106+
107+
fn should_rollout(rollout_percentage: u32, entity: &impl Entity, feature_id: &str) -> bool {
108+
let tag = format!("{}:{}", entity.get_id(), feature_id);
109+
rollout_percentage == 100 || Self::calculate_normalized_hash(&tag) < rollout_percentage
110+
}
111+
101112
fn use_rollout_percentage_to_get_value_from_feature_directly(
102113
&self,
103114
entity: &impl Entity,
@@ -109,16 +120,6 @@ impl FeatureSnapshot {
109120
Ok(self.disabled_value.clone())
110121
}
111122
}
112-
113-
fn calculate_normalized_hash(data: &str) -> u32 {
114-
let hash = murmur3_32(&mut Cursor::new(data), 0).expect("Cannot hash the value.");
115-
(f64::from(hash) / f64::from(u32::MAX) * 100.0) as u32
116-
}
117-
118-
fn should_rollout(rollout_percentage: u32, entity: &impl Entity, feature_id: &str) -> bool {
119-
let tag = format!("{}:{}", entity.get_id(), feature_id);
120-
rollout_percentage == 100 || Self::calculate_normalized_hash(&tag) < rollout_percentage
121-
}
122123
}
123124

124125
impl Feature for FeatureSnapshot {

0 commit comments

Comments
 (0)