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