@@ -768,6 +768,7 @@ mod tests {
768768 }
769769 }
770770
771+ use crate :: SketchHashKey :: Invalid ;
771772 use quickcheck:: * ;
772773
773774 #[ derive( Hash , PartialEq , Eq , PartialOrd , Ord , Copy , Clone , Debug ) ]
@@ -779,6 +780,63 @@ mod tests {
779780 }
780781 }
781782
783+ #[ test]
784+ fn test_entry_insertion_order ( ) {
785+ let mut map = SketchHashMap {
786+ map : HashMap :: new ( ) ,
787+ head : Invalid ,
788+ } ;
789+
790+ map. entry ( SketchHashKey :: Negative ( i64:: MIN ) ) . count += 5 ;
791+ map. entry ( SketchHashKey :: Negative ( 10 ) ) . count += 1 ;
792+ map. entry ( SketchHashKey :: Positive ( i64:: MAX - 100 ) ) . count += 17 ;
793+ map. entry ( SketchHashKey :: Zero ) . count += 7 ;
794+ map. entry ( SketchHashKey :: Positive ( -10 ) ) . count += 11 ;
795+ map. entry ( SketchHashKey :: Negative ( -10 ) ) . count += 3 ;
796+ map. entry ( SketchHashKey :: Positive ( 10 ) ) . count += 13 ;
797+
798+ let keys: Vec < _ > = map. iter ( ) . collect :: < Vec < _ > > ( ) ;
799+ assert_eq ! (
800+ keys,
801+ vec![
802+ ( SketchHashKey :: Negative ( 10 ) , 1 ) ,
803+ ( SketchHashKey :: Negative ( -10 ) , 3 ) ,
804+ ( SketchHashKey :: Negative ( i64 :: MIN ) , 5 ) ,
805+ ( SketchHashKey :: Zero , 7 ) ,
806+ ( SketchHashKey :: Positive ( -10 ) , 11 ) ,
807+ ( SketchHashKey :: Positive ( 10 ) , 13 ) ,
808+ ( SketchHashKey :: Positive ( i64 :: MAX - 100 ) , 17 ) ,
809+ ]
810+ ) ;
811+
812+ // We add some things before the current head, insert some new ones,
813+ // add some to the end, and again inbetween some others
814+ map. entry ( SketchHashKey :: Negative ( i64:: MAX ) ) . count += 3 ;
815+ map. entry ( SketchHashKey :: Negative ( -10 ) ) . count += 23 ;
816+ map. entry ( SketchHashKey :: Positive ( 10 ) ) . count += 123 ;
817+ map. entry ( SketchHashKey :: Positive ( 9 ) ) . count += 29 ;
818+ map. entry ( SketchHashKey :: Positive ( 11 ) ) . count += 31 ;
819+ map. entry ( SketchHashKey :: Positive ( i64:: MAX ) ) . count += 8 ;
820+
821+ let keys: Vec < _ > = map. iter ( ) . collect :: < Vec < _ > > ( ) ;
822+ assert_eq ! (
823+ keys,
824+ vec![
825+ ( SketchHashKey :: Negative ( i64 :: MAX ) , 3 ) ,
826+ ( SketchHashKey :: Negative ( 10 ) , 1 ) ,
827+ ( SketchHashKey :: Negative ( -10 ) , 26 ) , // 3 + 23
828+ ( SketchHashKey :: Negative ( i64 :: MIN ) , 5 ) ,
829+ ( SketchHashKey :: Zero , 7 ) ,
830+ ( SketchHashKey :: Positive ( -10 ) , 11 ) ,
831+ ( SketchHashKey :: Positive ( 9 ) , 29 ) ,
832+ ( SketchHashKey :: Positive ( 10 ) , 136 ) , // 13 + 123
833+ ( SketchHashKey :: Positive ( 11 ) , 31 ) ,
834+ ( SketchHashKey :: Positive ( i64 :: MAX - 100 ) , 17 ) ,
835+ ( SketchHashKey :: Positive ( i64 :: MAX ) , 8 ) ,
836+ ]
837+ ) ;
838+ }
839+
782840 #[ quickcheck]
783841 // Use multiple hashsets as input to allow a small number of duplicate values without getting ridiculous levels of duplication (as quickcheck is inclined to create)
784842 fn fuzzing_test (
0 commit comments