@@ -26,9 +26,8 @@ use crate::codec::assert::insufficient_data;
2626use crate :: codec:: family:: Family ;
2727use crate :: common:: NumStdDev ;
2828use crate :: error:: Error ;
29+ use crate :: hll:: Coupon ;
2930use crate :: hll:: estimator:: HipEstimator ;
30- use crate :: hll:: get_slot;
31- use crate :: hll:: get_value;
3231use crate :: hll:: serialization:: CUR_MODE_HLL ;
3332use crate :: hll:: serialization:: HLL_PREAMBLE_SIZE ;
3433use crate :: hll:: serialization:: HLL_PREINTS ;
@@ -78,10 +77,10 @@ impl Array8 {
7877 }
7978
8079 /// Update with a coupon
81- pub fn update ( & mut self , coupon : u32 ) {
80+ pub fn update ( & mut self , coupon : Coupon ) {
8281 let mask = ( 1 << self . lg_config_k ) - 1 ;
83- let slot = get_slot ( coupon) & mask;
84- let new_value = get_value ( coupon) ;
82+ let slot = coupon. slot ( ) & mask;
83+ let new_value = coupon. value ( ) ;
8584
8685 let old_value = self . get ( slot) ;
8786
@@ -350,8 +349,7 @@ impl Array8 {
350349#[ cfg( test) ]
351350mod tests {
352351 use super :: * ;
353- use crate :: hll:: coupon;
354- use crate :: hll:: pack_coupon;
352+ use crate :: hll:: Coupon ;
355353
356354 #[ test]
357355 fn test_array8_basic ( ) {
@@ -391,20 +389,20 @@ mod tests {
391389 let mut arr = Array8 :: new ( 4 ) ;
392390
393391 // Update slot 0 with value 5
394- arr. update ( pack_coupon ( 0 , 5 ) ) ;
392+ arr. update ( Coupon :: pack ( 0 , 5 ) ) ;
395393 assert_eq ! ( arr. get( 0 ) , 5 ) ;
396394
397395 // Update with a smaller value (should be ignored)
398- arr. update ( pack_coupon ( 0 , 3 ) ) ;
396+ arr. update ( Coupon :: pack ( 0 , 3 ) ) ;
399397 assert_eq ! ( arr. get( 0 ) , 5 ) ;
400398
401399 // Update with a larger value
402- arr. update ( pack_coupon ( 0 , 42 ) ) ;
400+ arr. update ( Coupon :: pack ( 0 , 42 ) ) ;
403401 assert_eq ! ( arr. get( 0 ) , 42 ) ;
404402
405403 // Test value at max coupon range (63)
406- // Note: pack_coupon only stores 6 bits (0-63)
407- arr. update ( pack_coupon ( 1 , 63 ) ) ;
404+ // Note: Coupon::pack only stores 6 bits (0-63)
405+ arr. update ( Coupon :: pack ( 1 , 63 ) ) ;
408406 assert_eq ! ( arr. get( 1 ) , 63 ) ;
409407 }
410408
@@ -417,8 +415,7 @@ mod tests {
417415
418416 // Add some unique values using real coupon hashing
419417 for i in 0 ..10_000u32 {
420- let coupon = coupon ( i) ;
421- arr. update ( coupon) ;
418+ arr. update ( Coupon :: from_hash ( i) ) ;
422419 }
423420
424421 let estimate = arr. estimate ( ) ;
@@ -471,8 +468,8 @@ mod tests {
471468 let mut arr = Array8 :: new ( 8 ) ; // 256 buckets
472469
473470 // Test that values < 32 and >= 32 are handled correctly
474- arr. update ( pack_coupon ( 0 , 10 ) ) ; // value < 32, goes to kxq0
475- arr. update ( pack_coupon ( 1 , 50 ) ) ; // value >= 32, goes to kxq1
471+ arr. update ( Coupon :: pack ( 0 , 10 ) ) ; // value < 32, goes to kxq0
472+ arr. update ( Coupon :: pack ( 1 , 50 ) ) ; // value >= 32, goes to kxq1
476473
477474 // Initial kxq0 = 256 (all zeros = 1.0 each)
478475 assert ! ( arr. estimator. kxq0( ) < 256.0 , "kxq0 should have decreased" ) ;
0 commit comments