}
// Get structurally hashed version of the node.
-BEEV::ASTNode HashingNodeFactory::CreateNode(const Kind kind, const BEEV::ASTVec & back_children)
+BEEV::ASTNode HashingNodeFactory::CreateNode(const Kind kind, const BEEV::ASTVec & back_children)
{
- // create a new node. Children will be modified.
- ASTInterior *n_ptr = new ASTInterior(kind);
-
- ASTVec children(back_children);
+ // We can't create NOT(NOT (..)) nodes because of how the numbering scheme we use works.
+ // So you can't trust the hashiing node factory even to return nodes of the same kind that
+ // you ask for.
+ if (kind == BEEV::NOT && back_children[0].GetKind() == BEEV::NOT)
+ {
+ return back_children[0][0];
+ }
+
+ ASTVec children(back_children);
// The Bitvector solver seems to expect constants on the RHS, variables on the LHS.
// We leave the order of equals children as we find them.
if (BEEV::isCommutative(kind) && kind != BEEV::AND)
SortByArith(children);
}
- // We can't create NOT(NOT (..)) nodes because of how the numbering scheme we use works.
- // So you can't trust the hashiing node factory even to return nodes of the same kind that
- // you ask for.
- if (kind == BEEV::NOT && children[0].GetKind() == BEEV::NOT)
- {
- delete n_ptr;
- return children[0][0];
- }
-
- // insert all of children at end of new_children.
- ASTNode n(bm.CreateInteriorNode(kind, n_ptr, children));
+ ASTInterior *n_ptr = new ASTInterior(kind,children);
+ ASTNode n(bm.LookupOrCreateInterior(n_ptr));
return n;
}