--- a/Symbol.st Sun Jan 13 12:28:36 2013 +0000
+++ b/Symbol.st Tue Jan 15 16:00:19 2013 +0100
@@ -184,7 +184,6 @@
! !
-
!Symbol methodsFor:'Compatibility-Squeak'!
isUnary
@@ -325,123 +324,116 @@
%{ /* NOCONTEXT */
/* for now, this is needed... */
-#define xxHASH_SDBM
-#define HASH_DRAGONBOOK
+#undef HASH_DRAGONBOOK
+#define HASH_SDBM
REGISTER unsigned INT val;
- REGISTER unsigned char *cp, *ce;
+ REGISTER unsigned char *cp;
int l;
- if (__Class(self) == Symbol) {
- val = __GET_HASH(self);
- /*
- * only do it, if I have no standard hash key
- * assigned (which can only happen due to a #become:,
- * or by creating a symbol uninterned, and interning it
- * after it got a hashKey assigned.
- */
- if (val == 0) {
- cp = __stringVal(self);
- l = __stringSize(self);
+ if (__qIsSymbol(self)) {
+ val = __GET_HASH(self);
+ /*
+ * only do it, if I have no standard hash key
+ * assigned (which can only happen due to a #become:,
+ * or by creating a symbol uninterned, and interning it
+ * after it got a hashKey assigned.
+ */
+ if (val == 0) {
+ cp = __stringVal(self);
+ l = __stringSize(self);
#ifdef HASH_DRAGONBOOK
- /*
- * this is the dragon-book algorithm
- * We have tested 5-bit shifts as well:
- *
- * ST/X Symbols: 17807
- * Hashkey collisions (4bit): 14 0.07%
- * Hashkey collisions (5bit): 300 1.68%
- */
+ /*
+ * this is the dragon-book algorithm
+ * We have tested 5-bit shifts as well:
+ *
+ * ST/X Symbols: 17807
+ * Hashkey collisions (4bit): 14 0.07%
+ * Hashkey collisions (5bit): 300 1.68%
+ */
- if (l > 0) {
- val = cp[0];
- if (l > 1) {
- val = (val << 4) + cp[1];
- if (l > 2) {
- val = (val << 4) + cp[2];
- if (l > 3) {
- val = (val << 4) + cp[3];
- if (l > 4) {
- val = (val << 4) + cp[4];
- if (l > 5) {
- val = (val << 4) + cp[5];
- if (l > 6) {
- val = (val << 4) + cp[6];
- for (ce = cp + l, cp += 7; cp < ce; cp++) {
- REGISTER unsigned INT g;
+ if (l > 0) {
+ val = cp[0];
+ if (l > 1) {
+ val = (val << 4) + cp[1];
+ if (l > 2) {
+ val = (val << 4) + cp[2];
+ if (l > 3) {
+ val = (val << 4) + cp[3];
+ if (l > 4) {
+ val = (val << 4) + cp[4];
+ if (l > 5) {
+ val = (val << 4) + cp[5];
+ REGISTER unsigned char *ce;
- if (g = (val & 0xF0000000)) {
- val ^= g >> 24;
- val ^= g;
- }
- val = (val << 4) + *cp;
- }
- }
- }
- }
- }
- }
- }
- } else {
- val = 0;
- }
- val = (val * 31415821) & _MAX_INT;
+ if (l > 6) {
+ val = (val << 4) + cp[6];
+ for (ce = cp + l, cp += 7; cp < ce; cp++) {
+ REGISTER unsigned INT g;
+
+ if (g = (val & 0xF0000000)) {
+ val ^= g >> 24;
+ val ^= g;
+ }
+ val = (val << 4) + *cp;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ val = 0;
+ }
+ val = (val * 31415821) & _MAX_INT;
#else
# ifdef HASH_SDBM
- /*
- * this is the sdbm algorithm
- *
- * ST/X Symbols: 51404
- * Hashkey collisions (dragonBook): 54
- * Hashkey collisions (sdbm): 2
- */
- val = 0;
- while (l >= 4) {
- unsigned INT ch;
-
- l -= 4;
- ch = cp[0];
- val = (val * 65599) + ch;
- ch = cp[1];
- val = (val * 65599) + ch;
- ch = cp[2];
- val = (val * 65599) + ch;
- ch = cp[3];
- val = (val * 65599) + ch;
- cp += 4;
- }
- while (l) {
- unsigned INT ch;
-
- l--;
- ch = *cp++;
- val = (val * 65599) + ch;
- }
- val = val & _MAX_INT;
+ /*
+ * this is the sdbm algorithm
+ *
+ * ST/X Symbols: 51404
+ * Hashkey collisions (dragonBook): 54
+ * Hashkey collisions (sdbm): 2
+ */
+ val = 0;
+ while (l >= 4) {
+ l -= 4;
+ val = (val * 65599) + cp[0];
+ val = (val * 65599) + cp[1];
+ val = (val * 65599) + cp[2];
+ val = (val * 65599) + cp[3];
+ cp += 4;
+ }
+ while (l--) {
+ val = (val * 65599) + *cp++;
+ }
+ val = val & _MAX_INT;
# else
- error error
+# error "Undefined Hash Algorithm"
# endif
#endif
- } else {
- val = __MAKE_HASH__(val);
- }
- RETURN ( __mkSmallInteger(val) );
- }
+ } else {
+ val = __MAKE_HASH__(val);
+ }
+ RETURN ( __mkSmallInteger(val) );
+ }
%}.
- ^ super identityHash
+
+ ^ super identityHash.
"
- |hashColl hashSet|
+ |hashColl hashSet|
- hashColl := OrderedCollection new:20000.
- Symbol allInstancesDo:[:instance |
- hashColl add:instance identityHash
- ].
- hashSet := hashColl asSet.
+ hashColl := OrderedCollection new:20000.
+ Symbol allInstancesDo:[:instance |
+ hashColl add:instance identityHash
+ ].
+ hashSet := hashColl asSet.
- Transcript showCR:'Symbols: ', hashColl size printString,
- ' unique hash keys: ', hashSet size printString,
- ' collisions:', (hashColl size - hashSet size) printString.
+ Transcript showCR:'Symbols: ', hashColl size printString,
+ ' unique hash keys: ', hashSet size printString,
+ ' collisions:', (hashColl size - hashSet size) printString.
"
"Modified (comment): / 26-12-2011 / 14:32:10 / cg"
@@ -559,6 +551,7 @@
^ self
! !
+
!Symbol methodsFor:'printing & storing'!
printOn:aStream
@@ -803,9 +796,10 @@
!Symbol class methodsFor:'documentation'!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.99 2011-12-29 00:29:45 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.100 2013-01-15 15:00:19 stefan Exp $'
!
version_SVN
^ '§ Id: Symbol.st 10648 2011-06-23 15:55:10Z vranyj1 §'
! !
+