Fixing the performance bug
[satune.git] / src / Collections / structs.cc
index 96b85e7dc1aedb6fd9ae8228ed63f31582777af4..ac69f9d53bef7afec830d2da3797ab96b5f33581 100644 (file)
@@ -6,13 +6,17 @@
 #include "ordergraph.h"
 #include "orderelement.h"
 #include "structs.h"
+#include "decomposeorderresolver.h"
+
+#define HASHNEXT(hash, newval) {hash+=newval; hash += hash << 10; hash ^= hash >>6;}
+#define HASHFINAL(hash) {hash += hash <<3; hash ^= hash >> 11; hash += hash << 15;}
 
 unsigned int table_entry_hash_function(TableEntry *This) {
        unsigned int h = 0;
        for (uint i = 0; i < This->inputSize; i++) {
-               h += This->inputs[i];
-               h *= 31;
+               HASHNEXT(h, This->inputs[i]);
        }
+       HASHFINAL(h);
        return h;
 }
 
@@ -25,16 +29,20 @@ bool table_entry_equals(TableEntry *key1, TableEntry *key2) {
        return true;
 }
 
-unsigned int order_node_hash_function(OrderNode *This) {
+unsigned int order_node_hash_function(OrderNodeKey *This) {
        return (uint) This->id;
 }
 
-bool order_node_equals(OrderNode *key1, OrderNode *key2) {
+bool order_node_equals(OrderNodeKey *key1, OrderNodeKey *key2) {
        return key1->id == key2->id;
 }
 
 unsigned int order_edge_hash_function(OrderEdge *This) {
-       return (uint) (((uintptr_t)This->sink) ^ ((uintptr_t)This->source << 4));
+       uint hash=0;
+       HASHNEXT(hash, (uint)(uintptr_t) This->sink);
+       HASHNEXT(hash, (uint)(uintptr_t) This->source);
+       HASHFINAL(hash);
+       return hash;
 }
 
 bool order_edge_equals(OrderEdge *key1, OrderEdge *key2) {
@@ -50,9 +58,26 @@ bool order_element_equals(OrderElement *key1, OrderElement *key2) {
 }
 
 unsigned int order_pair_hash_function(OrderPair *This) {
-       return (uint) (This->first << 2) ^ This->second;
+       uint hash=0;
+       HASHNEXT(hash, This->first);
+       HASHNEXT(hash, This->second);
+       HASHFINAL(hash);
+       return hash;
 }
 
 bool order_pair_equals(OrderPair *key1, OrderPair *key2) {
        return key1->first == key2->first && key1->second == key2->second;
 }
+
+unsigned int doredge_hash_function(DOREdge *key) {
+       uint hash=0;
+       HASHNEXT(hash, (uint) key->newfirst);
+       HASHNEXT(hash, (uint) key->newsecond);
+       HASHFINAL(hash);
+       return hash;
+}
+
+bool doredge_equals(DOREdge *key1, DOREdge *key2) {
+       return key1->newfirst == key2->newfirst &&
+                                key1->newsecond == key2->newsecond;
+}