Skip to content

Commit 244c29d

Browse files
committed
construction for neg bug fix
1 parent 8be0884 commit 244c29d

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

ROBDD.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "ROBDD.hpp"
22
#include <fstream>
3+
bool BDD_node::operator==(const BDD_node &rhs) const
4+
{
5+
return this->var == rhs.var && this->low == rhs.low && this->high == rhs.high;
6+
}
37
ROBDD::ROBDD()
48
{
59
this->zero = new BDD_node({0, nullptr, nullptr});
@@ -8,11 +12,11 @@ ROBDD::ROBDD()
812
this->node_table[*(this->one)] = this->one;
913
}
1014

11-
BDD_node* ROBDD::get_one() const
15+
BDD_node *ROBDD::get_one() const
1216
{
1317
return this->one;
1418
}
15-
BDD_node* ROBDD::get_zero() const
19+
BDD_node *ROBDD::get_zero() const
1620
{
1721
return this->zero;
1822
}
@@ -173,7 +177,6 @@ void ROBDD::output(std::ofstream &out)
173177
this->printed.clear();
174178
}
175179

176-
177180
void ROBDD::_output(BDD_node *node, std::ofstream &out)
178181
{
179182
// print node itself
@@ -187,7 +190,7 @@ void ROBDD::_output(BDD_node *node, std::ofstream &out)
187190
out << this->ID_to_var[node->var];
188191
else
189192
out << node->var;
190-
out << "\"]" << std::endl; // use label as node name
193+
out << "\"]" << std::endl; // use label as node name
191194
}
192195
// no subnodes
193196
if (node->var <= 1)

ROBDD.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct BDD_node
1717
// var = 0 and var = 1 reserved
1818
unsigned int var;
1919
BDD_node *low, *high;
20-
bool operator==(const BDD_node &rhs) const { return this->var == rhs.var && this->low == rhs.low && this->high == rhs.high; }
20+
bool operator==(const BDD_node &rhs) const;
2121
};
2222
struct ROBDD
2323
{
@@ -26,8 +26,8 @@ struct ROBDD
2626
{
2727
std::size_t operator()(const BDD_node &T) const
2828
{
29-
return std::hash<void *>()(static_cast<void *>(T.low))
30-
^ std::hash<void *>()(static_cast<void *>(T.high))
29+
return (std::hash<void *>()(static_cast<void *>(T.low)) // hash result affected by order
30+
- std::hash<void *>()(static_cast<void *>(T.high)))
3131
^ std::hash<int>()(T.var);
3232
}
3333
};
@@ -36,7 +36,7 @@ struct ROBDD
3636
std::size_t operator()(const std::pair<BDD_node *, BDD_node *> &T) const
3737
{
3838
return std::hash<void *>()(static_cast<void *>(T.first))
39-
^ std::hash<void *>()(static_cast<void *>(T.second));
39+
- std::hash<void *>()(static_cast<void *>(T.second));
4040
}
4141
};
4242
BDD_node *root;

expression.y

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func
4747
| term {$$ = $1;}
4848

4949
term
50-
: NOT atom {$$ = $2; auto tmp = $$->high; $$->high = $$->low; $$->low = tmp;}
50+
: NOT atom {$$ = T->make_node($2->var, $2->high, $2->low);}
5151
| atom {$$ = $1;}
5252

5353
atom

0 commit comments

Comments
 (0)