1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
pub trait Var: Copy { fn new(sort_idx: u8, deps: u64, bound: bool) -> Self; fn is_bound(&self) -> bool; fn depends_on(&self, t: u8) -> bool; fn depends_on_full(&self, other: u64) -> bool; fn dependencies(&self) -> u64; fn sort_idx(&self) -> u8; fn is_compatible_to(&self, other: &Self) -> bool; } #[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct Var_(u64); impl From<u64> for Var_ { #[inline(always)] fn from(value: u64) -> Var_ { Var_(value) } } impl Var for Var_ { #[inline(always)] fn new(sort_idx: u8, deps: u64, bound: bool) -> Var_ { if bound { Var_((((sort_idx & 0x7F) as u64) << 56) | deps | (1 << 63)) } else { Var_((((sort_idx & 0x7F) as u64) << 56) | deps) } } #[inline(always)] fn is_bound(&self) -> bool { self.0 & (1u64 << 63) != 0 } #[inline(always)] fn depends_on(&self, t: u8) -> bool { self.0 & (1u64 << t) != 0 } #[inline(always)] fn depends_on_full(&self, other: u64) -> bool { (self.dependencies() & other) != 0 } #[inline(always)] fn dependencies(&self) -> u64 { self.0 & ((1u64 << 56) - 1) } #[inline(always)] fn sort_idx(&self) -> u8 { ((self.0 >> 56) & 0x7F) as u8 } #[inline(always)] fn is_compatible_to(&self, other: &Self) -> bool { let diff = self.0 ^ other.0; let a = diff & !((1u64 << 56) - 1); let b = a & !(1u64 << 63); let c = self.0 & (1u64 << 63); (a == 0) || ((b == 0) && (c != 0)) } }