diff -r 77ab35cd09a5 -r 08bfe7364c0f CharacterArray.st --- a/CharacterArray.st Fri Sep 07 14:53:25 2007 +0200 +++ b/CharacterArray.st Fri Sep 07 14:54:01 2007 +0200 @@ -1738,62 +1738,39 @@ hash "return an integer useful as a hash-key" -%{ /* NOCONTEXT */ - - REGISTER unsigned g, val; - REGISTER unsigned char *cp, *cp0; - int l; - - cp = __stringVal(self); - l = __stringSize(self); - if (__qClass(self) != @global(String)) { - int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars)); - - cp += n; - l -= n; - } - - /* - * this is the dragon-book algorithm - */ - - val = 0; - switch (l) { - default: - for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) { - val = (val << 4) + *cp; - if (g = (val & 0xF0000000)) { - val ^= g >> 24; - val ^= g; - } - } - break; - case 7: - val = cp[6] << 4; - case 6: - val = (val + cp[5]) << 4; - case 5: - val = (val + cp[4]) << 4; - case 4: - val = (val + cp[3]) << 4; - case 3: - val = (val + cp[2]) << 4; - case 2: - val = (val + cp[1]) << 4; - case 1: - val = val + cp[0]; - case 0: - break; - } - - /* - * multiply by large prime to spread values - * This speeds up Set and Dictionary by a factor of 10! - */ - val *= 31415821; - RETURN ( __mkSmallInteger(val & 0x3fffffff)); -%} - + |h g| + + "/ + "/ this is the dragon-book algorithm + "/ + h := 0. + self reverseDo:[:char | + h := (h bitShift:4) + char asciiValue. + h := h bitAnd:16rFFFFFFFF. + g := (h bitAnd: 16rF0000000). + g ~~ 0 ifTrue:[ + h := h bitXor:(g bitShift:-24). + h := h bitXor:g. + ] + ]. + "/ + "/ multiply by large prime to spread values + "/ This speeds up Set and Dictionary by a factor of 10!! + "/ + h := h * 31415821. + h := h bitAnd:16r3fffffff. + ^ h + + " + 'a' hash + 'a' asUnicode16String hash + 'aa' hash + 'aa' asUnicode16String hash + 'ab' hash + 'ab' asUnicode16String hash + 'ab' hash + 'ab' asArray hash + " ! sameAs:aString @@ -3813,7 +3790,6 @@ "Modified: 17.4.1997 / 12:50:23 / cg" ! ! - !CharacterArray methodsFor:'special string converting'! chopTo:maxLen @@ -5278,7 +5254,7 @@ !CharacterArray class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.360 2007-07-28 18:09:44 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.361 2007-09-07 12:54:01 sr Exp $' ! ! CharacterArray initialize!