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
73
74
75
76
77
78
79
80
81
82
use super::*;
use std::fmt::{Display, Error, Formatter};
impl Display for BddPointer {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_fmt(format_args!("{}", self.0))
}
}
impl BddPointer {
pub fn zero() -> BddPointer {
BddPointer(0)
}
pub fn one() -> BddPointer {
BddPointer(1)
}
pub fn is_zero(&self) -> bool {
self.0 == 0
}
pub fn is_one(&self) -> bool {
self.0 == 1
}
pub fn is_terminal(&self) -> bool {
self.0 < 2
}
pub fn to_index(self) -> usize {
self.0 as usize
}
pub fn from_index(index: usize) -> BddPointer {
BddPointer(index as u32)
}
pub fn from_bool(value: bool) -> BddPointer {
if value {
BddPointer::one()
} else {
BddPointer::zero()
}
}
pub fn as_bool(&self) -> Option<bool> {
match self.0 {
0 => Some(false),
1 => Some(true),
_ => None,
}
}
pub fn flip_if_terminal(&mut self) {
if self.0 < 2 {
self.0 = (self.0 + 1) % 2;
}
}
pub fn to_le_bytes(self) -> [u8; 4] {
self.0.to_le_bytes()
}
pub fn from_le_bytes(bytes: [u8; 4]) -> BddPointer {
BddPointer(u32::from_le_bytes(bytes))
}
}