author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 19 Jan 2012 10:06:02 +0000 | |
branch | jv |
changeset 17910 | 8d796ca8bd1d |
parent 17892 | d86c8bd5ece3 |
child 17911 | a99f15c5efa5 |
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 |
" |
|
5557 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
9481 | 14 |
KeyedCollection variableSubclass:#MethodDictionary |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
15 |
instanceVariableNames:'' |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
16 |
classVariableNames:'' |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
17 |
poolDictionaries:'' |
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
18 |
category:'Kernel-Methods' |
328 | 19 |
! |
20 |
||
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
21 |
!MethodDictionary class methodsFor:'documentation'! |
328 | 22 |
|
23 |
copyright |
|
24 |
" |
|
2183 | 25 |
COPYRIGHT (c) 1995 by eXept Software AG |
2110 | 26 |
All Rights Reserved |
328 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
Instances of MethodDictionary store selector/method associations |
|
8467 | 40 |
in classes. Conceptionally, they behave like IdentityDictionaries, but are |
41 |
implemented using a single array (instead of Dictionary, which uses |
|
328 | 42 |
two arrays to store keys and values separately). |
43 |
Also, they do not use hashing, since due to caching in the VM, hashing |
|
44 |
does not make too much of a difference in speed, but complicates the |
|
8467 | 45 |
VM implementation. |
1465 | 46 |
|
47 |
[author:] |
|
48 |
Stefan Vogel |
|
49 |
||
50 |
[see also:] |
|
51 |
Dictionary |
|
8467 | 52 |
IdentityDictionary |
1465 | 53 |
Behavior Class |
8467 | 54 |
Method |
55 |
Symbol |
|
328 | 56 |
" |
57 |
! ! |
|
58 |
||
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
59 |
!MethodDictionary class methodsFor:'instance creation'! |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
60 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
61 |
new:sz |
2897 | 62 |
"create and return a new methodDictionary holding sz |
63 |
key->value associations" |
|
64 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
65 |
^ self basicNew:(sz * 2) |
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 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
68 |
withAll:aDictionary |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
69 |
"create a MethodDictionary from another Dictionary" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
70 |
|
1519 | 71 |
|newDict i "{ Class: SmallInteger }" | |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
72 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
73 |
newDict := self new:aDictionary size. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
74 |
i := 1. |
1519 | 75 |
aDictionary keysAndValuesDo:[:key :value | |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
76 |
newDict basicAt:i put:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
77 |
newDict basicAt:i+1 put:value. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
78 |
i := i+2. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
79 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
80 |
^ newDict |
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 |
" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
83 |
|d| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
84 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
85 |
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
|
86 |
MethodDictionary withAll:d. |
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 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
89 |
"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
|
90 |
"Modified: 12.6.1996 / 13:56:36 / stefan" |
1519 | 91 |
"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
|
92 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
93 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
94 |
withKeys:keys andValues:values |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
95 |
"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
|
96 |
|
2897 | 97 |
|inst |
98 |
sz "{ Class: SmallInteger }" |
|
99 |
idx "{ Class: SmallInteger }" | |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
100 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
101 |
sz := keys size. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
102 |
inst := self new:sz. |
2897 | 103 |
idx := 2. |
1519 | 104 |
1 to:sz do:[:i | |
2897 | 105 |
inst basicAt:(idx-1) put:(keys at:i). |
106 |
inst basicAt:(idx) put:(values at:i). |
|
107 |
idx := idx + 2. |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
108 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
109 |
^ inst |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
110 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
111 |
"Created: 12.6.1996 / 13:46:43 / stefan" |
1519 | 112 |
"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
|
113 |
! ! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
114 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
115 |
|
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
116 |
!MethodDictionary class methodsFor:'queries'! |
328 | 117 |
|
118 |
isBuiltInClass |
|
119 |
"this class is known by the run-time-system" |
|
120 |
||
121 |
^ self == MethodDictionary |
|
9481 | 122 |
|
123 |
"Modified: / 08-08-2006 / 16:06:26 / cg" |
|
328 | 124 |
! ! |
125 |
||
126 |
!MethodDictionary methodsFor:'accessing'! |
|
127 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
128 |
associationAt:key |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
129 |
"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
|
130 |
by aKey - |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
131 |
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
|
132 |
|
2897 | 133 |
^ Association key:key value:(self at:key) |
328 | 134 |
! |
135 |
||
136 |
at:key ifAbsent:exceptionBlock |
|
137 |
"return the element indexed by aKey - |
|
138 |
return result of exceptionBlock if no element is stored under aKey" |
|
139 |
||
140 |
|sz "{ Class: SmallInteger }"| |
|
141 |
||
142 |
sz := self basicSize. |
|
143 |
1 to:sz by:2 do:[:i | |
|
2897 | 144 |
(self basicAt:i) == key ifTrue:[^ self basicAt:(i + 1)] |
328 | 145 |
]. |
146 |
^ exceptionBlock value |
|
147 |
! |
|
148 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
149 |
at:key put:value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
150 |
"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
|
151 |
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
|
152 |
empty slot (nil key) present." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
153 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
154 |
|slot sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
155 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
156 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
157 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
158 |
slot := self basicAt:i. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
159 |
(slot == key) ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
160 |
^ self basicAt:(i + 1) put:value |
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 |
slot isNil ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
163 |
self basicAt:i put:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
164 |
^ self basicAt:(i + 1) put:value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
165 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
166 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
167 |
^ self errorKeyNotFound:key |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
168 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
169 |
"Modified: 7.6.1996 / 09:39:04 / stefan" |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
170 |
"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
|
171 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
172 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
173 |
at:key putOrAppend:value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
174 |
"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
|
175 |
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
|
176 |
empty slot (nil key) present. |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
177 |
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
|
178 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
179 |
|slot emptySlot newDict sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
180 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
181 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
182 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
183 |
slot := self basicAt:i. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
184 |
(slot == key) ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
185 |
self basicAt:(i + 1) put:value . |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
186 |
^ self. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
187 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
188 |
slot isNil ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
189 |
emptySlot := i. |
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 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
192 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
193 |
emptySlot notNil ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
194 |
self basicAt:emptySlot put:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
195 |
self basicAt:(emptySlot + 1) put:value. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
196 |
^ self. |
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 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
199 |
"/ not enough room for new entry, copy to new dictionary |
2406 | 200 |
newDict := self class new:sz//2+1. |
2183 | 201 |
|
202 |
"/ cannot do this ... |
|
203 |
"/ newDict replaceFrom:1 to:sz with:self startingAt:1. |
|
204 |
"/ must use basicAt |
|
205 |
1 to:sz do:[:i | |
|
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
206 |
newDict basicAt:i put:(self basicAt:i). |
2183 | 207 |
]. |
208 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
209 |
newDict basicAt:(sz+1) put:key. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
210 |
newDict basicAt:(sz+2) put:value. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
211 |
^ newDict. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
212 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
213 |
"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
|
214 |
"Modified: 7.6.1996 / 17:32:40 / stefan" |
2246
57451418f10a
make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents:
2183
diff
changeset
|
215 |
"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
|
216 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
217 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
218 |
keyAtValue:value ifAbsent:exceptionBlock |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
219 |
"return the first key with value - |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
220 |
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
|
221 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
222 |
|sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
223 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
224 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
225 |
2 to:sz by:2 do:[:i | |
2897 | 226 |
(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
|
227 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
228 |
^ exceptionBlock value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
229 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
230 |
"Created: 7.6.1996 / 14:53:57 / stefan" |
9481 | 231 |
! ! |
232 |
||
233 |
||
234 |
!MethodDictionary methodsFor:'enumerating'! |
|
235 |
||
236 |
collect:aBlock |
|
237 |
"for each element in the receiver, evaluate the argument, aBlock |
|
238 |
and return a Bag with the results." |
|
239 |
||
240 |
|newCollection| |
|
241 |
||
242 |
newCollection := Bag new. |
|
243 |
self do:[:value | |
|
244 |
newCollection add:(aBlock value:value) |
|
245 |
]. |
|
246 |
^ newCollection |
|
247 |
||
248 |
"Created: / 24-06-1996 / 17:41:41 / cg" |
|
249 |
"Modified: / 08-08-2006 / 16:12:04 / cg" |
|
1461
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 |
|
9481 | 252 |
keysAndValuesDo:aBlock |
253 |
"evaluate the 2 arg block aBlock for each key (i.e. each selector) |
|
254 |
and each value (i.e. each method)" |
|
255 |
||
256 |
|key value sz "{ Class: SmallInteger }"| |
|
257 |
||
258 |
sz := self basicSize. |
|
259 |
1 to:sz by:2 do:[:i | |
|
260 |
key := self basicAt:i. value := self basicAt:(i+1). |
|
261 |
key notNil ifTrue:[ |
|
262 |
value notNil ifTrue:[ |
|
263 |
aBlock value:key value:value. |
|
264 |
] |
|
265 |
] |
|
266 |
]. |
|
267 |
||
268 |
"Created: / 07-06-1996 / 09:27:42 / stefan" |
|
269 |
"Modified: / 08-08-2006 / 16:11:30 / cg" |
|
270 |
! ! |
|
271 |
||
272 |
||
273 |
!MethodDictionary methodsFor:'private'! |
|
274 |
||
275 |
compressed |
|
276 |
"compress - return either the myself or a new, compressed MethodDictionary" |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
277 |
|
9481 | 278 |
|newDict tally key mySize |
279 |
dstIndex "{ Class: SmallInteger }" |
|
280 |
sz "{ Class: SmallInteger }" | |
|
281 |
||
282 |
sz := self basicSize. |
|
283 |
mySize := sz // 2. |
|
284 |
tally := 0. |
|
285 |
1 to:sz by:2 do:[:i | |
|
286 |
(self basicAt:i) notNil ifTrue:[ |
|
287 |
tally := tally + 1 |
|
288 |
] |
|
289 |
]. |
|
290 |
||
291 |
tally == mySize ifTrue:[^ self]. |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
292 |
|
9481 | 293 |
newDict := self species new:tally. |
294 |
dstIndex := 1. |
|
295 |
1 to:sz by:2 do:[:i | |
|
296 |
key := self basicAt:i. |
|
297 |
key notNil ifTrue:[ |
|
298 |
newDict basicAt:dstIndex put:key. |
|
299 |
newDict basicAt:dstIndex+1 put:(self basicAt:i+1). |
|
300 |
dstIndex := dstIndex + 2. |
|
301 |
] |
|
302 |
]. |
|
303 |
^ newDict |
|
304 |
||
305 |
"Modified: / 05-08-2004 / 20:05:44 / stefan" |
|
306 |
! ! |
|
307 |
||
308 |
!MethodDictionary methodsFor:'queries'! |
|
309 |
||
310 |
size |
|
311 |
"return the number of elements (associations) in the receiver" |
|
312 |
||
313 |
^ self basicSize // 2 |
|
314 |
! ! |
|
315 |
||
316 |
!MethodDictionary methodsFor:'removing'! |
|
1461
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 |
removeKey:key ifAbsent:failBlock |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
319 |
"remove key from dictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
320 |
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
|
321 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
322 |
|value sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
323 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
324 |
sz := self basicSize. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
325 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
326 |
(self basicAt:i) == key ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
327 |
value := self basicAt:(i + 1). |
9444 | 328 |
self basicAt:i put:nil. |
329 |
self basicAt:(i+1) put:nil. |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
330 |
^ value |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
331 |
] |
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 |
|
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
334 |
^ failBlock value. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
335 |
|
9444 | 336 |
"Created: / 07-06-1996 / 15:57:56 / stefan" |
337 |
"Modified: / 16-07-2006 / 13:08:41 / cg" |
|
1461
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 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
340 |
removeKeyAndCompress:key |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
341 |
"remove key from dictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
342 |
A new, compressed MethodDictionary will be returned, |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
343 |
or nil, if key is not present." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
344 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
345 |
|newDict dstIndex sz "{ Class: SmallInteger }"| |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
346 |
|
2402
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
347 |
sz := self basicSize. |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
348 |
1 to:sz by:2 do:[:i | |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
349 |
(self basicAt:i) == key ifTrue:[ |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
350 |
dstIndex := i |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
351 |
] |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
352 |
]. |
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
353 |
|
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
354 |
dstIndex isNil ifTrue:[^ self]. |
1508
960d6e7e563b
removeKeyAndCompress - failed if key was not present.
Claus Gittinger <cg@exept.de>
parents:
1485
diff
changeset
|
355 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
356 |
sz := self basicSize. |
2406 | 357 |
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
|
358 |
dstIndex := 1. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
359 |
1 to:sz by:2 do:[:i | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
360 |
(self basicAt:i) ~~ key ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
361 |
newDict basicAt:dstIndex put:(self basicAt:i). |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
362 |
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
|
363 |
dstIndex := dstIndex + 2. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
364 |
] |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
365 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
366 |
dstIndex > sz ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
367 |
^ nil |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
368 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
369 |
^ newDict |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
370 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
371 |
"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
|
372 |
"Modified: 7.6.1996 / 16:47:02 / stefan" |
2402
fc35bd8b4343
#identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents:
2386
diff
changeset
|
373 |
"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
|
374 |
! ! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
375 |
|
2109
c019b0e813ec
oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents:
1703
diff
changeset
|
376 |
!MethodDictionary class methodsFor:'documentation'! |
328 | 377 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
530
diff
changeset
|
378 |
version |
17892 | 379 |
^ '$Header: /cvs/stx/stx/libbasic/MethodDictionary.st,v 1.29 2011/07/20 15:52:04 cg Exp $' |
17847 | 380 |
! |
381 |
||
382 |
version_CVS |
|
17865 | 383 |
^ '§Header: /cvs/stx/stx/libbasic/MethodDictionary.st,v 1.29 2011/07/20 15:52:04 cg Exp §' |
384 |
! |
|
385 |
||
386 |
version_SVN |
|
17910 | 387 |
^ '$Id: MethodDictionary.st 10758 2012-01-19 10:06:02Z vranyj1 $' |
17846 | 388 |
! ! |
17892 | 389 |
|
17910 | 390 |