use core::hash::Hash;
use core::num::NonZeroU64;
const HASH_SEEDS: (u64, u64, u64, u64) = (9, 10, 11, 12);
pub type ItemIdSet = nohash_hasher::IntSet<ItemId>;
pub type ItemIdMap<V> = nohash_hasher::IntMap<ItemId, V>;
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct ItemId(NonZeroU64);
impl nohash_hasher::IsEnabled for ItemId {}
impl ItemId {
pub fn new(source: impl Hash) -> Self {
let (a, b, c, d) = HASH_SEEDS;
let hash = ahash::RandomState::with_seeds(a, b, c, d).hash_one(source);
Self(NonZeroU64::new(hash).unwrap_or(NonZeroU64::MIN)) }
#[inline(always)]
pub fn value(self) -> u64 {
self.0.get()
}
}
impl core::fmt::Debug for ItemId {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "ItemId({:04X})", self.value() as u16)
}
}