#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Sat, 07 May 2016 13:19:22 +0200
changeset 19743 b5c295a51c56
parent 19742 3625237bc6d7
child 19744 f64dd57ad912
#BUGFIX by cg class: CharacterArray changed: #hash_fnv1a make sure that hash returns the same value as the VM when 0-bytes are in the string. (which stops at 0-bytes).
CharacterArray.st
--- a/CharacterArray.st	Sat May 07 13:03:22 2016 +0200
+++ b/CharacterArray.st	Sat May 07 13:19:22 2016 +0200
@@ -2344,14 +2344,23 @@
 hash_fnv1a
     "return an integer useful as a hash-key.
      This method uses the fnv-1a algorithm
-     (which is actually a very good one)"
-
-    |h|
+     (which is actually a very good one).
+     Attention: stops when a 0-codepoint is encountered
+                (for compatibility with the hash used by the VM)
+     Also: on 64bit CPUs, only small 4-byte hashvalues are returned,
+                (so hash values are independent from the architecture)"
+
+    |h byte|
 
     h := 2166136261.
     self do:[:eachChar |
-	h := h bitXor:(eachChar codePoint).
-	h := (h * 16777619) bitAnd:16rFFFFFFFF.
+        byte := eachChar codePoint.
+        byte == 0 ifTrue:[
+            "/ stop
+            ^ (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF.
+        ].    
+        h := h bitXor:byte.
+        h := (h * 16777619) bitAnd:16rFFFFFFFF.
     ].
     "/ make sure, it fits into a smallInt
     h := (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF.