pub const SEQUENCE_BITS: u32 = 42;
const SEQUENCE_MASK: u64 = (1_u64 << SEQUENCE_BITS) - 1;
pub type PartitionId = u32;
pub type KwId = u64;
pub type AttrId = EntityId;
pub type TxId = EntityId;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[repr(u32)]
pub enum Partition {
Db = 0,
Tx = 1,
User = 2,
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct EntityId(u64);
impl EntityId {
#[must_use]
pub const fn new(partition: PartitionId, sequence: u64) -> Self {
Self(((partition as u64) << SEQUENCE_BITS) | (sequence & SEQUENCE_MASK))
}
#[must_use]
pub const fn from_raw(raw: u64) -> Self {
Self(raw)
}
#[must_use]
pub const fn raw(self) -> u64 {
self.0
}
#[must_use]
pub const fn partition(self) -> PartitionId {
(self.0 >> SEQUENCE_BITS) as PartitionId
}
#[must_use]
pub const fn sequence(self) -> u64 {
self.0 & SEQUENCE_MASK
}
}