This is an automated email from the ASF dual-hosted git repository. tison pushed a commit to branch frequent-items in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
commit 63e6955521b61900f9bbe308e38179e3c13ec151 Author: tison <[email protected]> AuthorDate: Sun Feb 1 15:23:40 2026 +0800 redo with tidy change Signed-off-by: tison <[email protected]> --- datasketches/src/frequencies/sketch.rs | 23 ++++++++++------------- datasketches/tests/frequencies_update_test.rs | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/datasketches/src/frequencies/sketch.rs b/datasketches/src/frequencies/sketch.rs index e0d9711..9ee44b6 100644 --- a/datasketches/src/frequencies/sketch.rs +++ b/datasketches/src/frequencies/sketch.rs @@ -66,14 +66,12 @@ impl<T> Row<T> { self.estimate } - /// Returns the upper bound for the frequency. + /// Returns the guaranteed upper bound for the frequency. pub fn upper_bound(&self) -> u64 { self.upper_bound } /// Returns the guaranteed lower bound for the frequency. - /// - /// This value is never negative. pub fn lower_bound(&self) -> u64 { self.lower_bound } @@ -115,7 +113,11 @@ impl<T: Eq + Hash> FrequentItemsSketch<T> { /// assert_eq!(sketch.num_active_items(), 2); /// ``` pub fn new(max_map_size: usize) -> Self { - let lg_max_map_size = exact_log2(max_map_size); + assert!( + max_map_size.is_power_of_two(), + "max_map_size must be power of 2" + ); + let lg_max_map_size = max_map_size.trailing_zeros() as u8; Self::with_lg_map_sizes(lg_max_map_size, LG_MIN_MAP_SIZE) } @@ -155,16 +157,16 @@ impl<T: Eq + Hash> FrequentItemsSketch<T> { /// Returns the guaranteed lower bound frequency for an item. /// - /// This value is never negative and is guaranteed to be no larger than the true frequency. - /// If the item is not tracked, the lower bound is zero. + /// This value is guaranteed to be no larger than the true frequency. If the item is not + /// tracked, the lower bound is zero. pub fn lower_bound(&self, item: &T) -> u64 { self.hash_map.get(item) } /// Returns the guaranteed upper bound frequency for an item. /// - /// This value is guaranteed to be no smaller than the true frequency. - /// If the item is tracked, this is `item_count + offset`. + /// This value is guaranteed to be no smaller than the true frequency. If the item is tracked, + /// this is `item_count + offset`. pub fn upper_bound(&self, item: &T) -> u64 { self.hash_map.get(item) + self.offset } @@ -599,8 +601,3 @@ impl FrequentItemsSketch<String> { Self::deserialize_inner(bytes, deserialize_string_items) } } - -fn exact_log2(value: usize) -> u8 { - assert!(value.is_power_of_two(), "value must be power of 2"); - value.trailing_zeros() as u8 -} diff --git a/datasketches/tests/frequencies_update_test.rs b/datasketches/tests/frequencies_update_test.rs index f2b0001..a5a98e1 100644 --- a/datasketches/tests/frequencies_update_test.rs +++ b/datasketches/tests/frequencies_update_test.rs @@ -480,13 +480,13 @@ fn test_longs_reset() { } #[test] -#[should_panic(expected = "value must be power of 2")] +#[should_panic(expected = "max_map_size must be power of 2")] fn test_longs_invalid_map_size_panics() { FrequentItemsSketch::<i64>::new(6); } #[test] -#[should_panic(expected = "value must be power of 2")] +#[should_panic(expected = "max_map_size must be power of 2")] fn test_items_invalid_map_size_panics() { let _ = FrequentItemsSketch::<String>::new(6); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
