Adjusted ImutAVLTree::ComputeHash to compute a hash value that is based on a
authorTed Kremenek <kremenek@apple.com>
Mon, 21 Jan 2008 22:50:37 +0000 (22:50 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 21 Jan 2008 22:50:37 +0000 (22:50 +0000)
clearer sequence of hashing compositions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46227 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/ImmutableSet.h

index 5118b0d33696a0c52d377ef5dc0c88b219ffa352..856667d1219069a66c976c77cc97aa68db9e73d6 100644 (file)
@@ -210,11 +210,24 @@ private:
   unsigned ComputeHash(ImutAVLTree* L, ImutAVLTree* R, value_type_ref V) {
     FoldingSetNodeID ID;
     
-    ID.AddInteger(L ? L->ComputeHash() : 0);
+    if (L) ID.AddInteger(L->ComputeHash());
     ImutInfo::Profile(ID,V);
-    ID.AddInteger(R ? R->ComputeHash() : 0);
     
-    return ID.ComputeHash();    
+    // Compute the "intermediate" hash.  Basically, we want the net profile to
+    // be:  H(H(....H(H(H(item0),item1),item2)...),itemN), where
+    //  H(item) is the hash of the data item and H(hash,item) is a hash
+    //  of the last item hash and the the next item.
+    
+    unsigned X = ID.ComputeHash();
+    ID.clear();
+    
+    if (R) {
+      ID.AddInteger(X);
+      ID.AddInteger(R->ComputeHash());
+      X = ID.ComputeHash();
+    }
+    
+    return X;
   }
   
   inline unsigned ComputeHash() {