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
83
84
85
86
87
88
89
90
91
92
93
94
use super::*;
impl BddNode {
pub fn mk_zero(num_vars: u16) -> BddNode {
BddNode {
var: BddVariable(num_vars),
low_link: BddPointer::zero(),
high_link: BddPointer::zero(),
}
}
pub fn mk_one(num_vars: u16) -> BddNode {
BddNode {
var: BddVariable(num_vars),
low_link: BddPointer::one(),
high_link: BddPointer::one(),
}
}
pub fn mk_node(var: BddVariable, low_link: BddPointer, high_link: BddPointer) -> BddNode {
BddNode {
var,
low_link,
high_link,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
impl BddNode {
pub fn is_terminal(&self) -> bool {
self.low_link == self.high_link && (self.low_link.is_one() || self.low_link.is_zero())
}
pub fn is_one(&self) -> bool {
self.is_terminal() && self.low_link.is_one()
}
pub fn is_zero(&self) -> bool {
self.is_terminal() && self.low_link.is_zero()
}
}
#[test]
fn bdd_node_one() {
let one = BddNode::mk_one(2);
assert!(one.is_terminal());
assert!(one.is_one());
assert!(!one.is_zero());
assert_eq!(BddVariable(2), one.var);
}
#[test]
fn bdd_node_zero() {
let zero = BddNode::mk_zero(2);
assert!(zero.is_terminal());
assert!(zero.is_zero());
assert!(!zero.is_one());
assert_eq!(BddVariable(2), zero.var);
}
#[test]
fn bdd_node_create() {
let node = BddNode::mk_node(
BddVariable(4),
BddPointer::from_index(16),
BddPointer::zero(),
);
assert_eq!(BddPointer::from_index(16), node.low_link);
assert_eq!(BddPointer::zero(), node.high_link);
assert_eq!(BddVariable(4), node.var);
assert!(!node.is_terminal());
assert!(!node.is_one());
assert!(!node.is_zero());
}
}