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