diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-06-13 23:16:40 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-06-14 13:53:02 +0200 |
| commit | c81e2a5f56eb262663f292578c683fba7f18251f (patch) | |
| tree | 6c045a8dcbec5e75e01a15f970ef8cee6ff042d0 /src/util/prehashed.rs | |
| parent | 891af17260a6750a74a102388a05e59cf1ffc3c1 (diff) | |
Many fixes
Diffstat (limited to 'src/util/prehashed.rs')
| -rw-r--r-- | src/util/prehashed.rs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/util/prehashed.rs b/src/util/prehashed.rs deleted file mode 100644 index 79455918..00000000 --- a/src/util/prehashed.rs +++ /dev/null @@ -1,63 +0,0 @@ -use std::any::Any; -use std::fmt::{self, Debug, Formatter}; -use std::hash::{Hash, Hasher}; -use std::ops::Deref; - -/// A wrapper around a type that precomputes its hash. -#[derive(Copy, Clone)] -pub struct Prehashed<T: ?Sized> { - /// The precomputed hash. - hash: u64, - /// The wrapped item. - item: T, -} - -impl<T: Hash + 'static> Prehashed<T> { - /// Compute an item's hash and wrap it. - pub fn new(item: T) -> Self { - Self { - hash: { - // Also hash the TypeId because the type might be converted - // through an unsized coercion. - let mut state = fxhash::FxHasher64::default(); - item.type_id().hash(&mut state); - item.hash(&mut state); - state.finish() - }, - item, - } - } - - /// Return the wrapped value. - pub fn into_iter(self) -> T { - self.item - } -} - -impl<T: ?Sized> Deref for Prehashed<T> { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.item - } -} - -impl<T: Debug + ?Sized> Debug for Prehashed<T> { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - self.item.fmt(f) - } -} - -impl<T: ?Sized> Hash for Prehashed<T> { - fn hash<H: Hasher>(&self, state: &mut H) { - state.write_u64(self.hash); - } -} - -impl<T: Eq + ?Sized> Eq for Prehashed<T> {} - -impl<T: ?Sized> PartialEq for Prehashed<T> { - fn eq(&self, other: &Self) -> bool { - self.hash == other.hash - } -} |
