11
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
- use std:: io:: Cursor ;
15
-
16
- use murmur3:: murmur3_32;
17
14
18
15
use crate :: entity:: Entity ;
19
16
use crate :: metering:: { MeteringRecorderSender , MeteringSubject } ;
@@ -24,6 +21,10 @@ use crate::segment_evaluation::TargetingRules;
24
21
25
22
use crate :: errors:: Result ;
26
23
24
+ use std:: io:: Cursor ;
25
+
26
+ use murmur3:: murmur3_32;
27
+
27
28
/// Provides a snapshot of a [`Feature`].
28
29
#[ derive( Debug ) ]
29
30
pub struct FeatureSnapshot {
@@ -98,6 +99,16 @@ impl FeatureSnapshot {
98
99
}
99
100
}
100
101
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
+
101
112
fn use_rollout_percentage_to_get_value_from_feature_directly (
102
113
& self ,
103
114
entity : & impl Entity ,
@@ -109,16 +120,6 @@ impl FeatureSnapshot {
109
120
Ok ( self . disabled_value . clone ( ) )
110
121
}
111
122
}
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
- }
122
123
}
123
124
124
125
impl Feature for FeatureSnapshot {
0 commit comments