use std::cmp::Ordering;
use std::marker::PhantomData;
pub type ItemHash = u64;
#[derive(Debug, Clone, Copy)]
pub struct HashedItem<T: Clone + Copy> {
pub(crate) hash: ItemHash,
#[allow(unused)]
pub(crate) item: Option<T>,
}
impl<T: Clone + Copy> PartialEq for HashedItem<T> {
fn eq(&self, other: &HashedItem<T>) -> bool {
other.hash.eq(&self.hash)
}
}
impl<T: Clone + Copy> Eq for HashedItem<T> {}
impl<T: Clone + Copy> Ord for HashedItem<T> {
fn cmp(&self, other: &HashedItem<T>) -> Ordering {
self.hash.cmp(&other.hash)
}
}
impl<T: Clone + Copy> PartialOrd for HashedItem<T> {
fn partial_cmp(&self, other: &HashedItem<T>) -> Option<Ordering> {
Some(self.hash.cmp(&other.hash))
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct HashCount<T: Clone + Copy> {
pub hashed: HashedItem<T>,
pub count: u16,
}
#[derive(Debug, Clone)]
pub struct InvHashedItem<T: Clone + Copy> {
pub(crate) hash: ItemHash,
pub(crate) t_marker: PhantomData<T>,
}
impl<T: Clone + Copy> InvHashedItem<T> {
pub fn new(hash: ItemHash) -> Self {
InvHashedItem {
hash,
t_marker: PhantomData,
}
}
pub fn get_hash(&self) -> ItemHash {
self.hash
} }
impl<T: Copy + Clone> PartialEq for InvHashedItem<T> {
fn eq(&self, other: &InvHashedItem<T>) -> bool {
other.hash.eq(&self.hash)
}
}
impl<T: Copy + Clone> Eq for InvHashedItem<T> {}
impl<T: Clone + Copy> Ord for InvHashedItem<T> {
fn cmp(&self, other: &InvHashedItem<T>) -> Ordering {
self.hash.cmp(&other.hash)
}
}
impl<T: Clone + Copy> PartialOrd for InvHashedItem<T> {
fn partial_cmp(&self, other: &InvHashedItem<T>) -> Option<Ordering> {
Some(self.hash.cmp(&other.hash))
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InvHashCount<T: Clone + Copy> {
pub hashed: InvHashedItem<T>,
pub(crate) count: u8,
}
impl<T: Clone + Copy> InvHashCount<T> {
pub fn new(hashed: InvHashedItem<T>, count: u8) -> Self {
InvHashCount { hashed, count }
}
pub fn get_count(&self) -> u8 {
self.count
}
}