use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BlockId(u32);
impl BlockId {
#[inline]
#[must_use]
pub const fn new(id: u32) -> Self {
Self(id)
}
#[inline]
#[must_use]
pub const fn as_u32(self) -> u32 {
self.0
}
}
impl Hash for BlockId {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
impl PartialOrd for BlockId {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for BlockId {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FunctionId(u32);
impl FunctionId {
#[inline]
#[must_use]
pub const fn new(id: u32) -> Self {
Self(id)
}
#[inline]
#[must_use]
pub const fn as_u32(self) -> u32 {
self.0
}
}
impl Hash for FunctionId {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
impl PartialOrd for FunctionId {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for FunctionId {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EdgeId(u64);
impl EdgeId {
#[inline]
#[must_use]
pub const fn new(from: BlockId, to: BlockId) -> Self {
Self((from.0 as u64) << 32 | to.0 as u64)
}
#[inline]
#[must_use]
pub const fn source(self) -> BlockId {
BlockId((self.0 >> 32) as u32)
}
#[inline]
#[must_use]
pub const fn target(self) -> BlockId {
BlockId(self.0 as u32)
}
#[inline]
#[must_use]
pub const fn as_u64(self) -> u64 {
self.0
}
}
impl Hash for EdgeId {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
impl PartialOrd for EdgeId {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for EdgeId {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
}
}