#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NumaNodeId(u32);
impl NumaNodeId {
pub const ZERO: Self = Self(0);
pub const INVALID: Self = Self(u32::MAX);
#[must_use]
pub const fn new(raw: u32) -> Self {
Self(raw)
}
#[must_use]
pub const fn get(self) -> u32 {
self.0
}
#[must_use]
pub const fn index(self) -> usize {
self.0 as usize
}
#[must_use]
#[inline]
pub const fn is_valid(self) -> bool {
self.0 != Self::INVALID.0
}
#[must_use]
pub const fn bucket_index<const BUCKETS: usize>(self) -> NumaBucketIndex<BUCKETS> {
NumaBucketIndex::new(self.index())
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NumaBucketIndex<const BUCKETS: usize>(usize);
impl<const BUCKETS: usize> NumaBucketIndex<BUCKETS> {
const ASSERT_NONZERO: () = {
assert!(BUCKETS > 0, "NUMA bucket count must be non-zero");
};
#[must_use]
pub const fn new(raw: usize) -> Self {
let () = Self::ASSERT_NONZERO;
Self(raw % BUCKETS)
}
#[must_use]
pub const fn index(self) -> usize {
self.0
}
#[must_use]
pub const fn wrapping_add(self, offset: usize) -> Self {
let () = Self::ASSERT_NONZERO;
let offset = offset % BUCKETS;
let remaining = BUCKETS - self.0;
if offset < remaining {
Self(self.0 + offset)
} else {
Self(offset - remaining)
}
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WorkerId(u32);
impl WorkerId {
pub const INVALID: Self = Self(u32::MAX);
#[must_use]
pub const fn new(raw: u32) -> Self {
Self(raw)
}
#[must_use]
pub const fn get(self) -> u32 {
self.0
}
#[must_use]
pub const fn index(self) -> usize {
self.0 as usize
}
#[must_use]
#[inline]
pub const fn is_valid(self) -> bool {
self.0 != Self::INVALID.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct LocalityDomainId(u32);
impl LocalityDomainId {
pub const INVALID: Self = Self(u32::MAX);
#[must_use]
pub const fn new(raw: u32) -> Self {
Self(raw)
}
#[must_use]
pub const fn get(self) -> u32 {
self.0
}
#[must_use]
#[inline]
pub const fn is_valid(self) -> bool {
self.0 != Self::INVALID.0
}
}