From: bdemsky Date: Tue, 29 Aug 2017 03:22:08 +0000 (-0700) Subject: Finish hash/comparison functions X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=commitdiff_plain;h=d6e2d6263454c904c27f739f199812d440b7c1f4 Finish hash/comparison functions --- diff --git a/src/AST/asthash.cc b/src/AST/asthash.cc index c57ce90..f2ed5ec 100644 --- a/src/AST/asthash.cc +++ b/src/AST/asthash.cc @@ -97,8 +97,47 @@ bool compareBoolean(Boolean *b1, Boolean *b2) { } } -uint hashElement(Element *element) { +uint hashElement(Element *e) { + switch(e->type) { + case ELEMSET: { + return (uint)(uintptr_t) e; + } + case ELEMFUNCRETURN: { + ElementFunction * ef=(ElementFunction *) e; + return ((uint)(uintptr_t) ef->function) ^ + ((uint)(uintptr_t) ef->overflowstatus) ^ + hashArray(&ef->inputs); + } + case ELEMCONST: { + ElementConst * ec=(ElementConst *) e; + return ((uint)(uintptr_t) ec->set) ^ ((uint) ec->value); + } + default: + ASSERT(0); + } } bool compareElement(Element *e1, Element *e2) { + if (e1->type != e2->type) + return false; + switch(e1->type) { + case ELEMSET: { + return e1 == e2; + } + case ELEMFUNCRETURN: { + ElementFunction * ef1=(ElementFunction *) e1; + ElementFunction * ef2=(ElementFunction *) e2; + return (ef1->function == ef2->function) && + (ef1->overflowstatus == ef2->overflowstatus) && + compareArray(&ef1->inputs, &ef2->inputs); + } + case ELEMCONST: { + ElementConst * ec1=(ElementConst *) e1; + ElementConst * ec2=(ElementConst *) e2; + return (ec1->set == ec2->set) && + (ec1->value == ec2->value); + } + default: + ASSERT(0); + } } diff --git a/src/AST/boolean.cc b/src/AST/boolean.cc index 7949cdc..6f2f475 100644 --- a/src/AST/boolean.cc +++ b/src/AST/boolean.cc @@ -9,8 +9,7 @@ Boolean::Boolean(ASTNodeType _type) : ASTNode(_type), polarity(P_UNDEFINED), boolVal(BV_UNDEFINED), - parents(), - idNumber(0) { + parents() { } BooleanVar::BooleanVar(VarType t) : diff --git a/src/AST/element.cc b/src/AST/element.cc index 2efbf7d..e47d195 100644 --- a/src/AST/element.cc +++ b/src/AST/element.cc @@ -8,8 +8,7 @@ Element::Element(ASTNodeType _type) : ASTNode(_type), - encoding(this), - idNumber(0) { + encoding(this) { } ElementSet::ElementSet(Set *s) :