use std::collections::hash_map::DefaultHasher;
use std::fmt::Display;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
#[derive(Clone)]
pub struct S3FIFOKey<V: Hash> {
hash: u64,
_phantom: PhantomData<V>,
}
impl<V: Hash> PartialEq for S3FIFOKey<V> {
fn eq(&self, other: &Self) -> bool {
self.hash == other.hash
}
}
impl<V: Hash> S3FIFOKey<V> {
pub fn new(value: &V) -> Self {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
S3FIFOKey {
hash: hasher.finish(),
_phantom: PhantomData,
}
}
}
impl<V: Hash> std::fmt::Debug for S3FIFOKey<V> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("S3FIFOKey")
.field("hash", &self.hash)
.finish()
}
}
impl<V: Hash> Display for S3FIFOKey<V> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:#x}", self.hash)
}
}