author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 15:23:19 +0100 | |
changeset 624 | f09ad5cf21d4 |
parent 530 | 07d0bce293c9 |
child 1461 | dd25bb1e9973 |
permissions | -rw-r--r-- |
328 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
||
13 |
Array subclass:#MethodDictionary |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Methods' |
|
18 |
! |
|
19 |
||
20 |
!MethodDictionary class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
version |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/MthdDict.st,v 1.4 1995-11-11 15:24:32 cg Exp $' |
328 | 38 |
! |
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
Instances of MethodDictionary store selector/method associations |
|
43 |
in classes. Conceptionally, they behave like Dictionaries, but are |
|
44 |
implemented using a single array (instead of dictionary, which uses |
|
45 |
two arrays to store keys and values separately). |
|
46 |
Also, they do not use hashing, since due to caching in the VM, hashing |
|
47 |
does not make too much of a difference in speed, but complicates the |
|
48 |
VM implementations. |
|
49 |
" |
|
50 |
! ! |
|
51 |
||
52 |
!MethodDictionary class methodsFor:'queries'! |
|
53 |
||
54 |
isBuiltInClass |
|
55 |
"this class is known by the run-time-system" |
|
56 |
||
57 |
^ self == MethodDictionary |
|
58 |
! ! |
|
59 |
||
60 |
!MethodDictionary class methodsFor:'instance creation'! |
|
61 |
||
62 |
new:sz |
|
63 |
^ self basicNew:(sz * 2) |
|
64 |
! ! |
|
65 |
||
66 |
!MethodDictionary methodsFor:'accessing'! |
|
67 |
||
68 |
size |
|
69 |
"return the number of elements (associations) in the receiver" |
|
70 |
||
71 |
^ self basicSize // 2 |
|
72 |
! |
|
73 |
||
74 |
at:key |
|
75 |
"return the value for a given key, which is supposed to be a symbol" |
|
76 |
||
77 |
|sz "{ Class: SmallInteger }"| |
|
78 |
||
79 |
sz := self basicSize. |
|
80 |
1 to:sz by:2 do:[:i | |
|
81 |
(self basicAt:i) == key ifTrue:[ |
|
82 |
^ self basicAt:(i + 1) |
|
83 |
] |
|
84 |
]. |
|
85 |
^ self errorKeyNotFound |
|
86 |
! |
|
87 |
||
88 |
at:key ifAbsent:exceptionBlock |
|
89 |
"return the element indexed by aKey - |
|
90 |
return result of exceptionBlock if no element is stored under aKey" |
|
91 |
||
92 |
|sz "{ Class: SmallInteger }"| |
|
93 |
||
94 |
sz := self basicSize. |
|
95 |
1 to:sz by:2 do:[:i | |
|
96 |
(self basicAt:i) == key ifTrue:[ |
|
97 |
^ self basicAt:(i + 1) |
|
98 |
] |
|
99 |
]. |
|
100 |
^ exceptionBlock value |
|
101 |
! |
|
102 |
||
103 |
associationAt:key |
|
104 |
"return an association consisting of aKey and the element indexed |
|
105 |
by aKey - |
|
106 |
report an error, if no element is stored under aKey." |
|
107 |
||
108 |
|sz "{ Class: SmallInteger }"| |
|
109 |
||
110 |
sz := self basicSize. |
|
111 |
1 to:sz by:2 do:[:i | |
|
112 |
(self basicAt:i) == key ifTrue:[ |
|
113 |
^ key -> (self basicAt:(i + 1)) |
|
114 |
] |
|
115 |
]. |
|
116 |
^ self errorKeyNotFound |
|
117 |
! |
|
118 |
||
119 |
at:key put:value |
|
120 |
"set the value for a given key, which is supposed to be a symbol. |
|
121 |
In contrast to dictionaries, we do not allow adding elements here." |
|
122 |
||
123 |
|sz "{ Class: SmallInteger }"| |
|
124 |
||
125 |
sz := self basicSize. |
|
126 |
1 to:sz by:2 do:[:i | |
|
127 |
(self basicAt:i) == key ifTrue:[ |
|
128 |
^ self basicAt:(i + 1) put:value |
|
129 |
] |
|
130 |
]. |
|
131 |
^ self errorKeyNotFound |
|
132 |
! ! |
|
133 |
||
134 |
!MethodDictionary methodsFor:'queries'! |
|
135 |
||
136 |
keys |
|
137 |
"return a collection containing all keys of the receiver" |
|
138 |
||
139 |
^ (1 to:self basicSize by:2) collect:[:index | self basicAt:index]. |
|
140 |
! |
|
141 |
||
142 |
||
143 |
!MethodDictionary methodsFor:'enumeration'! |
|
144 |
||
145 |
do:aBlock |
|
146 |
"evaluate the argument, aBlock for each element in the collection." |
|
147 |
||
148 |
|sz "{ Class: SmallInteger }"| |
|
149 |
||
150 |
sz := self basicSize. |
|
151 |
1 to:sz by:2 do:[:i | |
|
152 |
aBlock value:(self basicAt:i) |
|
153 |
]. |
|
154 |
! |
|
155 |
||
156 |
keysAndValuesDo:aBlock |
|
157 |
"evaluate the argument, aBlock for each element in the collection. |
|
158 |
Pass both index and element to the block." |
|
159 |
||
160 |
|sz "{ Class: SmallInteger }"| |
|
161 |
||
162 |
sz := self basicSize. |
|
163 |
1 to:sz by:2 do:[:i | |
|
164 |
aBlock value:(self basicAt:i) value:(self basicAt:(i + 1)) |
|
165 |
]. |
|
166 |
! ! |