MethodDictionary.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 23823 3bb336d73111
child 24480 ba11b0600aa7
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21656
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
     1
"{ Encoding: utf8 }"
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
     2
328
claus
parents:
diff changeset
     3
"
2183
a2811a1d1037 may not use replaceFrom:,
Claus Gittinger <cg@exept.de>
parents: 2110
diff changeset
     4
 COPYRIGHT (c) 1995 by eXept Software AG
2110
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
     5
              All Rights Reserved
328
claus
parents:
diff changeset
     6
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    12
 hereby transferred.
claus
parents:
diff changeset
    13
"
5557
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 3460
diff changeset
    14
"{ Package: 'stx:libbasic' }"
f5f8d236027c category change
Claus Gittinger <cg@exept.de>
parents: 3460
diff changeset
    15
19843
4ce3c7f4d168 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17251
diff changeset
    16
"{ NameSpace: Smalltalk }"
4ce3c7f4d168 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17251
diff changeset
    17
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
    18
KeyedCollection variableSubclass:#MethodDictionary
2246
57451418f10a make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents: 2183
diff changeset
    19
	instanceVariableNames:''
23819
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    20
	classVariableNames:'EmptySingleton'
2246
57451418f10a make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents: 2183
diff changeset
    21
	poolDictionaries:''
57451418f10a make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents: 2183
diff changeset
    22
	category:'Kernel-Methods'
328
claus
parents:
diff changeset
    23
!
claus
parents:
diff changeset
    24
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
    25
!MethodDictionary class methodsFor:'documentation'!
328
claus
parents:
diff changeset
    26
claus
parents:
diff changeset
    27
copyright
claus
parents:
diff changeset
    28
"
2183
a2811a1d1037 may not use replaceFrom:,
Claus Gittinger <cg@exept.de>
parents: 2110
diff changeset
    29
 COPYRIGHT (c) 1995 by eXept Software AG
2110
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
    30
              All Rights Reserved
328
claus
parents:
diff changeset
    31
claus
parents:
diff changeset
    32
 This software is furnished under a license and may be used
claus
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    37
 hereby transferred.
claus
parents:
diff changeset
    38
"
claus
parents:
diff changeset
    39
!
claus
parents:
diff changeset
    40
claus
parents:
diff changeset
    41
documentation
claus
parents:
diff changeset
    42
"
claus
parents:
diff changeset
    43
    Instances of MethodDictionary store selector/method associations
8467
f25892c63a56 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
    44
    in classes. Conceptionally, they behave like IdentityDictionaries, but are
f25892c63a56 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
    45
    implemented using a single array (instead of Dictionary, which uses
328
claus
parents:
diff changeset
    46
    two arrays to store keys and values separately).
claus
parents:
diff changeset
    47
    Also, they do not use hashing, since due to caching in the VM, hashing
claus
parents:
diff changeset
    48
    does not make too much of a difference in speed, but complicates the 
8467
f25892c63a56 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
    49
    VM implementation.
1465
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    50
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    51
    [author:]
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    52
        Stefan Vogel
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    53
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    54
    [see also:]
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    55
        Dictionary
8467
f25892c63a56 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
    56
        IdentityDictionary
1465
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    57
        Behavior Class
8467
f25892c63a56 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
    58
        Method 
f25892c63a56 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 5557
diff changeset
    59
        Symbol
328
claus
parents:
diff changeset
    60
"
claus
parents:
diff changeset
    61
! !
claus
parents:
diff changeset
    62
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
    63
!MethodDictionary class methodsFor:'instance creation'!
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    64
23819
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    65
new 
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    66
    "create and return an empty methodDictionary.
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    67
     Because mDicts cannot grow, we return a singleton
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    68
     (if any selectors are added later, a new instance
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    69
      will be created anyway).
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    70
     Using a singleton will speed up dynamic creation of
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    71
     new classes which will be filled in later"
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    72
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    73
    EmptySingleton isNil ifTrue:[
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    74
        EmptySingleton := super new.
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    75
    ].    
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    76
    ^ EmptySingleton
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    77
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    78
    "Created: / 03-03-2019 / 15:27:43 / Claus Gittinger"
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    79
!
8803cc371eca #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22309
diff changeset
    80
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    81
new:sz 
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
    82
    "create and return a new methodDictionary holding sz
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
    83
     key->value associations"
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
    84
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    85
    ^ self basicNew:(sz * 2)
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    86
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    87
22309
a48cd79a42a5 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21656
diff changeset
    88
newWithCapacity:size
a48cd79a42a5 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21656
diff changeset
    89
    "return a new empty Collection with capacity for n elements."
a48cd79a42a5 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21656
diff changeset
    90
a48cd79a42a5 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21656
diff changeset
    91
    ^ self new:size
a48cd79a42a5 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21656
diff changeset
    92
a48cd79a42a5 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21656
diff changeset
    93
    "Created: / 10-10-2017 / 17:51:14 / stefan"
a48cd79a42a5 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21656
diff changeset
    94
!
a48cd79a42a5 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21656
diff changeset
    95
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    96
withAll:aDictionary
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    97
    "create a MethodDictionary from another Dictionary"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    98
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
    99
    |newDict i "{ 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
    newDict := self new:aDictionary size.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   102
    i := 1.
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   103
    aDictionary keysAndValuesDo:[:key :value |
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   104
        newDict basicAt:i   put:key.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   105
        newDict basicAt:i+1 put:value.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   106
        i := i+2.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   107
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   108
    ^ newDict
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   109
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   110
    "
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   111
        |d|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   112
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   113
        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
   114
        MethodDictionary withAll:d.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   115
    "
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   116
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   117
    "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
   118
    "Modified: 12.6.1996 / 13:56:36 / stefan"
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   119
    "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
   120
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   121
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   122
withKeys:keys andValues:values
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   123
    "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
   124
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   125
    |inst 
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   126
     sz "{ Class: SmallInteger }"
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   127
     idx "{ Class: SmallInteger }" |
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   128
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   129
    sz := keys size.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   130
    inst := self new:sz.
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   131
    idx := 2.
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   132
    1 to:sz do:[:i |
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   133
        inst basicAt:(idx-1)  put:(keys   at:i).
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   134
        inst basicAt:(idx)    put:(values at:i).
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   135
	idx := idx + 2.
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   136
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   137
    ^ inst
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   138
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   139
    "Created: 12.6.1996 / 13:46:43 / stefan"
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   140
    "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
   141
! !
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   142
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   143
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
   144
!MethodDictionary class methodsFor:'queries'!
328
claus
parents:
diff changeset
   145
claus
parents:
diff changeset
   146
isBuiltInClass
claus
parents:
diff changeset
   147
    "this class is known by the run-time-system"
claus
parents:
diff changeset
   148
claus
parents:
diff changeset
   149
    ^ self == MethodDictionary
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   150
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   151
    "Modified: / 08-08-2006 / 16:06:26 / cg"
328
claus
parents:
diff changeset
   152
! !
claus
parents:
diff changeset
   153
claus
parents:
diff changeset
   154
!MethodDictionary methodsFor:'accessing'!
claus
parents:
diff changeset
   155
claus
parents:
diff changeset
   156
at:key ifAbsent:exceptionBlock
claus
parents:
diff changeset
   157
    "return the element indexed by aKey - 
claus
parents:
diff changeset
   158
     return result of exceptionBlock if no element is stored under aKey"
claus
parents:
diff changeset
   159
claus
parents:
diff changeset
   160
    |sz "{ Class: SmallInteger }"|
claus
parents:
diff changeset
   161
claus
parents:
diff changeset
   162
    sz := self basicSize.
claus
parents:
diff changeset
   163
    1 to:sz by:2 do:[:i |
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   164
        (self basicAt:i) == key ifTrue:[^ self basicAt:(i + 1)]
328
claus
parents:
diff changeset
   165
    ].
claus
parents:
diff changeset
   166
    ^ exceptionBlock value
claus
parents:
diff changeset
   167
!
claus
parents:
diff changeset
   168
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   169
at:key put:value 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   170
    "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
   171
     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
   172
     empty slot (nil key) present."
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   173
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   174
    |slot sz "{ Class: SmallInteger }"|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   175
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   176
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   177
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   178
        slot := self basicAt:i.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   179
        (slot == key) ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   180
            ^ self basicAt:(i + 1) put:value
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   181
        ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   182
        slot isNil ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   183
            self basicAt:i put:key.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   184
            ^ self basicAt:(i + 1) put:value
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   185
        ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   186
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   187
    ^ self errorKeyNotFound:key
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   188
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   189
    "Modified: 7.6.1996 / 09:39:04 / stefan"
2246
57451418f10a make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents: 2183
diff changeset
   190
    "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
   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
at:key putOrAppend:value 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   194
    "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
   195
     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
   196
     empty slot (nil key) present.
2246
57451418f10a make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents: 2183
diff changeset
   197
     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
   198
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   199
    |slot emptySlot newDict sz "{ Class: SmallInteger }"|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   200
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   201
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   202
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   203
        slot := self basicAt:i.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   204
        (slot == key) ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   205
            self basicAt:(i + 1) put:value .
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   206
            ^ self.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   207
        ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   208
        slot isNil ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   209
            emptySlot := i.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   210
        ]
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   211
    ].
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
    emptySlot notNil ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   214
        self basicAt:emptySlot       put:key.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   215
        self basicAt:(emptySlot + 1) put:value.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   216
        ^ self.
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
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   219
    "/ not enough room for new entry, copy to new dictionary
2406
ca517087511a oops - ever growing dictionary
ca
parents: 2402
diff changeset
   220
    newDict := self class new:sz//2+1.
2183
a2811a1d1037 may not use replaceFrom:,
Claus Gittinger <cg@exept.de>
parents: 2110
diff changeset
   221
21656
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   222
"/ cannot do this (not defined in Object!!)  ...
2183
a2811a1d1037 may not use replaceFrom:,
Claus Gittinger <cg@exept.de>
parents: 2110
diff changeset
   223
"/    newDict replaceFrom:1 to:sz with:self startingAt:1.
a2811a1d1037 may not use replaceFrom:,
Claus Gittinger <cg@exept.de>
parents: 2110
diff changeset
   224
"/ must use basicAt
a2811a1d1037 may not use replaceFrom:,
Claus Gittinger <cg@exept.de>
parents: 2110
diff changeset
   225
    1 to:sz do:[:i |
2246
57451418f10a make certain, loops are inlined
Claus Gittinger <cg@exept.de>
parents: 2183
diff changeset
   226
        newDict basicAt:i put:(self basicAt:i).
2183
a2811a1d1037 may not use replaceFrom:,
Claus Gittinger <cg@exept.de>
parents: 2110
diff changeset
   227
    ].
a2811a1d1037 may not use replaceFrom:,
Claus Gittinger <cg@exept.de>
parents: 2110
diff changeset
   228
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   229
    newDict basicAt:(sz+1) put:key.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   230
    newDict basicAt:(sz+2) put:value.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   231
    ^ newDict.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   232
21656
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   233
    "Created: / 07-06-1996 / 15:01:54 / stefan"
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   234
    "Modified: / 07-06-1996 / 17:32:40 / stefan"
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   235
    "Modified: / 23-01-1997 / 14:00:03 / cg"
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   236
    "Modified (comment): / 17-03-2017 / 11:26:44 / stefan"
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   237
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   238
21370
7a58ed21b4d8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21266
diff changeset
   239
keyAtIdenticalValue:value ifAbsent:exceptionBlock
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   240
    "return the first key with value - 
21370
7a58ed21b4d8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21266
diff changeset
   241
     return result of exceptionBlock if no key can be found.
7a58ed21b4d8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21266
diff changeset
   242
     This is a slow access, since the receiver is searched sequentially.
7a58ed21b4d8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21266
diff changeset
   243
     NOTICE:
7a58ed21b4d8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21266
diff changeset
   244
        The value is searched using identity compare"
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   245
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   246
    |sz "{ Class: SmallInteger }"|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   247
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   248
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   249
    2 to:sz by:2 do:[:i |
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2798
diff changeset
   250
        (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
   251
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   252
    ^ exceptionBlock value
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   253
21370
7a58ed21b4d8 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21266
diff changeset
   254
    "Created: / 07-02-2017 / 11:14:40 / cg"
21654
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   255
!
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   256
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   257
keyAtValue:value
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   258
    "return the key under which value is stored.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   259
     Raise an error if not found.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   260
     This is a slow access, since the receiver is searched sequentially.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   261
     NOTICE:
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   262
        The value is searched using identity compare.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   263
        use #keyAtEqualValue:ifAbsent: to compare for equality."
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   264
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   265
    ^ self keyAtIdenticalValue:value.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   266
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   267
    "Created: / 19-06-1998 / 00:49:16 / cg"
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   268
    "Modified (comment): / 07-02-2017 / 11:13:29 / cg"
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   269
!
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   270
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   271
keyAtValue:value ifAbsent:exceptionBlock
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   272
    "return the key under which value is stored.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   273
     If not found, return the value from evaluating exceptionBlock.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   274
     This is a slow access, since the receiver is searched sequentially.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   275
     NOTICE:
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   276
        The value is searched using identity compare;
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   277
        use #keyAtEqualValue:ifAbsent: to compare for equality."
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   278
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   279
    ^ self keyAtIdenticalValue:value ifAbsent:exceptionBlock.
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   280
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   281
    "Created: / 19-06-1998 / 00:50:34 / cg"
cd8f5a3cbdd6 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21370
diff changeset
   282
    "Modified: / 07-02-2017 / 11:13:20 / cg"
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   283
! !
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   284
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   285
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   286
!MethodDictionary methodsFor:'enumerating'!
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   287
17251
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   288
do:aBlock
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   289
    "evaluate aBlock for each value (i.e. each method)"
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   290
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   291
    |key value sz "{ Class: SmallInteger }"|
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   292
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   293
    sz := self basicSize.
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   294
    1 to:sz by:2 do:[:i |
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   295
        key := self basicAt:i. 
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   296
        key notNil ifTrue:[
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   297
            value := self basicAt:(i+1).
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   298
            value notNil ifTrue:[
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   299
                aBlock value:value.
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   300
            ]
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   301
        ]
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   302
    ].
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   303
!
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   304
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   305
keysAndValuesDo:aBlock
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   306
    "evaluate the 2 arg block aBlock for each key (i.e. each selector)
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   307
     and each value (i.e. each method)"
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   308
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   309
    |key value sz "{ Class: SmallInteger }"|
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   310
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   311
    sz := self basicSize.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   312
    1 to:sz by:2 do:[:i |
21656
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   313
        key := self basicAt:i. 
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   314
        value := self basicAt:(i+1).
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   315
        (key notNil and:[value notNil]) ifTrue:[
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   316
            aBlock value:key value:value.
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   317
        ]
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   318
    ].
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   319
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   320
    "Created: / 07-06-1996 / 09:27:42 / stefan"
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   321
    "Modified: / 08-08-2006 / 16:11:30 / cg"
21656
d0426621ce99 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21654
diff changeset
   322
    "Modified: / 17-03-2017 / 11:07:07 / stefan"
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   323
! !
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   324
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   325
!MethodDictionary methodsFor:'private'!
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   326
23821
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   327
atIndex:idx putKey:key andValue:value 
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   328
    "set the key, which is supposed to be a symbol,
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   329
     and the value at idx.
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   330
     Only use this to initialize a methodDictionary fast,
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   331
     when the set of methods is known beforehand 
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   332
     (avoids search for nil slots)"
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   333
23823
3bb336d73111 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23822
diff changeset
   334
    self basicAt:(idx*2)-1 put:key.
3bb336d73111 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23822
diff changeset
   335
    self basicAt:(idx*2) put:value
23821
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   336
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   337
    "Created: / 03-03-2019 / 19:18:44 / Claus Gittinger"
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   338
!
f6440feca8f9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23819
diff changeset
   339
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   340
compressed
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   341
    "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
   342
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   343
    |newDict tally key mySize
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   344
     dstIndex "{ Class: SmallInteger }" 
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   345
     sz       "{ Class: SmallInteger }" |
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   346
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   347
    sz := self basicSize.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   348
    mySize := sz // 2.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   349
    tally := 0.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   350
    1 to:sz by:2 do:[:i |
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   351
        (self basicAt:i) notNil ifTrue:[
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   352
            tally := tally + 1
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   353
        ]
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   354
    ].
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   355
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   356
    tally == mySize ifTrue:[^ self].
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   357
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   358
    newDict := self species new:tally.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   359
    dstIndex := 1.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   360
    1 to:sz by:2 do:[:i |
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   361
        key := self basicAt:i.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   362
        key notNil ifTrue:[
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   363
           newDict basicAt:dstIndex   put:key.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   364
           newDict basicAt:dstIndex+1 put:(self basicAt:i+1).
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   365
           dstIndex := dstIndex + 2.
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   366
        ]
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   367
    ].
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   368
    ^ newDict
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   369
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   370
    "Modified: / 05-08-2004 / 20:05:44 / stefan"
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   371
! !
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   372
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   373
!MethodDictionary methodsFor:'queries'!
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   374
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   375
size
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   376
    "return the number of elements (associations) in the receiver"
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   377
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   378
    ^ self basicSize // 2
21266
afdca9f67ead #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19843
diff changeset
   379
!
afdca9f67ead #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19843
diff changeset
   380
afdca9f67ead #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19843
diff changeset
   381
speciesForCollecting
afdca9f67ead #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19843
diff changeset
   382
    ^ Bag
afdca9f67ead #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19843
diff changeset
   383
afdca9f67ead #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19843
diff changeset
   384
    "Created: / 20-01-2017 / 18:07:53 / stefan"
9481
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   385
! !
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   386
08aa83ec59c2 inheritance changed
Claus Gittinger <cg@exept.de>
parents: 9444
diff changeset
   387
!MethodDictionary methodsFor:'removing'!
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   388
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   389
removeKey:key ifAbsent:failBlock
19843
4ce3c7f4d168 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17251
diff changeset
   390
    "remove key from dictionary, 
4ce3c7f4d168 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17251
diff changeset
   391
     return the value previously stored there.
4ce3c7f4d168 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17251
diff changeset
   392
     If it was not in the collection return the result
4ce3c7f4d168 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17251
diff changeset
   393
     from evaluating failBlock.
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   394
     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
   395
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   396
    |value sz "{ Class: SmallInteger }"|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   397
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   398
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   399
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   400
        (self basicAt:i) == key ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   401
           value := self basicAt:(i + 1).
9444
c7134e0aa248 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8467
diff changeset
   402
           self basicAt:i put:nil. 
c7134e0aa248 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8467
diff changeset
   403
           self basicAt:(i+1) put:nil.
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   404
           ^ value
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   405
        ]
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   406
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   407
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
   408
    ^ failBlock value.
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   409
9444
c7134e0aa248 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8467
diff changeset
   410
    "Created: / 07-06-1996 / 15:57:56 / stefan"
c7134e0aa248 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8467
diff changeset
   411
    "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
   412
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   413
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   414
removeKeyAndCompress:key
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   415
    "remove key from dictionary. 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   416
     A new, compressed MethodDictionary will be returned,
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   417
     or nil, if key is not present."
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   418
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   419
    |newDict dstIndex sz "{ Class: SmallInteger }"|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   420
2402
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   421
    sz := self basicSize.
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   422
    1 to:sz by:2 do:[:i |
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   423
        (self basicAt:i) == key ifTrue:[
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   424
            dstIndex := i
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   425
        ]
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   426
    ].
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   427
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   428
    dstIndex isNil ifTrue:[^ self].
1508
960d6e7e563b removeKeyAndCompress - failed if key was not present.
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
   429
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   430
    sz := self basicSize.
2406
ca517087511a oops - ever growing dictionary
ca
parents: 2402
diff changeset
   431
    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
   432
    dstIndex := 1.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   433
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   434
        (self basicAt:i) ~~ key ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   435
           newDict basicAt:dstIndex   put:(self basicAt:i).
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   436
           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
   437
           dstIndex := dstIndex + 2.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   438
        ]
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   439
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   440
    dstIndex > sz ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   441
        ^ nil
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   442
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   443
    ^ newDict
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   444
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   445
    "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
   446
    "Modified: 7.6.1996 / 16:47:02 / stefan"
2402
fc35bd8b4343 #identityIndexOf: is not allowed;
Claus Gittinger <cg@exept.de>
parents: 2386
diff changeset
   447
    "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
   448
! !
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   449
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
   450
!MethodDictionary class methodsFor:'documentation'!
328
claus
parents:
diff changeset
   451
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   452
version
19843
4ce3c7f4d168 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17251
diff changeset
   453
    ^ '$Header$'
13514
Claus Gittinger <cg@exept.de>
parents: 13513
diff changeset
   454
!
Claus Gittinger <cg@exept.de>
parents: 13513
diff changeset
   455
Claus Gittinger <cg@exept.de>
parents: 13513
diff changeset
   456
version_CVS
19843
4ce3c7f4d168 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17251
diff changeset
   457
    ^ '$Header$'
328
claus
parents:
diff changeset
   458
! !
17251
43078c56ed69 class: MethodDictionary
Claus Gittinger <cg@exept.de>
parents: 13514
diff changeset
   459