# HG changeset patch # User Claus Gittinger # Date 1412758187 -7200 # Node ID 8e30e6a52a64beed764e3f3fa0e27e2b0b7f0894 # Parent 247352d5de0f0b71235751a5cb4d6d3362e0ef26 class: CharacterArray added: #hash_fnv1a #hash_java diff -r 247352d5de0f -r 8e30e6a52a64 CharacterArray.st --- a/CharacterArray.st Sun Oct 05 00:36:59 2014 +0200 +++ b/CharacterArray.st Wed Oct 08 10:49:47 2014 +0200 @@ -283,7 +283,6 @@ "Created: 3.8.1997 / 18:16:40 / cg" ! ! - !CharacterArray class methodsFor:'cleanup'! lowSpaceCleanup @@ -327,7 +326,6 @@ " ! ! - !CharacterArray class methodsFor:'pattern matching'! matchEscapeCharacter @@ -725,7 +723,6 @@ ^ self == CharacterArray ! ! - !CharacterArray methodsFor:'Compatibility-ANSI'! addLineDelimiters @@ -2242,6 +2239,49 @@ "Created: / 26-12-2011 / 13:46:06 / cg" ! +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| + + h := 2166136261. + self do:[:eachChar | + h := h bitXor:(eachChar codePoint). + h := (h * 16777619) bitAnd:16rFFFFFFFF. + ]. + ^ h + + " + 'abc' hash_fnv1a + 'foofooHelloWorld' hash_fnv1a + 'blablaHelloWorld' hash_fnv1a + " +! + +hash_java + "return an integer useful as a hash-key. + This method uses the same algorithm as used in + the java virtual machine + (which is actually not a very good one)." + + |h| + + h := 0. + self do:[:eachChar | + h := (h * 31) + (eachChar codePoint). + h := h bitAnd:16rFFFFFFFF. + ]. + ^ h + + " + 'abc' hash_java + 'foofooHelloWorld' hash_java + 'blablaHelloWorld' hash_java + " +! + levenshteinTo:aString "return the levenshtein distance to the argument, aString; this value corresponds to the number of replacements that have to be @@ -4129,8 +4169,6 @@ ! ! - - !CharacterArray methodsFor:'matching - glob expressions'! compoundMatch:aString @@ -4814,7 +4852,6 @@ ! ! - !CharacterArray methodsFor:'padded copying'! centerPaddedTo:newSize @@ -7004,15 +7041,14 @@ ^ aVisitor visitString:self with:aParameter ! ! - !CharacterArray class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.543 2014-10-03 01:48:38 vrany Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.544 2014-10-08 08:49:47 cg Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.543 2014-10-03 01:48:38 vrany Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.544 2014-10-08 08:49:47 cg Exp $' ! !