evaluate method
Evaluate the logic value of a given CompressTerm.
Implementation
LogicValue evaluate() {
late LogicValue value;
switch (type) {
case CompressTermType.pp:
value = logic.value;
case CompressTermType.sum:
// xor the eval of the terms
final termValues = [for (final term in inputs) term.evaluate()];
final sum = termValues.swizzle().xor();
value = sum;
case CompressTermType.carry:
final termValues = [for (final term in inputs) term.evaluate()];
final termValuesInt = [
for (var i = 0; i < termValues.length; i++) termValues[i].toInt()
];
final count = (termValuesInt.isNotEmpty)
? termValuesInt.reduce((c, term) => c + term)
: 0;
final majority =
(count > termValues.length ~/ 2 ? LogicValue.one : LogicValue.zero);
value = majority;
}
return value;
}