author | Claus Gittinger <cg@exept.de> |
Wed, 22 Nov 2000 11:56:15 +0100 | |
changeset 5724 | 96c2a5cf4217 |
parent 5557 | f5f8d236027c |
child 8467 | f25892c63a56 |
permissions | -rw-r--r-- |
328 | 1 |
" |
2183 | 2 |
COPYRIGHT (c) 1995 by eXept Software AG |
2110 | 3 |
All Rights Reserved |
328 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5557 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
2386
b499ac8389c1
Ooops, MthdDict must be a variableSubclass of Collection.
Stefan Vogel <sv@exept.de>
parents:
2380
diff
changeset
|
15 |
Collection variableSubclass:#MethodDictionary |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
16 |
instanceVariableNames:'' |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
17 |
classVariableNames:'' |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
18 |
poolDictionaries:'' |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
19 |
category:'Kernel-Methods' |
328 | 20 |
! |
21 |
||
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
22 |
!MethodDictionary class methodsFor:'documentation'! |
328 | 23 |
|
24 |
copyright |
|
25 |
" |
|
2183 | 26 |
COPYRIGHT (c) 1995 by eXept Software AG |
2110 | 27 |
All Rights Reserved |
328 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Instances of MethodDictionary store selector/method associations |
|
41 |
in classes. Conceptionally, they behave like Dictionaries, but are |
|
42 |
implemented using a single array (instead of dictionary, which uses |
|
43 |
two arrays to store keys and values separately). |
|
44 |
Also, they do not use hashing, since due to caching in the VM, hashing |
|
45 |
does not make too much of a difference in speed, but complicates the |
|
46 |
VM implementations. |
|
1465 | 47 |
|
48 |
[author:] |
|
49 |
Stefan Vogel |
|
50 |
||
51 |
[see also:] |
|
52 |
Dictionary |
|
53 |
Behavior Class |
|
54 |
Method Symbol |
|
328 | 55 |
" |
56 |
! ! |
|
57 |
||
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
58 |
!MethodDictionary class methodsFor:'instance creation'! |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
59 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
60 |
new:sz |
2897 | 61 |
"create and return a new methodDictionary holding sz |
62 |
key->value associations" |
|
63 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
64 |
^ self basicNew:(sz * 2) |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
65 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
66 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
67 |
withAll:aDictionary |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
68 |
"create a MethodDictionary from another Dictionary" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
69 |
|
1519 | 70 |
|newDict i "{ Class: SmallInteger }" | |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
71 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
72 |
newDict := self new:aDictionary size. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
73 |
i := 1. |
1519 | 74 |
aDictionary keysAndValuesDo:[:key :value | |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
75 |
newDict basicAt:i put:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
76 |
newDict basicAt:i+1 put:value. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
77 |
i := i+2. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
78 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
79 |
^ newDict |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
80 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
81 |
" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
82 |
|d| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
83 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
84 |
d := Dictionary withKeys:#(a b c d e) andValues:#(1 2 3 4 5). |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
85 |
MethodDictionary withAll:d. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
86 |
" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
87 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
88 |
"Created: 12.6.1996 / 13:46:43 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
89 |
"Modified: 12.6.1996 / 13:56:36 / stefan" |
1519 | 90 |
"Modified: 3.7.1996 / 11:05:55 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
91 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
92 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
93 |
withKeys:keys andValues:values |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
94 |
"create a MethodDictionary from a key (selector) array and value (method) array" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
95 |
|
2897 | 96 |
|inst |
97 |
sz "{ Class: SmallInteger }" |
|
98 |
idx "{ Class: SmallInteger }" | |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
99 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
100 |
sz := keys size. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
101 |
inst := self new:sz. |
2897 | 102 |
idx := 2. |
1519 | 103 |
1 to:sz do:[:i | |
2897 | 104 |
inst basicAt:(idx-1) put:(keys at:i). |
105 |
inst basicAt:(idx) put:(values at:i). |
|
106 |
idx := idx + 2. |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
107 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
108 |
^ inst |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
109 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
110 |
"Created: 12.6.1996 / 13:46:43 / stefan" |
1519 | 111 |
"Modified: 3.7.1996 / 11:05:34 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
112 |
! ! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
113 |
|
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
114 |
!MethodDictionary class methodsFor:'binary storage'! |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
115 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
116 |
binaryFullDefinitionFrom:stream manager:manager |
1519 | 117 |
|size "{ Class: SmallInteger }" |
118 |
inst| |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
119 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
120 |
size := manager nextObject. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
121 |
inst := self new:size. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
122 |
1 to:size*2 by:2 do:[:i| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
123 |
inst basicAt:i put:manager nextObject. "/ get selector |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
124 |
inst basicAt:(i + 1) put:(Method binaryFullDefinitionFrom:stream manager:manager). |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
125 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
126 |
^ inst |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
127 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
128 |
"Created: 7.6.1996 / 13:37:22 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
129 |
"Modified: 7.6.1996 / 13:52:08 / stefan" |
1519 | 130 |
"Modified: 3.7.1996 / 11:06:34 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
131 |
! ! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
132 |
|
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
133 |
!MethodDictionary class methodsFor:'queries'! |
328 | 134 |
|
135 |
isBuiltInClass |
|
136 |
"this class is known by the run-time-system" |
|
137 |
||
138 |
^ self == MethodDictionary |
|
139 |
! ! |
|
140 |
||
141 |
!MethodDictionary methodsFor:'accessing'! |
|
142 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
143 |
associationAt:key |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
144 |
"return an association consisting of aKey and the element indexed |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
145 |
by aKey - |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
146 |
report an error, if no element is stored under aKey." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
147 |
|
2897 | 148 |
^ Association key:key value:(self at:key) |
328 | 149 |
! |
150 |
||
151 |
at:key |
|
152 |
"return the value for a given key, which is supposed to be a symbol" |
|
153 |
||
154 |
|sz "{ Class: SmallInteger }"| |
|
155 |
||
156 |
sz := self basicSize. |
|
157 |
1 to:sz by:2 do:[:i | |
|
2897 | 158 |
(self basicAt:i) == key ifTrue:[^ self basicAt:(i + 1)] |
328 | 159 |
]. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
160 |
^ self errorKeyNotFound:key |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
161 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
162 |
"Modified: 7.6.1996 / 15:53:28 / stefan" |
328 | 163 |
! |
164 |
||
165 |
at:key ifAbsent:exceptionBlock |
|
166 |
"return the element indexed by aKey - |
|
167 |
return result of exceptionBlock if no element is stored under aKey" |
|
168 |
||
169 |
|sz "{ Class: SmallInteger }"| |
|
170 |
||
171 |
sz := self basicSize. |
|
172 |
1 to:sz by:2 do:[:i | |
|
2897 | 173 |
(self basicAt:i) == key ifTrue:[^ self basicAt:(i + 1)] |
328 | 174 |
]. |
175 |
^ exceptionBlock value |
|
176 |
! |
|
177 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
178 |
at:key put:value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
179 |
"set the value for a given key, which is supposed to be a symbol. |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
180 |
In contrast to dictionaries, we allow adding elements only, if there is an |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
181 |
empty slot (nil key) present." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
182 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
183 |
|slot sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
184 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
185 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
186 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
187 |
slot := self basicAt:i. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
188 |
(slot == key) ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
189 |
^ self basicAt:(i + 1) put:value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
190 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
191 |
slot isNil ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
192 |
self basicAt:i put:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
193 |
^ self basicAt:(i + 1) put:value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
194 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
195 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
196 |
^ self errorKeyNotFound:key |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
197 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
198 |
"Modified: 7.6.1996 / 09:39:04 / stefan" |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
199 |
"Modified: 23.1.1997 / 13:59:29 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
200 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
201 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
202 |
at:key putOrAppend:value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
203 |
"set the value for a given key, which is supposed to be a symbol. |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
204 |
In contrast to dictionaries, we allow adding elements only, if there is an |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
205 |
empty slot (nil key) present. |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
206 |
Otherwise a new MethodDictionary is created & returned" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
207 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
208 |
|slot emptySlot newDict sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
209 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
210 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
211 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
212 |
slot := self basicAt:i. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
213 |
(slot == key) ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
214 |
self basicAt:(i + 1) put:value . |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
215 |
^ self. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
216 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
217 |
slot isNil ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
218 |
emptySlot := i. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
219 |
] |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
220 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
221 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
222 |
emptySlot notNil ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
223 |
self basicAt:emptySlot put:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
224 |
self basicAt:(emptySlot + 1) put:value. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
225 |
^ self. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
226 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
227 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
228 |
"/ not enough room for new entry, copy to new dictionary |
2406 | 229 |
newDict := self class new:sz//2+1. |
2183 | 230 |
|
231 |
"/ cannot do this ... |
|
232 |
"/ newDict replaceFrom:1 to:sz with:self startingAt:1. |
|
233 |
"/ must use basicAt |
|
234 |
1 to:sz do:[:i | |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
235 |
newDict basicAt:i put:(self basicAt:i). |
2183 | 236 |
]. |
237 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
238 |
newDict basicAt:(sz+1) put:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
239 |
newDict basicAt:(sz+2) put:value. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
240 |
^ newDict. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
241 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
242 |
"Created: 7.6.1996 / 15:01:54 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
243 |
"Modified: 7.6.1996 / 17:32:40 / stefan" |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
244 |
"Modified: 23.1.1997 / 14:00:03 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
245 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
246 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
247 |
keyAtValue:value ifAbsent:exceptionBlock |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
248 |
"return the first key with value - |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
249 |
return result of exceptionBlock if no key can be found" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
250 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
251 |
|sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
252 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
253 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
254 |
2 to:sz by:2 do:[:i | |
2897 | 255 |
(self basicAt:i) == value ifTrue:[^ self basicAt:(i - 1)] |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
256 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
257 |
^ exceptionBlock value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
258 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
259 |
"Created: 7.6.1996 / 14:53:57 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
260 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
261 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
262 |
removeKey:key |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
263 |
"remove key from dictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
264 |
We actually do not remove it, but set it to nil." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
265 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
266 |
^ self removeKey:key ifAbsent:[self errorKeyNotFound:key]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
267 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
268 |
"Created: 7.6.1996 / 15:58:50 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
269 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
270 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
271 |
removeKey:key ifAbsent:failBlock |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
272 |
"remove key from dictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
273 |
We actually do not remove it, but set it to nil." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
274 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
275 |
|value sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
276 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
277 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
278 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
279 |
(self basicAt:i) == key ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
280 |
value := self basicAt:(i + 1). |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
281 |
self basicAt:i put:nil. self basicAt:(i+1) put:nil. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
282 |
^ value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
283 |
] |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
284 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
285 |
|
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
286 |
^ failBlock value. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
287 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
288 |
"Created: 7.6.1996 / 15:57:56 / stefan" |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
289 |
"Modified: 23.1.1997 / 14:36:24 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
290 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
291 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
292 |
removeKeyAndCompress:key |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
293 |
"remove key from dictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
294 |
A new, compressed MethodDictionary will be returned, |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
295 |
or nil, if key is not present." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
296 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
297 |
|newDict dstIndex sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
298 |
|
2402
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
299 |
sz := self basicSize. |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
300 |
1 to:sz by:2 do:[:i | |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
301 |
(self basicAt:i) == key ifTrue:[ |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
302 |
dstIndex := i |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
303 |
] |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
304 |
]. |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
305 |
|
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
306 |
dstIndex isNil ifTrue:[^ self]. |
1508
960d6e7e563b
removeKeyAndCompress - failed if key was not present.
Claus Gittinger <cg@exept.de>
parents:
1485
diff
changeset
|
307 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
308 |
sz := self basicSize. |
2406 | 309 |
newDict := self class new:(sz//2-1). |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
310 |
dstIndex := 1. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
311 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
312 |
(self basicAt:i) ~~ key ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
313 |
newDict basicAt:dstIndex put:(self basicAt:i). |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
314 |
newDict basicAt:dstIndex+1 put:(self basicAt:i+1). |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
315 |
dstIndex := dstIndex + 2. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
316 |
] |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
317 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
318 |
dstIndex > sz ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
319 |
^ nil |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
320 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
321 |
^ newDict |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
322 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
323 |
"Created: 7.6.1996 / 15:57:56 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
324 |
"Modified: 7.6.1996 / 16:47:02 / stefan" |
2402
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
325 |
"Modified: 12.2.1997 / 19:47:23 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
326 |
! ! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
327 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
328 |
!MethodDictionary methodsFor:'binary storage'! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
329 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
330 |
storeFullBinaryDefinitionOn:stream manager:manager |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
331 |
"store the complete description (i.e. including methods)" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
332 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
333 |
self size storeBinaryOn:stream manager:manager. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
334 |
self keysAndValuesDo:[:sel :mthd| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
335 |
sel storeBinaryOn:stream manager:manager. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
336 |
mthd makeRealMethod storeFullBinaryDefinitionOn:stream manager:manager. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
337 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
338 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
339 |
"Created: 7.6.1996 / 12:53:00 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
340 |
! ! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
341 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
342 |
!MethodDictionary methodsFor:'enumerating'! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
343 |
|
1485 | 344 |
collect:aBlock |
345 |
"for each element in the receiver, evaluate the argument, aBlock |
|
346 |
and return a Bag with the results." |
|
347 |
||
348 |
|sz "{ Class: SmallInteger }" |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
349 |
newCollection key value| |
1485 | 350 |
|
351 |
newCollection := Bag new. |
|
352 |
sz := self basicSize. |
|
353 |
1 to:sz by:2 do:[:i | |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
354 |
key := self basicAt:i. value := self basicAt:i+1. |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
355 |
key notNil ifTrue:[ |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
356 |
newCollection add:(aBlock value:value) |
1485 | 357 |
] |
358 |
]. |
|
359 |
^ newCollection |
|
360 |
||
361 |
"Created: 24.6.1996 / 17:41:41 / cg" |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
362 |
"Modified: 23.1.1997 / 13:58:24 / cg" |
1485 | 363 |
! |
364 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
365 |
do:aBlock |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
366 |
"evaluate the 1 arg block aBlock for each value (i.e. each Method)" |
328 | 367 |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
368 |
|sz "{ Class: SmallInteger }" |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
369 |
key value| |
328 | 370 |
|
371 |
sz := self basicSize. |
|
372 |
1 to:sz by:2 do:[:i | |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
373 |
key := self basicAt:i. value := self basicAt:i+1. |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
374 |
key notNil ifTrue:[ |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
375 |
aBlock value:value. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
376 |
] |
328 | 377 |
]. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
378 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
379 |
"Created: 7.6.1996 / 09:25:23 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
380 |
"Modified: 7.6.1996 / 13:47:37 / stefan" |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
381 |
"Modified: 23.1.1997 / 13:57:49 / cg" |
328 | 382 |
! |
383 |
||
1703 | 384 |
findFirstKey:aBlock |
385 |
"find and return the first key, for which evaluation of the argument, aBlock |
|
386 |
returns true; return nil if none is detected." |
|
387 |
||
388 |
self keysDo:[:key | |
|
389 |
(aBlock value:key) ifTrue:[^ key]. |
|
390 |
]. |
|
391 |
^ nil |
|
392 |
||
393 |
"Created: 8.10.1996 / 22:01:31 / cg" |
|
394 |
"Modified: 8.10.1996 / 22:02:03 / cg" |
|
395 |
! |
|
396 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
397 |
keysAndValuesDo:aBlock |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
398 |
"evaluate the 2 arg block aBlock for each key (i.e. each selector) |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
399 |
and each value (i.e. each method)" |
328 | 400 |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
401 |
|key value sz "{ Class: SmallInteger }"| |
328 | 402 |
|
403 |
sz := self basicSize. |
|
404 |
1 to:sz by:2 do:[:i | |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
405 |
key := self basicAt:i. value := self basicAt:(i+1). |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
406 |
(key notNil) ifTrue:[ |
3460 | 407 |
value notNil ifTrue:[ |
408 |
aBlock value:key value:value. |
|
409 |
] |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
410 |
] |
328 | 411 |
]. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
412 |
|
3460 | 413 |
"Created: / 7.6.1996 / 09:27:42 / stefan" |
414 |
"Modified: / 3.2.1998 / 00:48:47 / cg" |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
415 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
416 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
417 |
keysDo:aBlock |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
418 |
"evaluate the 1 arg block aBlock for each key (i.e. each selector)" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
419 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
420 |
|key sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
421 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
422 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
423 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
424 |
key := self basicAt:i. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
425 |
(key notNil) ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
426 |
aBlock value:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
427 |
] |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
428 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
429 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
430 |
"Created: 7.6.1996 / 09:26:34 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
431 |
! ! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
432 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
433 |
!MethodDictionary methodsFor:'inspecting'! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
434 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
435 |
inspectorClass |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
436 |
"redefined to use DictionaryInspector |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
437 |
(instead of the default Inspector)." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
438 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
439 |
^ DictionaryInspectorView |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
440 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
441 |
"Created: 12.6.1996 / 12:29:13 / stefan" |
328 | 442 |
! ! |
443 |
||
2406 | 444 |
!MethodDictionary methodsFor:'private'! |
445 |
||
446 |
compressed |
|
447 |
"compress - return either the receiver or myself" |
|
448 |
||
449 |
|newDict tally dstIndex "{ Class: SmallInteger }" sz "{ Class: SmallInteger }" |
|
450 |
key mySize| |
|
451 |
||
452 |
sz := self basicSize. |
|
453 |
mySize := sz // 2. |
|
454 |
tally := 0. |
|
455 |
1 to:sz by:2 do:[:i | |
|
456 |
(self basicAt:i) notNil ifTrue:[ |
|
457 |
tally := tally + 1 |
|
458 |
] |
|
459 |
]. |
|
460 |
||
461 |
tally == mySize ifTrue:[^ self]. |
|
462 |
||
463 |
newDict := self class new:tally. |
|
464 |
dstIndex := 1. |
|
465 |
1 to:sz by:2 do:[:i | |
|
466 |
key := self basicAt:i. |
|
467 |
key notNil ifTrue:[ |
|
468 |
newDict basicAt:dstIndex put:key. |
|
469 |
newDict basicAt:dstIndex+1 put:(self basicAt:i+1). |
|
470 |
dstIndex := dstIndex + 2. |
|
471 |
] |
|
472 |
]. |
|
473 |
^ newDict |
|
474 |
||
475 |
! ! |
|
476 |
||
328 | 477 |
!MethodDictionary methodsFor:'queries'! |
478 |
||
2798 | 479 |
includesKey:key |
480 |
"return true, if there is an entry stored under key |
|
481 |
(i.e. there is a method for that selector)" |
|
482 |
||
483 |
|sz "{ Class: SmallInteger }"| |
|
484 |
||
485 |
sz := self basicSize. |
|
486 |
1 to:sz by:2 do:[:i | |
|
487 |
(self basicAt:i) == key ifTrue:[^ true]. |
|
488 |
]. |
|
489 |
||
490 |
^ false |
|
491 |
||
492 |
"Created: 30.7.1997 / 11:01:37 / cg" |
|
493 |
! |
|
494 |
||
328 | 495 |
keys |
496 |
"return a collection containing all keys of the receiver" |
|
497 |
||
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
498 |
|sz "{ Class: SmallInteger }" |
2406 | 499 |
keys key| |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
500 |
|
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
501 |
sz := self basicSize. |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
502 |
keys := OrderedCollection new:(sz // 2). |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
503 |
|
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
504 |
1 to:sz by:2 do:[:index | |
2406 | 505 |
key := self basicAt:index. |
506 |
key notNil ifTrue:[ |
|
507 |
keys add:key |
|
508 |
] |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
509 |
]. |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
510 |
^ keys |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
511 |
|
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
512 |
" |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
513 |
self methodDictionary keys |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
514 |
" |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
515 |
|
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
516 |
"Modified: 23.1.1997 / 13:56:13 / cg" |
328 | 517 |
! |
518 |
||
5557 | 519 |
size |
520 |
"return the number of elements (associations) in the receiver" |
|
521 |
||
522 |
^ self basicSize // 2 |
|
523 |
! |
|
524 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
525 |
values |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
526 |
"return a collection containing all values of the receiver" |
328 | 527 |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
528 |
|sz "{ Class: SmallInteger }" |
2406 | 529 |
values key| |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
530 |
|
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
531 |
sz := self basicSize. |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
532 |
values := OrderedCollection new:(sz // 2). |
328 | 533 |
|
2406 | 534 |
1 to:sz by:2 do:[:index | |
535 |
key := self basicAt:index. |
|
536 |
key notNil ifTrue:[ |
|
537 |
values add:(self basicAt:index+1) |
|
538 |
] |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
539 |
]. |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
540 |
^ values |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
541 |
|
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
542 |
" |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
543 |
self methodDictionary values |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
544 |
" |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
545 |
|
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
546 |
"Modified: 23.1.1997 / 13:55:17 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
547 |
! ! |
328 | 548 |
|
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
549 |
!MethodDictionary class methodsFor:'documentation'! |
328 | 550 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
551 |
version |
5557 | 552 |
^ '$Header: /cvs/stx/stx/libbasic/MethodDictionary.st,v 1.22 2000-08-22 13:57:14 cg Exp $' |
328 | 553 |
! ! |