MethodDictionary.st
changeset 2246 57451418f10a
parent 2183 a2811a1d1037
child 2380 4af4a2c369cf
--- a/MethodDictionary.st	Thu Jan 23 14:16:06 1997 +0100
+++ b/MethodDictionary.st	Thu Jan 23 14:37:03 1997 +0100
@@ -11,10 +11,10 @@
 "
 
 Array subclass:#MethodDictionary
-        instanceVariableNames:''
-        classVariableNames:''
-        poolDictionaries:''
-        category:'Kernel-Methods'
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Kernel-Methods'
 !
 
 !MethodDictionary class methodsFor:'documentation'!
@@ -180,7 +180,7 @@
 
 at:key put:value 
     "set the value for a given key, which is supposed to be a symbol.
-     In contrast to dictionaries, we allow adding elements only, if there is a
+     In contrast to dictionaries, we allow adding elements only, if there is an
      empty slot (nil key) present."
 
     |slot sz "{ Class: SmallInteger }"|
@@ -199,13 +199,14 @@
     ^ self errorKeyNotFound:key
 
     "Modified: 7.6.1996 / 09:39:04 / stefan"
+    "Modified: 23.1.1997 / 13:59:29 / cg"
 !
 
 at:key putOrAppend:value 
     "set the value for a given key, which is supposed to be a symbol.
-     In contrast to dictionaries, we allow adding elements only, if there is a
+     In contrast to dictionaries, we allow adding elements only, if there is an
      empty slot (nil key) present.
-     Otherwise we create a return a new MethodDictionary"
+     Otherwise a new MethodDictionary is created & returned"
 
     |slot emptySlot newDict sz "{ Class: SmallInteger }"|
 
@@ -234,7 +235,7 @@
 "/    newDict replaceFrom:1 to:sz with:self startingAt:1.
 "/ must use basicAt
     1 to:sz do:[:i |
-	newDict basicAt:i put:(self basicAt:i).
+        newDict basicAt:i put:(self basicAt:i).
     ].
 
     newDict basicAt:(sz+1) put:key.
@@ -243,6 +244,7 @@
 
     "Created: 7.6.1996 / 15:01:54 / stefan"
     "Modified: 7.6.1996 / 17:32:40 / stefan"
+    "Modified: 23.1.1997 / 14:00:03 / cg"
 !
 
 keyAtValue:value ifAbsent:exceptionBlock
@@ -280,9 +282,8 @@
     sz := self basicSize.
     1 to:sz by:2 do:[:i |
         (self basicAt:i) == key ifTrue:[
-           self basicAt:i        put:nil.
            value := self basicAt:(i + 1).
-           self basicAt:(i + 1)  put:nil.
+           self basicAt:i put:nil. self basicAt:(i+1) put:nil.
            ^ value
         ]
     ].
@@ -290,7 +291,7 @@
     ^ failBlock value.
 
     "Created: 7.6.1996 / 15:57:56 / stefan"
-    "Modified: 9.1.1997 / 03:29:56 / cg"
+    "Modified: 23.1.1997 / 14:36:24 / cg"
 !
 
 removeKeyAndCompress:key
@@ -350,34 +351,39 @@
      and return a Bag with the results."
 
     |sz "{ Class: SmallInteger }"
-     newCollection|
+     newCollection key value|
 
     newCollection := Bag new.
     sz := self basicSize.
     1 to:sz by:2 do:[:i |
-        (self basicAt:i) notNil ifTrue:[
-            newCollection add:(aBlock value:(self basicAt:(i + 1)))
+        key := self basicAt:i. value := self basicAt:i+1.
+        key notNil ifTrue:[
+            newCollection add:(aBlock value:value)
         ]
     ].
     ^ newCollection
 
     "Created: 24.6.1996 / 17:41:41 / cg"
+    "Modified: 23.1.1997 / 13:58:24 / cg"
 !
 
 do:aBlock
     "evaluate the 1 arg block aBlock for each value (i.e. each Method)"
 
-    |sz "{ Class: SmallInteger }"|
+    |sz "{ Class: SmallInteger }"
+     key value|
 
     sz := self basicSize.
     1 to:sz by:2 do:[:i |
-        (self basicAt:i) notNil ifTrue:[
-            aBlock value:(self basicAt:(i + 1)).
+        key := self basicAt:i. value := self basicAt:i+1.
+        key notNil ifTrue:[
+            aBlock value:value.
         ]
     ].
 
     "Created: 7.6.1996 / 09:25:23 / stefan"
     "Modified: 7.6.1996 / 13:47:37 / stefan"
+    "Modified: 23.1.1997 / 13:57:49 / cg"
 !
 
 findFirstKey:aBlock
@@ -397,17 +403,18 @@
     "evaluate the 2 arg block aBlock for each key (i.e. each selector)
      and each value (i.e. each method)"
 
-    |key sz "{ Class: SmallInteger }"|
+    |key value sz "{ Class: SmallInteger }"|
 
     sz := self basicSize.
     1 to:sz by:2 do:[:i |
-        key := self basicAt:i.
+        key := self basicAt:i. value := self basicAt:(i+1).
         (key notNil) ifTrue:[
-            aBlock value:key value:(self basicAt:(i+1)).
+            aBlock value:key value:value.
         ]
     ].
 
     "Created: 7.6.1996 / 09:27:42 / stefan"
+    "Modified: 23.1.1997 / 13:57:06 / cg"
 !
 
 keysDo:aBlock
@@ -442,19 +449,47 @@
 keys
     "return a collection containing all keys of the receiver"
 
-    ^ (1 to:self basicSize by:2) collect:[:index | self basicAt:index].
+    |sz "{ Class: SmallInteger }"
+     keys|
+
+    sz := self basicSize.
+    keys := OrderedCollection new:(sz // 2).
+
+    1 to:sz by:2 do:[:index | 
+        keys add:(self basicAt:index)
+    ].
+    ^ keys
+
+    "
+     self methodDictionary keys 
+    "
+
+    "Modified: 23.1.1997 / 13:56:13 / cg"
 !
 
 values
     "return a collection containing all values of the receiver"
 
-    ^ (2 to:self basicSize by:2) collect:[:index | self basicAt:index].
+    |sz "{ Class: SmallInteger }"
+     values|
+
+    sz := self basicSize.
+    values := OrderedCollection new:(sz // 2).
 
-    "Created: 7.6.1996 / 09:40:32 / stefan"
+    2 to:sz+1 by:2 do:[:index | 
+        values add:(self basicAt:index)
+    ].
+    ^ values
+
+    "
+     self methodDictionary values
+    "
+
+    "Modified: 23.1.1997 / 13:55:17 / cg"
 ! !
 
 !MethodDictionary class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/MethodDictionary.st,v 1.13 1997-01-16 23:56:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/MethodDictionary.st,v 1.14 1997-01-23 13:37:03 cg Exp $'
 ! !