1use std::fmt;
17use std::ops::BitXorAssign;
18
19use rustc_stable_hash::{FromStableHash, SipHasher128Hash as StableHasherHash};
20
21#[derive(#[automatically_derived]
impl ::core::clone::Clone for Hash64 {
#[inline]
fn clone(&self) -> Hash64 {
let _: ::core::clone::AssertParamIsClone<u64>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Hash64 { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for Hash64 {
#[inline]
fn eq(&self, other: &Hash64) -> bool { self.inner == other.inner }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Hash64 {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u64>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Hash64 {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.inner, state)
}
}Hash, #[automatically_derived]
impl ::core::cmp::PartialOrd for Hash64 {
#[inline]
fn partial_cmp(&self, other: &Hash64)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.inner, &other.inner)
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Hash64 {
#[inline]
fn cmp(&self, other: &Hash64) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.inner, &other.inner)
}
}Ord, #[automatically_derived]
impl ::core::default::Default for Hash64 {
#[inline]
fn default() -> Hash64 {
Hash64 { inner: ::core::default::Default::default() }
}
}Default)]
23pub struct Hash64 {
24 inner: u64,
25}
26
27impl Hash64 {
28 pub const ZERO: Hash64 = Hash64 { inner: 0 };
29
30 #[inline]
31 pub fn new(n: u64) -> Self {
32 Self { inner: n }
33 }
34
35 #[inline]
36 pub fn as_u64(self) -> u64 {
37 self.inner
38 }
39
40 #[inline]
41 pub fn wrapping_add(self, other: Self) -> Self {
42 Self { inner: self.inner.wrapping_add(other.inner) }
43 }
44}
45
46impl BitXorAssign<u64> for Hash64 {
47 #[inline]
48 fn bitxor_assign(&mut self, rhs: u64) {
49 self.inner ^= rhs;
50 }
51}
52
53impl FromStableHash for Hash64 {
54 type Hash = StableHasherHash;
55
56 #[inline]
57 fn from(StableHasherHash([_0, _]): Self::Hash) -> Self {
58 Self { inner: _0 }
59 }
60}
61
62impl fmt::Debug for Hash64 {
63 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64 self.inner.fmt(f)
65 }
66}
67
68impl fmt::LowerHex for Hash64 {
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 fmt::LowerHex::fmt(&self.inner, f)
71 }
72}
73
74#[derive(#[automatically_derived]
impl ::core::clone::Clone for Hash128 {
#[inline]
fn clone(&self) -> Hash128 {
let _: ::core::clone::AssertParamIsClone<u128>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Hash128 { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for Hash128 {
#[inline]
fn eq(&self, other: &Hash128) -> bool { self.inner == other.inner }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Hash128 {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u128>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Hash128 {
#[inline]
fn partial_cmp(&self, other: &Hash128)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.inner, &other.inner)
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Hash128 {
#[inline]
fn cmp(&self, other: &Hash128) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.inner, &other.inner)
}
}Ord, #[automatically_derived]
impl ::core::default::Default for Hash128 {
#[inline]
fn default() -> Hash128 {
Hash128 { inner: ::core::default::Default::default() }
}
}Default)]
76pub struct Hash128 {
77 inner: u128,
78}
79
80impl std::hash::Hash for Hash128 {
85 fn hash<H: std::hash::Hasher>(&self, h: &mut H) {
86 h.write_u64(self.truncate().as_u64());
87 }
88}
89
90impl Hash128 {
91 #[inline]
92 pub fn new(n: u128) -> Self {
93 Self { inner: n }
94 }
95
96 #[inline]
97 pub fn truncate(self) -> Hash64 {
98 Hash64 { inner: self.inner as u64 }
99 }
100
101 #[inline]
102 pub fn wrapping_add(self, other: Self) -> Self {
103 Self { inner: self.inner.wrapping_add(other.inner) }
104 }
105
106 #[inline]
107 pub fn as_u128(self) -> u128 {
108 self.inner
109 }
110}
111
112impl FromStableHash for Hash128 {
113 type Hash = StableHasherHash;
114
115 #[inline]
116 fn from(StableHasherHash([_0, _1]): Self::Hash) -> Self {
117 Self { inner: u128::from(_0) | (u128::from(_1) << 64) }
118 }
119}
120
121impl fmt::Debug for Hash128 {
122 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123 self.inner.fmt(f)
124 }
125}
126
127impl fmt::LowerHex for Hash128 {
128 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129 fmt::LowerHex::fmt(&self.inner, f)
130 }
131}