Using hashset for tableEntries + adding handlers for different undefBehaviors for...
[satune.git] / src / Collections / structs.c
index 64821c9513a5020bee96da921ebae4c01953cf7e..3bd5e4a76d765510bc916a0e2462a2e351af0433 100644 (file)
@@ -1,6 +1,7 @@
 #include "structs.h"
 #include "mymemory.h"
 #include "orderpair.h"
+#include "tableentry.h"
 
 VectorImpl(Table, Table *, 4);
 VectorImpl(Set, Set *, 4);
@@ -29,4 +30,27 @@ static inline unsigned int order_pair_equals(OrderPair* key1, OrderPair* key2){
        return key1->first== key2->first && key1->second == key2->second;
 }
 
+static inline unsigned int table_entry_hash_Function(TableEntry* This){
+       //http://isthe.com/chongo/tech/comp/fnv/
+       unsigned int h = 2166136261;
+       const unsigned int FNV_PRIME = 16777619;
+       for(uint i=0; i<This->inputSize; i++){
+               h ^= This->inputs[i];
+               h *= FNV_PRIME;
+       }
+       return h;
+}
+
+static inline bool table_entry_equals(TableEntry* key1, TableEntry* key2){
+       if(key1->inputSize != key2->inputSize)
+               return false;
+       for(uint i=0; i<key1->inputSize; i++)
+               if(key1->inputs[i]!=key2->inputs[i])
+                       return false;
+       return true;
+}
+
 HashTableImpl(OrderPair, OrderPair *, OrderPair *, order_pair_hash_Function, order_pair_equals, ourfree);
+HashSetImpl(TableEntry, TableEntry*, table_entry_hash_Function, table_entry_equals);
+
+