@@ -353,6 +353,20 @@ impl<'a, C: GeoConfig<Diff>> GeoDiffCount<'a, C> {
353353 pub fn iter_ones ( & self ) -> impl Iterator < Item = C :: BucketType > + ' _ {
354354 iter_ones ( self . bit_chunks ( ) . peekable ( ) ) . map ( C :: BucketType :: from_usize)
355355 }
356+
357+ /// Generate a pseudo-random filter. For a given number of items
358+ #[ cfg( test) ]
359+ pub fn pseudorandom_filter ( config : C , items : usize ) -> Self {
360+ use rand:: RngCore ;
361+ use rand_chacha:: rand_core:: SeedableRng ;
362+
363+ let mut rng = rand_chacha:: ChaCha12Rng :: seed_from_u64 ( items as u64 ) ;
364+ let mut filter = Self :: new ( config) ;
365+ for _ in 0 ..items {
366+ filter. push_hash ( rng. next_u64 ( ) ) ;
367+ }
368+ filter
369+ }
356370}
357371
358372/// Applies a repeated bit mask to the underlying filter.
@@ -434,7 +448,8 @@ mod tests {
434448 use std:: io:: Write ;
435449
436450 use itertools:: Itertools ;
437- use rand:: { rngs:: StdRng , seq:: IteratorRandom , RngCore } ;
451+ use rand:: { seq:: IteratorRandom , RngCore } ;
452+ use rand_chacha:: ChaCha12Rng ;
438453
439454 use crate :: {
440455 build_hasher:: UnstableDefaultBuildHasher ,
@@ -658,7 +673,7 @@ mod tests {
658673 // This helper exists in order to easily test serializing types with different
659674 // bucket types in the MSB sparse bit field representation. See tests below.
660675 #[ cfg( target_endian = "little" ) ]
661- fn serialization_round_trip < C : GeoConfig < Diff > + Default > ( rnd : & mut StdRng ) {
676+ fn serialization_round_trip < C : GeoConfig < Diff > + Default > ( rnd : & mut ChaCha12Rng ) {
662677 // Run 100 simulations of random values being put into
663678 // a diff counter. "Serializing" to a vector to emulate
664679 // writing to a disk, and then deserializing and asserting
0 commit comments