@@ -90,8 +90,8 @@ pub trait CountMinSketch {
9090/// But an interesting property is that the count we return for "TEST" cannot be underestimated
9191pub struct HashCountMinSketch < Item : Hash , const WIDTH : usize , const DEPTH : usize > {
9292 phantom : std:: marker:: PhantomData < Item > , // just a marker for Item to be used
93- counts : Vec < [ usize ; WIDTH ] > ,
94- hashers : Vec < RandomState > ,
93+ counts : [ [ usize ; WIDTH ] ; DEPTH ] ,
94+ hashers : [ RandomState ; DEPTH ] ,
9595}
9696
9797impl < Item : Hash , const WIDTH : usize , const DEPTH : usize > Debug
@@ -106,13 +106,11 @@ impl<T: Hash, const WIDTH: usize, const DEPTH: usize> Default
106106 for HashCountMinSketch < T , WIDTH , DEPTH >
107107{
108108 fn default ( ) -> Self {
109- let hashers = std:: iter:: repeat_with ( RandomState :: new)
110- . take ( DEPTH )
111- . collect ( ) ;
109+ let hashers = std:: array:: from_fn ( |_| RandomState :: new ( ) ) ;
112110
113111 Self {
114112 phantom : std:: marker:: PhantomData ,
115- counts : vec ! [ [ 0 ; WIDTH ] ; DEPTH ] ,
113+ counts : [ [ 0 ; WIDTH ] ; DEPTH ] ,
116114 hashers,
117115 }
118116 }
@@ -185,14 +183,14 @@ mod tests {
185183 let mut sketch: HashCountMinSketch < & str , 5 , 7 > = HashCountMinSketch :: default ( ) ;
186184 sketch. increment ( "test" ) ;
187185 // Inspect internal state:
188- for counts in & sketch. counts {
186+ for counts in sketch. counts {
189187 let zeroes = counts. iter ( ) . filter ( |count| * * count == 0 ) . count ( ) ;
190188 assert_eq ! ( 4 , zeroes) ;
191189 let ones = counts. iter ( ) . filter ( |count| * * count == 1 ) . count ( ) ;
192190 assert_eq ! ( 1 , ones) ;
193191 }
194192 sketch. increment ( "test" ) ;
195- for counts in & sketch. counts {
193+ for counts in sketch. counts {
196194 let zeroes = counts. iter ( ) . filter ( |count| * * count == 0 ) . count ( ) ;
197195 assert_eq ! ( 4 , zeroes) ;
198196 let twos = counts. iter ( ) . filter ( |count| * * count == 2 ) . count ( ) ;
0 commit comments