From cde176a0b7d62fd76ccce12fad50d115cd6e240d Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 14 Sep 2012 12:26:48 +0200 Subject: [PATCH] migScope/tools/truthtable.py: add function to remove duplicate operands --- migScope/tools/truthtable.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/migScope/tools/truthtable.py b/migScope/tools/truthtable.py index ed53e2d3..d38316b9 100644 --- a/migScope/tools/truthtable.py +++ b/migScope/tools/truthtable.py @@ -2,8 +2,14 @@ import os import re import sys +def remove_duplicates(seq): + seen = set() + seen_add = seen.add + return [ x for x in seq if x not in seen and not seen_add(x)] + def get_operands(s): - return sorted(re.findall("[A-z0-9_]+", s)) + operands = remove_duplicates(sorted(re.findall("[A-z0-9_]+", s))) + return operands def gen_truth_table(s): operands = get_operands(s) @@ -19,7 +25,7 @@ def gen_truth_table(s): for i in range(2**width): for j in range(width): exec("%s = stim[j][i]" %operands[j]) - truth_table.append(eval(s)) + truth_table.append(eval(s) != 0) return truth_table def main(): -- 2.30.2