|
@@ -3,14 +3,15 @@ use crate::{gate::Gate, gate_type::GateType};
|
3
|
3
|
#[derive(Debug, Clone)]
|
4
|
4
|
pub struct Circuit {
|
5
|
5
|
pub gates: Vec<Gate>, // All gates
|
|
6
|
+ pub input_bits: Vec<bool>,
|
6
|
7
|
}
|
7
|
8
|
|
8
|
9
|
impl Circuit {
|
9
|
|
- pub fn eval(self, input_bits: Vec<bool>,) -> bool {
|
|
10
|
+ pub fn eval(self, ) -> bool {
|
10
|
11
|
let mut evaluated_gates = vec![];
|
11
|
12
|
|
12
|
13
|
for gate in self.gates {
|
13
|
|
- let result = gate.eval(&input_bits, &evaluated_gates);
|
|
14
|
+ let result = gate.eval(&self.input_bits, &evaluated_gates);
|
14
|
15
|
evaluated_gates.push(result);
|
15
|
16
|
}
|
16
|
17
|
|
|
@@ -24,7 +25,7 @@ impl Circuit {
|
24
|
25
|
This method should create a circuit that outputs 1 if the first number A (encoded in the first n
|
25
|
26
|
bits) is greater than the second number B (encoded in the next n bits) .
|
26
|
27
|
*/
|
27
|
|
- pub fn compare_n_bit_numbers( n: usize) -> Self {
|
|
28
|
+ pub fn compare_n_bit_numbers( n: usize, input_bits: Vec<bool>,) -> Self {
|
28
|
29
|
|
29
|
30
|
/*
|
30
|
31
|
base case n=1: 1-bit:
|
|
@@ -69,7 +70,7 @@ impl Circuit {
|
69
|
70
|
*/
|
70
|
71
|
|
71
|
72
|
let gates = create_n_bit_comparator_gates(n);
|
72
|
|
- return Circuit { gates };
|
|
73
|
+ return Circuit { gates, input_bits };
|
73
|
74
|
}
|
74
|
75
|
}
|
75
|
76
|
|