@@ -30,7 +30,7 @@ impl serde::ser::Error for FingerprinterError {
3030 }
3131}
3232
33- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
33+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
3434pub struct Fingerprint ( pub [ u8 ; 16 ] ) ;
3535
3636impl Fingerprint {
@@ -63,6 +63,14 @@ impl AsRef<[u8]> for Fingerprint {
6363 }
6464}
6565
66+ impl std:: hash:: Hash for Fingerprint {
67+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
68+ // Fingerprint is already evenly distributed, so we can just use the first few bytes.
69+ const N : usize = size_of :: < usize > ( ) ;
70+ state. write ( & self . 0 [ ..N ] ) ;
71+ }
72+ }
73+
6674impl Serialize for Fingerprint {
6775 fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
6876 where
@@ -101,6 +109,10 @@ impl Fingerprinter {
101109 value. serialize ( self )
102110 }
103111
112+ pub fn write_raw_bytes ( & mut self , bytes : & [ u8 ] ) {
113+ self . hasher . update ( bytes) ;
114+ }
115+
104116 fn write_type_tag ( & mut self , tag : & str ) {
105117 self . hasher . update ( tag. as_bytes ( ) ) ;
106118 self . hasher . update ( b";" ) ;
0 commit comments