@@ -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 : [ [ usize ; WIDTH ] ; DEPTH ] ,
94- hashers : [ RandomState ; DEPTH ] ,
93+ counts : Vec < [ usize ; WIDTH ] > ,
94+ hashers : Vec < RandomState > ,
9595}
9696
9797impl < Item : Hash , const WIDTH : usize , const DEPTH : usize > Debug
@@ -106,11 +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 :: array :: from_fn ( |_| RandomState :: new ( ) ) ;
109+ let hashers = ( 0 .. DEPTH ) . map ( |_| RandomState :: new ( ) ) . collect ( ) ;
110110
111111 Self {
112112 phantom : std:: marker:: PhantomData ,
113- counts : [ [ 0 ; WIDTH ] ; DEPTH ] ,
113+ counts : ( 0 .. DEPTH ) . map ( |_| [ 0 ; WIDTH ] ) . collect ( ) ,
114114 hashers,
115115 }
116116 }
@@ -183,14 +183,14 @@ mod tests {
183183 let mut sketch: HashCountMinSketch < & str , 5 , 7 > = HashCountMinSketch :: default ( ) ;
184184 sketch. increment ( "test" ) ;
185185 // Inspect internal state:
186- for counts in sketch. counts {
186+ for counts in & sketch. counts {
187187 let zeroes = counts. iter ( ) . filter ( |count| * * count == 0 ) . count ( ) ;
188188 assert_eq ! ( 4 , zeroes) ;
189189 let ones = counts. iter ( ) . filter ( |count| * * count == 1 ) . count ( ) ;
190190 assert_eq ! ( 1 , ones) ;
191191 }
192192 sketch. increment ( "test" ) ;
193- for counts in sketch. counts {
193+ for counts in & sketch. counts {
194194 let zeroes = counts. iter ( ) . filter ( |count| * * count == 0 ) . count ( ) ;
195195 assert_eq ! ( 4 , zeroes) ;
196196 let twos = counts. iter ( ) . filter ( |count| * * count == 2 ) . count ( ) ;
0 commit comments