Skip to content

Commit 41cbf61

Browse files
author
Gaetan Renaudeau
committed
Bugfix ftree to dot : handle NOT node
1 parent 921295b commit 41cbf61

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

ftree.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* - if type is variable : val is the variable litteral as int value in ascii table. Exemple: x variable is 120 (btw 120=='x')
1616
* - if type is operator : the operator enum value
1717
* left : the left child if exists
18-
* right : the right child if exists
18+
* right : the right child if exists, unused for NOT node
1919
*/
2020
struct _FunctionNode {
2121
NodeType type;
@@ -210,39 +210,31 @@ TruthTable* ftree_toTruthTable(FunctionTree* ftree, char* vars) {
210210
return table;
211211
}
212212

213-
FunctionTree* ftree_simplify(FunctionTree* ftree) {
214-
// TODO
215-
216-
return ftree;
217-
}
218-
219213

220214
/**
221215
* id = 1 at first call
222216
*/
223-
static void rec_ftree_printDot(FunctionNode* node, FILE* out, int id) {
224-
int lid, rid;
217+
static void rec_ftree_printDot(FunctionNode* node, FILE* out) {
225218
if(node==0) return;
226219
if(node->type==NodeType_VALUE) {
227-
fprintf(out, " n%d [label=\"%d\"]\n", id, node->val);
220+
fprintf(out, " n%p [label=\"%d\"]\n", node, node->val);
228221
}
229222
else if(node->type==NodeType_VARIABLE) {
230-
fprintf(out, " n%d [label=\"%c\"]\n", id, (char)node->val);
223+
fprintf(out, " n%p [label=\"%c\"]\n", node, (char)node->val);
231224
}
232225
else if(node->type==NodeType_OPERATOR) {
233-
lid = 2*id;
234-
rid = 2*id+1;
235-
fprintf(out, " n%d [label=\"%c\"]\n", id, ftree_operatorToChar(node->val));
236-
fprintf(out, " n%d -- n%d\n", id, lid);
237-
fprintf(out, " n%d -- n%d\n", id, rid);
238-
rec_ftree_printDot(node->left, out, lid);
239-
rec_ftree_printDot(node->right, out, rid);
226+
fprintf(out, " n%p [label=\"%c\"]\n", node, ftree_operatorToChar(node->val));
227+
fprintf(out, " n%p -- n%p\n", node, node->left);
228+
if(node->val != Op_NOT)
229+
fprintf(out, " n%p -- n%p\n", node, node->right);
230+
rec_ftree_printDot(node->left, out);
231+
rec_ftree_printDot(node->right, out);
240232
}
241233
}
242234

243235
void ftree_printDot(FunctionTree* ftree, FILE* out) {
244236
fprintf(out, "## Generated by Boolean Functions v%g\n", VERSION);
245237
fprintf(out, "graph {\n");
246-
rec_ftree_printDot(ftree->root, out, 1);
238+
rec_ftree_printDot(ftree->root, out);
247239
fprintf(out, "}\n");
248240
}

ftree.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ FunctionTree* ftree_createWithNode(FunctionNode* node);
2525

2626
FunctionTree* ftree_clone(FunctionTree* node);
2727

28-
FunctionTree* ftree_fromExpression(char*);
29-
3028
void ftree_free(FunctionTree*);
3129

3230
void ftree_normalize(FunctionTree*);
@@ -45,7 +43,5 @@ FunctionNode* ftree_newBool(int b);
4543
FunctionNode* ftree_newVar(char s);
4644
FunctionTree* ftree_createWithNode(FunctionNode* node);
4745

48-
49-
FunctionTree* ftree_simplify(FunctionTree* ftree);
5046
#endif
5147

function.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ Function* function_createWithFunctionTree(FunctionTree* tree) {
6262
f -> tree = tree;
6363
f -> vars = ftree_getVars(tree);
6464
f -> table = ftree_toTruthTable(tree, f->vars);
65-
f -> fmd = ftree_simplify(btable_toFunctionTree(f->table, f->vars));
65+
f -> fmd = (btable_toFunctionTree(f->table, f->vars));
6666
f -> btree = btree_simplify(btable_toBoolTree(f->table, f->vars));
67+
// f -> fmd = btree_toFunctionTree(f->btree); // TODO
6768
return f;
6869
}
6970

@@ -72,8 +73,9 @@ Function* function_createWithTruthTable(TruthTable* table) {
7273
f -> table = table;
7374
f -> vars = btable_generateVars(table);
7475
f -> tree = btable_toFunctionTree(f->table, f->vars);
75-
f -> fmd = ftree_simplify(ftree_clone(f->tree));
76+
f -> fmd = (ftree_clone(f->tree));
7677
f -> btree = btree_simplify(btable_toBoolTree(f->table, f->vars));
78+
// f -> fmd = btree_toFunctionTree(f->btree); // TODO
7779
return f;
7880
}
7981

0 commit comments

Comments
 (0)