IdentityDictionary.st
changeset 609 12be97f6d5a7
parent 530 07d0bce293c9
child 634 e15218d09420
--- a/IdentityDictionary.st	Thu Nov 23 02:23:53 1995 +0100
+++ b/IdentityDictionary.st	Thu Nov 23 02:26:15 1995 +0100
@@ -11,10 +11,10 @@
 "
 
 Dictionary subclass:#IdentityDictionary
-       instanceVariableNames:''
-       classVariableNames:''
-       poolDictionaries:''
-       category:'Collections-Unordered'
+	 instanceVariableNames:''
+	 classVariableNames:''
+	 poolDictionaries:''
+	 category:'Collections-Unordered'
 !
 
 !IdentityDictionary class methodsFor:'documentation'!
@@ -33,10 +33,6 @@
 "
 !
 
-version
-    ^ '$Header: /cvs/stx/stx/libbasic/IdentityDictionary.st,v 1.16 1995-11-11 15:23:26 cg Exp $'
-!
-
 documentation
 "
     same as a Dictionary but key must be identical - not just equal.
@@ -44,29 +40,10 @@
     #identityHash instead of #hash.
     IdentityDictionaries are especially useful, when symbols are used as keys.
 "
-! !
-
-!IdentityDictionary methodsFor:'testing'!
-
-includesValue:aValue
-    "return true, if the argument, aValue is stored in the dictionary,
-     Redefined to use identity compare, NOT equality compare"
-
-    ^ (valueArray identityIndexOf:aValue) ~~ 0
 !
 
-occurrencesOf:anObject
-    "count & return how often anObject is stored in the dictionary.
-     This counts values - not keys.
-     Redefined to use identity compare, NOT equality compare."
-
-    |cnt|
-
-    cnt := 0.
-    valueArray do:[:element |
-       element == anObject ifTrue:[cnt := cnt + 1]
-    ].
-    ^ cnt
+version
+    ^ '$Header: /cvs/stx/stx/libbasic/IdentityDictionary.st,v 1.17 1995-11-23 01:25:21 cg Exp $'
 ! !
 
 !IdentityDictionary methodsFor:'private'!
@@ -75,6 +52,49 @@
     ^ element1 == element2
 !
 
+emptyCollectionForKeys
+    "return an empty collection used for keys.
+     Made a separate method to allow redefinition for different kind of
+     containers in subclasses"
+
+    ^ IdentitySet new:(self size)
+!
+
+find:key ifAbsent:aBlock
+    "Look for the key in the receiver.  If it is found, return
+     the index of the association containing the key, otherwise
+     return the value of evaluating aBlock."
+
+    |index  "{ Class:SmallInteger }"
+     length "{ Class:SmallInteger }"
+     startIndex
+     probe|
+
+    length := keyArray basicSize.
+    length < 10 ifTrue:[
+	"assuming, that for small dictionaries the overhead of hashing
+	 is large ... maybe that proves wrong (if overhead of comparing
+	 is high)"
+	^ keyArray identityIndexOf:key ifAbsent:aBlock.
+    ].
+
+    index := key identityHash.
+    index := index \\ length + 1.
+    startIndex := index.
+
+    [true] whileTrue:[
+	probe := keyArray basicAt:index.
+	probe == key ifTrue:[^ index].
+
+	index == length ifTrue:[
+	    index := 1
+	] ifFalse:[
+	    index := index + 1
+	].
+	(probe isNil or:[index == startIndex]) ifTrue:[^ aBlock value]
+    ]
+!
+
 findKeyOrNil:key
     "Look for the key in the receiver.  If it is found, return
      the index of the association containing the key, otherwise
@@ -128,47 +148,28 @@
 	 this is only called after growing"
     ].
     ^ index
-! 
+! !
 
-find:key ifAbsent:aBlock
-    "Look for the key in the receiver.  If it is found, return
-     the index of the association containing the key, otherwise
-     return the value of evaluating aBlock."
-
-    |index  "{ Class:SmallInteger }"
-     length "{ Class:SmallInteger }"
-     startIndex
-     probe|
+!IdentityDictionary methodsFor:'testing'!
 
-    length := keyArray basicSize.
-    length < 10 ifTrue:[
-	"assuming, that for small dictionaries the overhead of hashing
-	 is large ... maybe that proves wrong (if overhead of comparing
-	 is high)"
-	^ keyArray identityIndexOf:key ifAbsent:aBlock.
-    ].
-
-    index := key identityHash.
-    index := index \\ length + 1.
-    startIndex := index.
+includesValue:aValue
+    "return true, if the argument, aValue is stored in the dictionary,
+     Redefined to use identity compare, NOT equality compare"
 
-    [true] whileTrue:[
-	probe := keyArray basicAt:index.
-	probe == key ifTrue:[^ index].
-
-	index == length ifTrue:[
-	    index := 1
-	] ifFalse:[
-	    index := index + 1
-	].
-	(probe isNil or:[index == startIndex]) ifTrue:[^ aBlock value]
-    ]
+    ^ (valueArray identityIndexOf:aValue) ~~ 0
 !
 
-emptyCollectionForKeys
-    "return an empty collection used for keys.
-     Made a separate method to allow redefinition for different kind of
-     containers in subclasses"
+occurrencesOf:anObject
+    "count & return how often anObject is stored in the dictionary.
+     This counts values - not keys.
+     Redefined to use identity compare, NOT equality compare."
+
+    |cnt|
 
-    ^ IdentitySet new:(self size)
+    cnt := 0.
+    valueArray do:[:element |
+       element == anObject ifTrue:[cnt := cnt + 1]
+    ].
+    ^ cnt
 ! !
+