Finish hash/comparison functions
authorbdemsky <bdemsky@uci.edu>
Tue, 29 Aug 2017 03:22:08 +0000 (20:22 -0700)
committerbdemsky <bdemsky@uci.edu>
Tue, 29 Aug 2017 03:22:08 +0000 (20:22 -0700)
src/AST/asthash.cc
src/AST/boolean.cc
src/AST/element.cc

index c57ce90fa2549078c54fc305c6f157b8142a26e9..f2ed5ecc2fb00361594a2458fe345f1a1be17b5c 100644 (file)
@@ -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) {
 }
 
 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);
+       }
 }
 }
index 7949cdc16dc6cb3335ecd0f3de2e7ed4589c4c2d..6f2f4753bf2009bee5b31c6564710704750bdd7d 100644 (file)
@@ -9,8 +9,7 @@ Boolean::Boolean(ASTNodeType _type) :
        ASTNode(_type),
        polarity(P_UNDEFINED),
        boolVal(BV_UNDEFINED),
        ASTNode(_type),
        polarity(P_UNDEFINED),
        boolVal(BV_UNDEFINED),
-       parents(),
-       idNumber(0) {
+       parents() {
 }
 
 BooleanVar::BooleanVar(VarType t) :
 }
 
 BooleanVar::BooleanVar(VarType t) :
index 2efbf7d9a8cd9685d3550e90e37271abe197386b..e47d195eff65058896da811c77e90ef79c713c1f 100644 (file)
@@ -8,8 +8,7 @@
 
 Element::Element(ASTNodeType _type) :
        ASTNode(_type),
 
 Element::Element(ASTNodeType _type) :
        ASTNode(_type),
-       encoding(this),
-       idNumber(0) {
+       encoding(this) {
 }
 
 ElementSet::ElementSet(Set *s) :
 }
 
 ElementSet::ElementSet(Set *s) :