@@ -43,17 +43,44 @@ pub trait Count<M: Method> {
4343 /// If only the size of the combined set is needed, [`Self::size_with_sketch`] is more efficient and should be used.
4444 fn push_sketch ( & mut self , other : & Self ) ;
4545
46- /// Return the estimated set size.
47- fn size ( & self ) -> f32 ;
46+ /// Return the estimated set size rounded to the nearest unsigned integer.
47+ fn size ( & self ) -> usize {
48+ let size = self . size_f32 ( ) . round ( ) ;
49+ debug_assert_f32s_in_range ( size) ;
50+ size as usize
51+ }
4852
49- /// Return the estimated set size when combined with the given sketch.
53+ /// Return the estimated set size as a real number.
54+ fn size_f32 ( & self ) -> f32 ;
55+
56+ /// Return the estimated set size when combined with the given sketch rounded to the nearest unsigned integer.
57+ /// If the combined set itself is not going to be used, this method is more efficient than using [`Self::push_sketch`] and [`Self::size`].
58+ fn size_with_sketch ( & self , other : & Self ) -> usize {
59+ let size = self . size_with_sketch_f32 ( other) . round ( ) ;
60+ debug_assert_f32s_in_range ( size) ;
61+ size as usize
62+ }
63+
64+ /// Return the estimated set size when combined with the given sketch as a real number.
5065 /// If the combined set itself is not going to be used, this method is more efficient than using [`Self::push_sketch`] and [`Self::size`].
51- fn size_with_sketch ( & self , other : & Self ) -> f32 ;
66+ fn size_with_sketch_f32 ( & self , other : & Self ) -> f32 ;
5267
5368 /// Returns the number of bytes in memory used to represent this filter.
5469 fn bytes_in_memory ( & self ) -> usize ;
5570}
5671
72+ #[ inline]
73+ fn debug_assert_f32s_in_range ( v : f32 ) {
74+ // The geometric filter should never produce these values.
75+ // These assertions failing indicates that there is a bug.
76+ debug_assert ! ( v. is_finite( ) , "Estimated size must be finite, got {v}" ) ;
77+ debug_assert ! ( v >= 0.0 , "Estimated size must be non-negative, got {v}" ) ;
78+ debug_assert ! (
79+ v <= usize :: MAX as f32 ,
80+ "Estimated size {v} exceeds usize::MAX" ,
81+ ) ;
82+ }
83+
5784#[ doc = include_str ! ( "../README.md" ) ]
5885#[ cfg( doctest) ]
5986pub struct ReadmeDocTests ;
0 commit comments