author | Jan Vrany <jan.vrany@labware.com> |
Wed, 02 Aug 2023 13:04:52 +0100 | |
branch | jv |
changeset 25462 | 548cb62b20c7 |
parent 25447 | be0c3d4cdfd5 |
permissions | -rw-r--r-- |
24913
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
1 |
" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
2 |
COPYRIGHT (c) 2018 by eXept Software AG |
25447
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
3 |
COPYRIGHT (c) 2023 LabWare |
24913
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
4 |
All Rights Reserved |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
5 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
6 |
This software is furnished under a license and may be used |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
7 |
only in accordance with the terms of that license and with the |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
8 |
inclusion of the above copyright notice. This software may not |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
9 |
be provided or otherwise made available to, or used by, any |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
10 |
other person. No title to or ownership of the software is |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
11 |
hereby transferred. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
12 |
" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
14 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
15 |
"{ NameSpace: Smalltalk }" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
16 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
17 |
KeyedCollection subclass:#SmallDictionary |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
18 |
instanceVariableNames:'keysAndValues tally' |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
19 |
classVariableNames:'' |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
20 |
poolDictionaries:'' |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
21 |
category:'Collections-Unordered' |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
22 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
23 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
24 |
!SmallDictionary class methodsFor:'documentation'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
25 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
26 |
copyright |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
27 |
" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
28 |
COPYRIGHT (c) 2018 by eXept Software AG |
25447
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
29 |
COPYRIGHT (c) 2023 LabWare |
24913
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
30 |
All Rights Reserved |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
31 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
32 |
This software is furnished under a license and may be used |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
33 |
only in accordance with the terms of that license and with the |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
34 |
inclusion of the above copyright notice. This software may not |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
35 |
be provided or otherwise made available to, or used by, any |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
36 |
other person. No title to or ownership of the software is |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
37 |
hereby transferred. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
38 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
39 |
" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
40 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
41 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
42 |
documentation |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
43 |
" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
44 |
A lightweight Dictionary implementation (without hashing) |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
45 |
for small dictionaries. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
46 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
47 |
Use this, when you have to store a small number (e.g. < 20) key/value pairs. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
48 |
As a side effect of the implementation, the dictionary is also ordered. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
49 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
50 |
Inspired by and compatible with RBSmallDictionary from RefactoryBrowser |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
51 |
(although the implementaion is different). |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
52 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
53 |
[instance variables:] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
54 |
keysAndValues Array keys are stored at odd indices, values at even indices |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
55 |
tally SmallInterger the number of valid key/value pairs |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
56 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
57 |
[class variables:] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
58 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
59 |
[see also:] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
60 |
Dictionary |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
61 |
MethodDictionary |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
62 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
63 |
[author:] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
64 |
Stefan Vogel |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
65 |
" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
66 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
67 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
68 |
!SmallDictionary class methodsFor:'instance creation'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
69 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
70 |
new |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
71 |
^ self basicNew initialize:2 |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
72 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
73 |
"Modified: / 14-09-2018 / 15:58:29 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
74 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
75 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
76 |
new:capacity |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
77 |
^ self basicNew initialize:capacity |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
78 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
79 |
"Modified: / 14-09-2018 / 15:58:49 / Stefan Vogel" |
25447
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
80 |
! |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
81 |
|
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
82 |
withKeysAndValues: anArray |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
83 |
^ self basicNew initializeWithKeysAndValues: anArray |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
84 |
|
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
85 |
"Created: / 13-06-2023 / 11:42:50 / Jan Vrany <jan.vrany@labware.com>" |
24913
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
86 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
87 |
|
25447
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
88 |
|
24913
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
89 |
!SmallDictionary methodsFor:'accessing'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
90 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
91 |
at:key ifAbsent:aBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
92 |
"return the element indexed by aKey - |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
93 |
return result of exceptionBlock if no element is stored under aKey" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
94 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
95 |
|keyIndex "{Class: SmallInteger}"| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
96 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
97 |
keyIndex := keysAndValues indexOf:key startingAt:1 step:2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
98 |
^ keyIndex == 0 ifTrue:[aBlock value] ifFalse:[keysAndValues basicAt:keyIndex+1] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
99 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
100 |
"Modified: / 18-09-2018 / 14:08:21 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
101 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
102 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
103 |
at:key ifAbsentPut:aBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
104 |
"return the element indexed by aKey if present, |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
105 |
if not present, store the result of evaluating valueBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
106 |
under aKey and return it. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
107 |
WARNING: do not add elements while iterating over the receiver. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
108 |
Iterate over a copy to do this." |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
109 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
110 |
|keyIndex| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
111 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
112 |
keyIndex := keysAndValues indexOf:key startingAt:1 step:2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
113 |
keyIndex == 0 ifTrue:[ |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
114 |
^ self privateAt:key put:aBlock value |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
115 |
] ifFalse:[ |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
116 |
^ keysAndValues basicAt:keyIndex+1. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
117 |
] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
118 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
119 |
"Modified: / 18-09-2018 / 14:08:26 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
120 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
121 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
122 |
keys |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
123 |
"return a collection containing the keys of the receiver" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
124 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
125 |
|keys sz "{Class: SmallInteger}"| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
126 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
127 |
keys := Array new:tally. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
128 |
sz := tally. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
129 |
1 to:sz do:[:i | keys at:i put:(keysAndValues at:i*2-1)]. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
130 |
^ keys |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
131 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
132 |
"Created: / 14-09-2018 / 17:35:25 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
133 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
134 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
135 |
order |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
136 |
"returns the keys in the order of their appearance" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
137 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
138 |
^ self keys |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
139 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
140 |
" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
141 |
|s| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
142 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
143 |
s := SmallDictionary new. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
144 |
s at:#a put:'aaa'; at:#b put:'bbb'; at:#c put:'ccc'; at:#d put:'ddd'; at:#a put:'aaaa'. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
145 |
s order |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
146 |
" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
147 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
148 |
"Created: / 14-09-2018 / 17:30:44 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
149 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
150 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
151 |
size |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
152 |
"return the number of elements in the receiver." |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
153 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
154 |
^ tally |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
155 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
156 |
"Modified (format): / 14-09-2018 / 15:44:11 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
157 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
158 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
159 |
!SmallDictionary methodsFor:'adding'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
160 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
161 |
add:anAssociation |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
162 |
"add the argument, anAssociation to the receiver. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
163 |
Returns the argument, anAssociation. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
164 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
165 |
WARNING: do not add elements while iterating over the receiver. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
166 |
Iterate over a copy to do this." |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
167 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
168 |
self at:anAssociation key put:anAssociation value. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
169 |
^ anAssociation |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
170 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
171 |
"Modified (format): / 14-09-2018 / 15:25:38 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
172 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
173 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
174 |
at:key put:value |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
175 |
"add the argument anObject under key, aKey to the receiver. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
176 |
Return anObject (sigh). |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
177 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
178 |
WARNING: do not add elements while iterating over the receiver. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
179 |
Iterate over a copy to do this." |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
180 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
181 |
|keyIndex| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
182 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
183 |
"/ specially tuned for single-element small dicts (most are) |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
184 |
tally == 0 ifTrue:[ |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
185 |
keysAndValues size >= 2 ifTrue:[ |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
186 |
keysAndValues basicAt:1 put:key. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
187 |
keysAndValues basicAt:2 put:value. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
188 |
tally := 1. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
189 |
^ self. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
190 |
]. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
191 |
]. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
192 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
193 |
keyIndex := keysAndValues indexOf:key startingAt:1 step:2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
194 |
keyIndex == 0 ifTrue:[ |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
195 |
self privateAt:key put:value |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
196 |
] ifFalse:[ |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
197 |
keysAndValues basicAt:keyIndex+1 put:value. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
198 |
]. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
199 |
^ value |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
200 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
201 |
"Modified: / 18-09-2018 / 14:12:13 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
202 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
203 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
204 |
!SmallDictionary methodsFor:'copying-private'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
205 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
206 |
postCopy |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
207 |
keysAndValues := keysAndValues copy. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
208 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
209 |
"Modified: / 14-09-2018 / 15:38:50 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
210 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
211 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
212 |
!SmallDictionary methodsFor:'enumerating'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
213 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
214 |
do:aBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
215 |
"enumerate the values" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
216 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
217 |
|sz "{Class: SmallInteger}"| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
218 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
219 |
sz := tally * 2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
220 |
2 to:sz by:2 do:[:i | aBlock value:(keysAndValues at:i)] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
221 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
222 |
"Modified: / 14-09-2018 / 16:30:18 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
223 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
224 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
225 |
keysAndValuesDo:aBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
226 |
|sz "{Class: SmallInteger}"| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
227 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
228 |
sz := tally * 2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
229 |
1 to:sz-1 by:2 do:[:i | |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
230 |
aBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
231 |
value:(keysAndValues at:i) |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
232 |
value:(keysAndValues at:i+1)] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
233 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
234 |
"Modified: / 14-09-2018 / 16:31:18 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
235 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
236 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
237 |
keysDo:aBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
238 |
|sz "{Class: SmallInteger}"| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
239 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
240 |
sz := tally * 2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
241 |
1 to:sz-1 by:2 do:[:i | aBlock value:(keysAndValues at:i)] |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
242 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
243 |
"Modified: / 14-09-2018 / 16:30:51 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
244 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
245 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
246 |
!SmallDictionary methodsFor:'initialize-release'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
247 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
248 |
initialize:capacity |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
249 |
keysAndValues := Array new:capacity*2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
250 |
tally := 0 |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
251 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
252 |
"Created: / 14-09-2018 / 15:57:42 / Stefan Vogel" |
25447
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
253 |
! |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
254 |
|
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
255 |
initializeWithKeysAndValues: anArray |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
256 |
(anArray size \\ 2) ~~ 0 ifTrue: [ |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
257 |
self error: 'Invalid keys and values array - odd number of elements' |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
258 |
]. |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
259 |
|
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
260 |
keysAndValues := anArray. |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
261 |
tally := anArray size // 2. |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
262 |
|
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
263 |
"Created: / 13-06-2023 / 11:38:49 / Jan Vrany <jan.vrany@labware.com>" |
24913
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
264 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
265 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
266 |
!SmallDictionary methodsFor:'private'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
267 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
268 |
grow:capacity |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
269 |
|newKeysAndValues| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
270 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
271 |
newKeysAndValues := Array new:capacity*2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
272 |
newKeysAndValues replaceFrom:1 to:tally * 2 with:keysAndValues. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
273 |
keysAndValues := newKeysAndValues. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
274 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
275 |
"Created: / 18-09-2018 / 15:37:24 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
276 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
277 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
278 |
growKeysAndValues |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
279 |
"duplicate the capacity" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
280 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
281 |
self grow:tally * 2 |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
282 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
283 |
"Modified: / 18-09-2018 / 15:37:34 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
284 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
285 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
286 |
privateAt:key put:value |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
287 |
|sz "{Class: SmallInteger}"| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
288 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
289 |
sz := tally * 2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
290 |
sz == keysAndValues size ifTrue: [self growKeysAndValues]. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
291 |
keysAndValues |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
292 |
basicAt:sz+1 put:key; |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
293 |
basicAt:sz+2 put:value. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
294 |
tally := tally + 1. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
295 |
^ value. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
296 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
297 |
"Modified: / 18-09-2018 / 13:33:30 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
298 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
299 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
300 |
!SmallDictionary methodsFor:'queries'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
301 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
302 |
includesKey:aKey |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
303 |
^ (keysAndValues indexOf:aKey startingAt:1 step:2) ~~ 0 |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
304 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
305 |
"Modified: / 18-09-2018 / 14:09:03 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
306 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
307 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
308 |
isEmpty |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
309 |
^ tally == 0 |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
310 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
311 |
"Created: / 14-09-2018 / 15:44:49 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
312 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
313 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
314 |
speciesForCollecting |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
315 |
^ Bag |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
316 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
317 |
"Created: / 18-09-2018 / 15:34:27 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
318 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
319 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
320 |
!SmallDictionary methodsFor:'removing'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
321 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
322 |
empty |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
323 |
"RefactoryBrowser compatibility" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
324 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
325 |
self removeAll |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
326 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
327 |
"Modified: / 14-09-2018 / 15:59:57 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
328 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
329 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
330 |
remove:anAssociation ifAbsent:anExceptionBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
331 |
self removeKey:(anAssociation key) ifAbsent:anExceptionBlock. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
332 |
^ anAssociation |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
333 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
334 |
"Modified (format): / 14-09-2018 / 15:40:44 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
335 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
336 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
337 |
removeAll |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
338 |
tally := 0. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
339 |
keysAndValues atAllPut:nil. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
340 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
341 |
"Modified: / 14-09-2018 / 16:02:28 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
342 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
343 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
344 |
removeKey:key ifAbsent:aBlock |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
345 |
|keyIndex "{Class:SmallInteger}" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
346 |
sz "{Class:SmallInteger}" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
347 |
value| |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
348 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
349 |
keyIndex := keysAndValues indexOf:key startingAt:1 step:2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
350 |
keyIndex == 0 ifTrue:[ |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
351 |
^ aBlock value |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
352 |
]. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
353 |
value := keysAndValues at:keyIndex+1. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
354 |
sz := tally*2. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
355 |
keyIndex to:sz-2 do:[:i | |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
356 |
keysAndValues at:i put:(keysAndValues at:i + 2). |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
357 |
]. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
358 |
keysAndValues at:sz-1 put:nil. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
359 |
keysAndValues at:sz put:nil. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
360 |
tally := tally - 1. |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
361 |
^ value |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
362 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
363 |
"Modified: / 18-09-2018 / 14:09:15 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
364 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
365 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
366 |
!SmallDictionary methodsFor:'testing'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
367 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
368 |
isDictionary |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
369 |
"return true, if the receiver is some kind of dictionary; |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
370 |
true returned here - the method is redefined from Object." |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
371 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
372 |
^ true |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
373 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
374 |
"Created: / 14-09-2018 / 18:31:24 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
375 |
! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
376 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
377 |
isFixedSize |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
378 |
"return true if the receiver cannot grow - this will vanish once |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
379 |
Arrays and Strings learn how to grow ..." |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
380 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
381 |
^ false |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
382 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
383 |
"Created: / 18-09-2018 / 15:35:25 / Stefan Vogel" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
384 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
385 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
386 |
!SmallDictionary methodsFor:'visiting'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
387 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
388 |
acceptVisitor:aVisitor with:aParameter |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
389 |
"dispatch for visitor pattern; send #visitDictionary:with: to aVisitor" |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
390 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
391 |
^ aVisitor visitDictionary:self with:aParameter |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
392 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
393 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
394 |
!SmallDictionary class methodsFor:'documentation'! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
395 |
|
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
396 |
version_CVS |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
397 |
^ '$Header$' |
25447
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
398 |
! |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
399 |
|
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
400 |
version_HG |
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
401 |
|
be0c3d4cdfd5
Implement `SmallDictionary >> withKeysAndValues:`
Jan Vrany <jan.vrany@labware.com>
parents:
24913
diff
changeset
|
402 |
^ '$Changeset: <not expanded> $' |
24913
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
403 |
! ! |
a8c2e208c890
Cherry picked `SmallDictionary` from eXept's head.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff
changeset
|
404 |