Improve hash function to fix collision problem
authorbdemsky <bdemsky@uci.edu>
Tue, 24 Oct 2017 02:36:35 +0000 (19:36 -0700)
committerbdemsky <bdemsky@uci.edu>
Tue, 24 Oct 2017 02:36:35 +0000 (19:36 -0700)
src/Backend/constraint.cc
src/Test/Makefile
src/csolver.cc

index 7c3a094701d3c12ffa08d5a3fba5c83dd6b3f4d8..b7cb320e2a9da41473d260e09a27940c1360f174 100644 (file)
@@ -146,12 +146,19 @@ Edge createNode(CNF *cnf, NodeType type, uint numEdges, Edge *edges) {
 }
 
 uint hashNode(NodeType type, uint numEdges, Edge *edges) {
-       uint hashvalue = type ^ numEdges;
+       uint hash = type;
+       hash += hash << 10;
+       hash ^= hash >> 6;
        for (uint i = 0; i < numEdges; i++) {
-               hashvalue ^= (uint) ((uintptr_t) edges[i].node_ptr);
-               hashvalue = (hashvalue << 3) | (hashvalue >> 29);       //rotate left by 3 bits
-       }
-       return (uint) hashvalue;
+               uint c = (uint) ((uintptr_t) edges[i].node_ptr);
+               hash += c;
+               hash += hash << 10;
+               hash += hash >> 6;
+       }
+       hash += hash << 3;
+       hash ^= hash >> 11;
+       hash += hash << 15;
+       return hash;
 }
 
 bool compareNodes(Node *node, NodeType type, uint numEdges, Edge *edges) {
index 0f1bc39a80de5ebd6b4f31b2314633c18250ca3b..5ec798914b18aa446f9922a6fc31727dd57e3516 100644 (file)
@@ -6,7 +6,7 @@ include $(BASE)/common.mk
 
 DEPS := $(join $(addsuffix ., $(dir $(OBJECTS))), $(addsuffix .d, $(notdir $(OBJECTS))))
 
-CPPFLAGS += -I$(BASE) -I$(BASE)/AST -I$(BASE)/Collections -I$(BASE)/Backend
+CPPFLAGS += -I$(BASE) -I$(BASE)/AST -I$(BASE)/Collections -I$(BASE)/Backend -I$(BASE)/Tuner
 
 all: $(OBJECTS) ../bin/run.sh
 
index 95c06f8568ec9e4da27e2704a9f1348c85baf51a..533fc4b8dfd0023c3b66498c898599056fb7b2c4 100644 (file)
@@ -465,7 +465,6 @@ int CSolver::solve() {
                tuner = new DefaultTuner();
                deleteTuner = true;
        }
-       serialize();
        
        long long startTime = getTimeNano();
        computePolarities(this);