Add epaint::util::hash function for hashing a value
This commit is contained in:
@@ -13,11 +13,6 @@ impl TypeId {
|
||||
|
||||
impl From<std::any::TypeId> for TypeId {
|
||||
fn from(id: std::any::TypeId) -> Self {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
let mut hasher = DefaultHasher::new();
|
||||
id.hash(&mut hasher);
|
||||
Self(hasher.finish())
|
||||
Self(epaint::util::hash(id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::hash::{Hash, Hasher};
|
||||
use epaint::util::hash;
|
||||
|
||||
const SIZE: usize = 1024; // must be small for web/WASM build (for unknown reason)
|
||||
|
||||
@@ -24,7 +24,7 @@ impl<K, V> std::fmt::Debug for Cache<K, V> {
|
||||
|
||||
impl<K, V> Cache<K, V>
|
||||
where
|
||||
K: Hash + PartialEq,
|
||||
K: std::hash::Hash + PartialEq,
|
||||
{
|
||||
pub fn get(&self, key: &K) -> Option<&V> {
|
||||
let bucket = (hash(key) % (SIZE as u64)) as usize;
|
||||
@@ -39,10 +39,3 @@ where
|
||||
self.0[bucket] = Some((key, value));
|
||||
}
|
||||
}
|
||||
|
||||
fn hash(value: impl Hash) -> u64 {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
let mut hasher = DefaultHasher::default();
|
||||
value.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user