#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Thu, 07 Apr 2016 14:36:35 +0200
changeset 19554 91ec8f105783
parent 19553 a1e1e8901461
child 19555 29a4c770f926
#REFACTORING by stefan class: UninterpretedBytes added: #hash better hashing than inherited method from SequenceableCollection comment/format in: #computeXorHashFrom:to:
UninterpretedBytes.st
--- a/UninterpretedBytes.st	Thu Apr 07 14:35:11 2016 +0200
+++ b/UninterpretedBytes.st	Thu Apr 07 14:36:35 2016 +0200
@@ -467,7 +467,6 @@
     "Modified: / 5.3.1998 / 14:56:22 / stefan"
 ! !
 
-
 !UninterpretedBytes methodsFor:'Compatibility'!
 
 doubleWordAt:index
@@ -4235,6 +4234,25 @@
      #[1 2 3 4 1 2 3 4] computeXorHashFrom:1 to:8.
      #[1 2 3 4 5 6 7 8] computeXorHashFrom:2 to:8.
      #[2 3 4 5 6 7 8] computeXorHashFrom:1 to:7.
+     #[2 3 4 5 6 7 8] computeXorHashFrom:1 to:8.
+    "
+!
+
+hash
+    |sz|
+
+    sz := self size.
+    sz <= 32 ifTrue:[
+        ^ self computeXorHashFrom:1 to:sz.
+    ].
+    ^ (sz bitXor:(self computeXorHashFrom:1 to:16)) bitXor:(self computeXorHashFrom:sz-16 to:sz)   
+
+    "
+        #[1 2 3 4] hash
+        #[1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
+          1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 ] hash
+        #[1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
+          1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1] hash
     "
 ! !