@@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
55use std:: collections:: hash_map:: Entry ;
66use std:: collections:: HashMap ;
77
8+ use crate :: SketchHashKey :: Zero ;
89#[ cfg( test) ]
910use ordered_float:: OrderedFloat ;
1011#[ cfg( test) ]
@@ -28,23 +29,28 @@ pub enum SketchHashKey {
2829}
2930
3031// Invalid is treated as greater than valid values (making it a nice boundary value for list end)
31- impl std:: cmp:: PartialOrd for SketchHashKey {
32- fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
32+ impl std:: cmp:: Ord for SketchHashKey {
33+ fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
3334 use self :: SketchHashKey :: * ;
3435 use std:: cmp:: Ordering :: * ;
36+
3537 match ( self , other) {
36- ( Invalid , Invalid ) => Equal ,
37- ( Invalid , _) => Greater ,
38- ( _, Invalid ) => Less ,
39- ( Zero , Zero ) => Equal ,
4038 ( Positive ( a) , Positive ( b) ) => a. cmp ( b) ,
4139 ( Negative ( a) , Negative ( b) ) => a. cmp ( b) . reverse ( ) ,
42- ( _, Positive ( _) ) => Less ,
43- ( Positive ( _) , _) => Greater ,
44- ( _, Negative ( _) ) => Greater ,
45- ( Negative ( _) , _) => Less ,
40+ ( Positive ( _) , Negative ( _) | Zero ) => Greater ,
41+ ( Negative ( _) | Zero , Positive ( _) ) => Less ,
42+ ( Zero , Negative ( _) ) => Greater ,
43+ ( Negative ( _) , Zero ) => Less ,
44+ ( Zero , Zero ) => Equal ,
45+ ( Invalid , Invalid ) => Equal ,
46+ ( Invalid , Negative ( _) | Zero | Positive ( _) ) => Greater ,
47+ ( Negative ( _) | Zero | Positive ( _) , Invalid ) => Less ,
4648 }
47- . into ( )
49+ }
50+ }
51+ impl std:: cmp:: PartialOrd for SketchHashKey {
52+ fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
53+ Some ( self . cmp ( other) )
4854 }
4955}
5056
0 commit comments