@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
55use std:: collections:: hash_map:: Entry ;
66use std:: collections:: HashMap ;
77
8- use crate :: SketchHashKey :: Zero ;
8+ use crate :: SketchHashKey :: Invalid ;
99#[ cfg( test) ]
1010use ordered_float:: OrderedFloat ;
1111#[ cfg( test) ]
@@ -110,7 +110,7 @@ pub struct SketchHashIterator<'a> {
110110 next_key : SketchHashKey ,
111111}
112112
113- impl < ' a > Iterator for SketchHashIterator < ' a > {
113+ impl Iterator for SketchHashIterator < ' _ > {
114114 type Item = ( SketchHashKey , u64 ) ;
115115
116116 fn next ( & mut self ) -> Option < ( SketchHashKey , u64 ) > {
@@ -284,7 +284,7 @@ impl SketchHashMap {
284284 entries[ old_index] = current;
285285
286286 // We should only return the slice containing the aggregated values
287- let iter = entries. into_iter ( ) . take ( old_index + 1 ) . peekable ( ) ;
287+ let iter = entries. iter_mut ( ) . take ( old_index + 1 ) . peekable ( ) ;
288288
289289 let mut iter = iter. peekable ( ) ;
290290 self . head = iter. peek ( ) . map ( |p| p. 0 ) . unwrap_or ( Invalid ) ;
@@ -304,7 +304,7 @@ impl SketchHashMap {
304304 #[ inline]
305305 fn compact ( & mut self ) {
306306 match self . len ( ) {
307- 0 => return ,
307+ 0 => ( ) ,
308308 // PERCENTILE_AGG_DEFAULT_SIZE defaults to 200, so
309309 // this entry covers that case.
310310 1 ..=200 => self . compact_using_stack :: < 200 > ( ) ,
@@ -344,7 +344,8 @@ impl UDDSketch {
344344 alpha : initial_error,
345345 gamma : ( 1.0 + initial_error) / ( 1.0 - initial_error) ,
346346 compactions : 0 ,
347- max_buckets : NonZeroU32 :: new ( max_buckets as u32 ) . expect ( "max buckets should be greater than zero" ) ,
347+ max_buckets : NonZeroU32 :: new ( max_buckets)
348+ . expect ( "max buckets should be greater than zero" ) ,
348349 num_values : 0 ,
349350 values_sum : 0.0 ,
350351 }
@@ -361,8 +362,7 @@ impl UDDSketch {
361362 buckets : SketchHashMap :: with_capacity ( capacity) ,
362363 alpha : metadata. current_error ,
363364 gamma : gamma ( metadata. current_error ) ,
364- compactions : u8:: try_from ( metadata. compactions )
365- . expect ( "compactions cannot be higher than 65" ) ,
365+ compactions : metadata. compactions ,
366366 max_buckets : NonZeroU32 :: new ( metadata. max_buckets )
367367 . expect ( "max buckets should be greater than zero" ) ,
368368 num_values : metadata. values ,
@@ -376,7 +376,7 @@ impl UDDSketch {
376376
377377 // This assumes the keys are unique and sorted
378378 while let ( Some ( key) , Some ( count) ) = ( keys. next ( ) , counts. next ( ) ) {
379- let next = keys. peek ( ) . map ( |k| * k ) . unwrap_or ( Invalid ) ;
379+ let next = keys. peek ( ) . copied ( ) . unwrap_or ( Invalid ) ;
380380 sketch
381381 . buckets
382382 . map
@@ -876,13 +876,13 @@ mod tests {
876876
877877 for i in 0 ..100 {
878878 assert ! ( ( ( sketch. estimate_quantile( ( i as f64 + 1.0 ) / 100.0 ) / bounds[ i] ) - 1.0 ) . abs( ) < sketch. max_error( ) * bounds[ i] . abs( ) ,
879- "Failed to correct match {} quantile with seed {}. Received: {}, Expected: {}, Error: {}, Expected error bound: {}" ,
880- ( i as f64 + 1.0 ) / 100.0 ,
881- seed,
882- sketch. estimate_quantile( ( i as f64 + 1.0 ) / 100.0 ) ,
883- bounds[ i] ,
884- ( ( sketch. estimate_quantile( ( i as f64 + 1.0 ) / 100.0 ) / bounds[ i] ) - 1.0 ) . abs( ) / bounds[ i] . abs( ) ,
885- sketch. max_error( ) ) ;
879+ "Failed to correct match {} quantile with seed {}. Received: {}, Expected: {}, Error: {}, Expected error bound: {}" ,
880+ ( i as f64 + 1.0 ) / 100.0 ,
881+ seed,
882+ sketch. estimate_quantile( ( i as f64 + 1.0 ) / 100.0 ) ,
883+ bounds[ i] ,
884+ ( ( sketch. estimate_quantile( ( i as f64 + 1.0 ) / 100.0 ) / bounds[ i] ) - 1.0 ) . abs( ) / bounds[ i] . abs( ) ,
885+ sketch. max_error( ) ) ;
886886 }
887887 }
888888
0 commit comments