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