7 #define HASHNEXT(hash, newval) {hash += newval; hash += hash << 10; hash ^= hash >> 6;}
8 #define HASHFINAL(hash) {hash += hash << 3; hash ^= hash >> 11; hash += hash << 15;}
10 bool compareArray(Array<BooleanEdge> *inputs1, Array<BooleanEdge> *inputs2) {
11 if (inputs1->getSize() != inputs2->getSize())
13 for (uint i = 0; i < inputs1->getSize(); i++) {
14 if (inputs1->get(i) != inputs2->get(i))
20 bool compareArray(Array<Element *> *inputs1, Array<Element *> *inputs2) {
21 if (inputs1->getSize() != inputs2->getSize())
23 for (uint i = 0; i < inputs1->getSize(); i++) {
24 if (inputs1->get(i) != inputs2->get(i))
30 uint hashArray(Array<BooleanEdge> *inputs) {
32 for (uint i = 0; i < inputs->getSize(); i++) {
33 uint newval = (uint)(uintptr_t) inputs->get(i).getRaw();
34 HASHNEXT(hash, newval);
40 uint hashArray(Array<Element *> *inputs) {
42 for (uint i = 0; i < inputs->getSize(); i++) {
43 uint newval = (uint)(uintptr_t) inputs->get(i);
44 HASHNEXT(hash, newval);
50 uint hashBoolean(Boolean *b) {
53 BooleanOrder *o = (BooleanOrder *)b;
55 HASHNEXT(hash, (uint) o->first);
56 HASHNEXT(hash, (uint) o->second);
57 HASHNEXT(hash, (((uint)(uintptr_t) o->order) & 0xffff));
63 return (uint)(uintptr_t) b;
66 BooleanLogic *l = (BooleanLogic *)b;
67 return ((uint)l->op) + 43 * hashArray(&l->inputs);
70 BooleanPredicate *p = (BooleanPredicate *)b;
72 HASHNEXT(hash, hashArray(&p->inputs));
73 HASHNEXT(hash, (uint)(uintptr_t) p->predicate);
74 HASHNEXT(hash, (uint)(uintptr_t) p->undefStatus);
83 bool compareBoolean(Boolean *b1, Boolean *b2) {
84 if (b1->type != b2->type)
88 BooleanOrder *o1 = (BooleanOrder *)b1;
89 BooleanOrder *o2 = (BooleanOrder *)b2;
90 return (o1->order == o2->order) && (o1->first == o2->first) && (o1->second == o2->second);
96 BooleanLogic *l1 = (BooleanLogic *)b1;
97 BooleanLogic *l2 = (BooleanLogic *)b2;
98 return (l1->op == l2->op) && compareArray(&l1->inputs, &l2->inputs);
101 BooleanPredicate *p1 = (BooleanPredicate *)b1;
102 BooleanPredicate *p2 = (BooleanPredicate *)b2;
103 return (p1->predicate == p2->predicate) &&
104 p1->undefStatus == p2->undefStatus &&
105 compareArray(&p1->inputs, &p2->inputs);
112 uint hashElement(Element *e) {
115 return (uint)(uintptr_t) e;
117 case ELEMFUNCRETURN: {
118 ElementFunction *ef = (ElementFunction *) e;
120 HASHNEXT(hash, hashArray (&ef->inputs));
121 HASHNEXT(hash, (uint)(uintptr_t) ef->getFunction());
122 HASHNEXT(hash, (uint)(uintptr_t) ef->overflowstatus);
127 ElementConst *ec = (ElementConst *) e;
128 return ((uint) ec->value);
135 bool compareElement(Element *e1, Element *e2) {
136 if (e1->type != e2->type)
142 case ELEMFUNCRETURN: {
143 ElementFunction *ef1 = (ElementFunction *) e1;
144 ElementFunction *ef2 = (ElementFunction *) e2;
145 return (ef1->getFunction() == ef2->getFunction()) &&
146 (ef1->overflowstatus == ef2->overflowstatus) &&
147 compareArray(&ef1->inputs, &ef2->inputs);
150 ElementConst *ec1 = (ElementConst *) e1;
151 ElementConst *ec2 = (ElementConst *) e2;
152 return (ec1->value == ec2->value);