CharacterArray: Do not stop FNV1A hash computation on nul chararacter jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 23 Jun 2016 23:30:33 +0100
branchjv
changeset 20029 5298074580d5
parent 20020 34c8b56353bd
child 20073 17bf4a096c2e
CharacterArray: Do not stop FNV1A hash computation on nul chararacter ...since the String>>hash doesn't! Both algorithms MUST match otherwise bad things happens: `'abc' hash ~~ 'abc' asUnicode16String hash`. This problem was introduced by change in eXept's code that tries to fix issue #65 differently. In jv-branch it was fixed a loong time before in 8735bd9eee2f/stx.libbasic. But well, eXept apparenly ignored this.
CharacterArray.st
--- a/CharacterArray.st	Fri Jun 17 16:50:05 2016 +0100
+++ b/CharacterArray.st	Thu Jun 23 23:30:33 2016 +0100
@@ -307,6 +307,7 @@
     "Created: / 09-01-2011 / 10:37:57 / cg"
 ! !
 
+
 !CharacterArray class methodsFor:'Compatibility-VW'!
 
 fromIntegerArray: anArray
@@ -550,7 +551,6 @@
     "
 ! !
 
-
 !CharacterArray class methodsFor:'pattern matching'!
 
 matchEscapeCharacter
@@ -967,6 +967,7 @@
     "Modified: / 13.11.2001 / 19:16:25 / cg"
 ! !
 
+
 !CharacterArray methodsFor:'Compatibility-Dolphin'!
 
 copyExpanding:expandTable
@@ -2535,22 +2536,16 @@
     "return an integer useful as a hash-key.
      This method uses the fnv-1a algorithm
      (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)"
+                (so hash values are independent from the architecture)"
 
     |h byte|
 
     h := 2166136261.
     self do:[:eachChar |
-	byte := eachChar codePoint.
-	byte == 0 ifTrue:[
-	    "/ stop
-	    ^ (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF.
-	].
-	h := h bitXor:byte.
-	h := (h * 16777619) bitAnd:16rFFFFFFFF.
+        byte := eachChar codePoint.
+        h := h bitXor:byte.
+        h := (h * 16777619) bitAnd:16rFFFFFFFF.
     ].
     "/ make sure, it fits into a smallInt
     h := (h bitXor: (h >> 30)) bitAnd: 16r3FFFFFFF.
@@ -2569,6 +2564,8 @@
      'blablaHelloWorld' asUnicode16String hash_fnv1a
      'blablaHelloWorld' asUnicode32String hash_fnv1a
     "
+
+    "Modified: / 23-06-2016 / 23:15:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 hash_java
@@ -6241,7 +6238,6 @@
     "Modified: 17.4.1997 / 12:50:23 / cg"
 ! !
 
-
 !CharacterArray methodsFor:'special string converting'!
 
 asUnixFilenameString
@@ -7289,7 +7285,6 @@
     "
 ! !
 
-
 !CharacterArray methodsFor:'substring searching'!
 
 findRangeOfString:subString