MethodDictionary.st
author Claus Gittinger <cg@exept.de>
Sat, 11 Jan 1997 13:14:19 +0100
changeset 2145 d243ffafeae3
parent 2110 3c531e1ab7c1
child 2183 a2811a1d1037
permissions -rw-r--r--
more docu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
328
claus
parents:
diff changeset
     1
"
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
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
claus
parents:
diff changeset
    13
Array subclass:#MethodDictionary
2110
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
    14
        instanceVariableNames:''
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
    15
        classVariableNames:''
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
    16
        poolDictionaries:''
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
    17
        category:'Kernel-Methods'
328
claus
parents:
diff changeset
    18
!
claus
parents:
diff changeset
    19
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
    20
!MethodDictionary class methodsFor:'documentation'!
328
claus
parents:
diff changeset
    21
claus
parents:
diff changeset
    22
copyright
claus
parents:
diff changeset
    23
"
claus
parents:
diff changeset
    24
 COPYRIGHT (c) 1995 by Claus Gittinger
2110
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
    25
              All Rights Reserved
328
claus
parents:
diff changeset
    26
claus
parents:
diff changeset
    27
 This software is furnished under a license and may be used
claus
parents:
diff changeset
    28
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
    30
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
    31
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    32
 hereby transferred.
claus
parents:
diff changeset
    33
"
claus
parents:
diff changeset
    34
!
claus
parents:
diff changeset
    35
claus
parents:
diff changeset
    36
documentation
claus
parents:
diff changeset
    37
"
claus
parents:
diff changeset
    38
    Instances of MethodDictionary store selector/method associations
claus
parents:
diff changeset
    39
    in classes. Conceptionally, they behave like Dictionaries, but are
claus
parents:
diff changeset
    40
    implemented using a single array (instead of dictionary, which uses
claus
parents:
diff changeset
    41
    two arrays to store keys and values separately).
claus
parents:
diff changeset
    42
    Also, they do not use hashing, since due to caching in the VM, hashing
claus
parents:
diff changeset
    43
    does not make too much of a difference in speed, but complicates the 
claus
parents:
diff changeset
    44
    VM implementations.
1465
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    45
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    46
    [author:]
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    47
        Stefan Vogel
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    48
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    49
    [see also:]
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    50
        Dictionary
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    51
        Behavior Class
Claus Gittinger <cg@exept.de>
parents: 1461
diff changeset
    52
        Method Symbol
328
claus
parents:
diff changeset
    53
"
claus
parents:
diff changeset
    54
! !
claus
parents:
diff changeset
    55
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
    56
!MethodDictionary class methodsFor:'instance creation'!
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    57
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    58
new:sz 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    59
    ^ self basicNew:(sz * 2)
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
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    62
withAll:aDictionary
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    63
    "create a MethodDictionary from another Dictionary"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    64
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
    65
    |newDict i "{ Class: SmallInteger }" |
1461
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
    newDict := self new:aDictionary size.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    68
    i := 1.
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
    69
    aDictionary keysAndValuesDo:[:key :value |
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    70
        newDict basicAt:i   put:key.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    71
        newDict basicAt:i+1 put:value.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    72
        i := i+2.
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
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    75
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    76
    "
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    77
        |d|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    78
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    79
        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
    80
        MethodDictionary withAll:d.
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
    "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
    84
    "Modified: 12.6.1996 / 13:56:36 / stefan"
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
    85
    "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
    86
!
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
withKeys:keys andValues:values
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    89
    "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
    90
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
    91
    |inst sz "{ Class: SmallInteger }" |
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
    sz := keys size.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    94
    inst := self new:sz.
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
    95
    1 to:sz do:[:i |
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    96
        inst basicAt:(i*2)-1  put:(keys   at:i).
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    97
        inst basicAt:(i*2)    put:(values at:i).
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    98
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
    99
    ^ inst
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
    "Created: 12.6.1996 / 13:46:43 / stefan"
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   102
    "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
   103
! !
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   104
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
   105
!MethodDictionary class methodsFor:'binary storage'!
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   106
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   107
binaryFullDefinitionFrom:stream manager:manager
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   108
   |size "{ Class: SmallInteger }" 
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   109
    inst|
1461
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
   size := manager nextObject.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   112
   inst := self new:size.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   113
   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
   114
        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
   115
        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
   116
   ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   117
   ^ inst
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   118
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   119
    "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
   120
    "Modified: 7.6.1996 / 13:52:08 / stefan"
1519
dd761a313ead added a typeHint
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   121
    "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
   122
! !
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   123
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
   124
!MethodDictionary class methodsFor:'queries'!
328
claus
parents:
diff changeset
   125
claus
parents:
diff changeset
   126
isBuiltInClass
claus
parents:
diff changeset
   127
    "this class is known by the run-time-system"
claus
parents:
diff changeset
   128
claus
parents:
diff changeset
   129
    ^ self == MethodDictionary
claus
parents:
diff changeset
   130
! !
claus
parents:
diff changeset
   131
claus
parents:
diff changeset
   132
!MethodDictionary methodsFor:'accessing'!
claus
parents:
diff changeset
   133
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   134
associationAt:key 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   135
    "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
   136
     by aKey - 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   137
     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
   138
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   139
    |sz "{ Class: SmallInteger }"|
328
claus
parents:
diff changeset
   140
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   141
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   142
    1 to:sz by:2 do:[:i |
2110
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
   143
        (self basicAt:i) == key ifTrue:[
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
   144
            ^ key -> (self basicAt:(i + 1))
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
   145
        ]
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   146
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   147
    ^ self errorKeyNotFound
328
claus
parents:
diff changeset
   148
!
claus
parents:
diff changeset
   149
claus
parents:
diff changeset
   150
at:key 
claus
parents:
diff changeset
   151
    "return the value for a given key, which is supposed to be a symbol"
claus
parents:
diff changeset
   152
claus
parents:
diff changeset
   153
    |sz "{ Class: SmallInteger }"|
claus
parents:
diff changeset
   154
claus
parents:
diff changeset
   155
    sz := self basicSize.
claus
parents:
diff changeset
   156
    1 to:sz by:2 do:[:i |
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   157
        (self basicAt:i) == key ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   158
            ^ self basicAt:(i + 1)
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   159
        ]
328
claus
parents:
diff changeset
   160
    ].
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   161
    ^ self errorKeyNotFound:key
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   162
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   163
    "Modified: 7.6.1996 / 15:53:28 / stefan"
328
claus
parents:
diff changeset
   164
!
claus
parents:
diff changeset
   165
claus
parents:
diff changeset
   166
at:key ifAbsent:exceptionBlock
claus
parents:
diff changeset
   167
    "return the element indexed by aKey - 
claus
parents:
diff changeset
   168
     return result of exceptionBlock if no element is stored under aKey"
claus
parents:
diff changeset
   169
claus
parents:
diff changeset
   170
    |sz "{ Class: SmallInteger }"|
claus
parents:
diff changeset
   171
claus
parents:
diff changeset
   172
    sz := self basicSize.
claus
parents:
diff changeset
   173
    1 to:sz by:2 do:[:i |
2110
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
   174
        (self basicAt:i) == key ifTrue:[
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
   175
            ^ self basicAt:(i + 1)
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
   176
        ]
328
claus
parents:
diff changeset
   177
    ].
claus
parents:
diff changeset
   178
    ^ exceptionBlock value
claus
parents:
diff changeset
   179
!
claus
parents:
diff changeset
   180
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   181
at:key put:value 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   182
    "set the value for a given key, which is supposed to be a symbol.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   183
     In contrast to dictionaries, we allow adding elements only, if there is a
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   184
     empty slot (nil key) present."
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
    |slot sz "{ Class: SmallInteger }"|
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
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   189
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   190
        slot := self basicAt:i.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   191
        (slot == key) ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   192
            ^ self basicAt:(i + 1) put:value
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   193
        ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   194
        slot isNil ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   195
            self basicAt:i put:key.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   196
            ^ self basicAt:(i + 1) put:value
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
    ^ self errorKeyNotFound:key
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   200
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   201
    "Modified: 7.6.1996 / 09:39:04 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   202
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   203
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   204
at:key putOrAppend:value 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   205
    "set the value for a given key, which is supposed to be a symbol.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   206
     In contrast to dictionaries, we allow adding elements only, if there is a
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   207
     empty slot (nil key) present.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   208
     Otherwise we create a return a new MethodDictionary"
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
    |slot emptySlot newDict sz "{ Class: SmallInteger }"|
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
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   213
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   214
        slot := self basicAt:i.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   215
        (slot == key) ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   216
            self basicAt:(i + 1) put:value .
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   217
            ^ self.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   218
        ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   219
        slot isNil ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   220
            emptySlot := i.
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
    ].
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
    emptySlot notNil ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   225
        self basicAt:emptySlot       put:key.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   226
        self basicAt:(emptySlot + 1) put:value.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   227
        ^ self.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   228
    ].
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
    "/ not enough room for new entry, copy to new dictionary
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   231
    newDict := self copyEmpty:sz/2+1.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   232
    newDict replaceFrom:1 to:sz with:self startingAt:1.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   233
    newDict basicAt:(sz+1) put:key.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   234
    newDict basicAt:(sz+2) put:value.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   235
    ^ newDict.
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
    "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
   238
    "Modified: 7.6.1996 / 17:32:40 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   239
!
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
keyAtValue:value ifAbsent:exceptionBlock
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   242
    "return the first key with value - 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   243
     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
   244
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   245
    |sz "{ Class: SmallInteger }"|
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
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   248
    2 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   249
        (self basicAt:i) == value ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   250
            ^ self basicAt:(i - 1)
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   251
        ]
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   252
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   253
    ^ exceptionBlock value
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   254
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   255
    "Created: 7.6.1996 / 14:53:57 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   256
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   257
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   258
removeKey:key 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   259
    "remove key from dictionary. 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   260
     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
   261
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   262
    ^ self removeKey:key ifAbsent:[self errorKeyNotFound:key].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   263
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   264
    "Created: 7.6.1996 / 15:58:50 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   265
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   266
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   267
removeKey:key ifAbsent:failBlock
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   268
    "remove key from dictionary. 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   269
     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
   270
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   271
    |value sz "{ Class: SmallInteger }"|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   272
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   273
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   274
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   275
        (self basicAt:i) == key ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   276
           self basicAt:i        put:nil.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   277
           value := self basicAt:(i + 1).
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   278
           self basicAt:(i + 1)  put:nil.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   279
           ^ value
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   280
        ]
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   281
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   282
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
   283
    ^ failBlock value.
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   284
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   285
    "Created: 7.6.1996 / 15:57:56 / stefan"
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
   286
    "Modified: 9.1.1997 / 03:29:56 / cg"
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   287
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   288
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   289
removeKeyAndCompress:key
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   290
    "remove key from dictionary. 
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   291
     A new, compressed MethodDictionary will be returned,
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   292
     or nil, if key is not present."
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   293
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   294
    |newDict dstIndex sz "{ Class: SmallInteger }"|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   295
1508
960d6e7e563b removeKeyAndCompress - failed if key was not present.
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
   296
    dstIndex := self identityIndexOf:key.
960d6e7e563b removeKeyAndCompress - failed if key was not present.
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
   297
    dstIndex == 0 ifTrue:[^ self].
960d6e7e563b removeKeyAndCompress - failed if key was not present.
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
   298
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   299
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   300
    newDict := self copyEmptyAndGrow:(sz/2-1).
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   301
    dstIndex := 1.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   302
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   303
        (self basicAt:i) ~~ key ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   304
           newDict basicAt:dstIndex   put:(self basicAt:i).
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   305
           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
   306
           dstIndex := dstIndex + 2.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   307
        ]
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   308
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   309
    dstIndex > sz ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   310
        ^ nil
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   311
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   312
    ^ newDict
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   313
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   314
    "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
   315
    "Modified: 7.6.1996 / 16:47:02 / stefan"
1508
960d6e7e563b removeKeyAndCompress - failed if key was not present.
Claus Gittinger <cg@exept.de>
parents: 1485
diff changeset
   316
    "Modified: 1.7.1996 / 21:31:38 / cg"
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   317
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   318
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   319
size
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   320
    "return the number of elements (associations) in the receiver"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   321
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   322
    ^ self basicSize // 2
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   323
! !
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   324
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   325
!MethodDictionary methodsFor:'binary storage'!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   326
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   327
storeFullBinaryDefinitionOn:stream manager:manager
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   328
    "store the complete description (i.e. including methods)"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   329
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   330
    self size storeBinaryOn:stream manager:manager.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   331
    self keysAndValuesDo:[:sel :mthd|
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   332
        sel storeBinaryOn:stream manager:manager.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   333
        mthd makeRealMethod storeFullBinaryDefinitionOn:stream manager:manager.
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
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   336
    "Created: 7.6.1996 / 12:53:00 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   337
! !
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
!MethodDictionary methodsFor:'enumerating'!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   340
1485
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   341
collect:aBlock
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   342
    "for each element in the receiver, evaluate the argument, aBlock
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   343
     and return a Bag with the results."
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   344
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   345
    |sz "{ Class: SmallInteger }"
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   346
     newCollection|
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   347
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   348
    newCollection := Bag new.
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   349
    sz := self basicSize.
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   350
    1 to:sz by:2 do:[:i |
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   351
        (self basicAt:i) notNil ifTrue:[
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   352
            newCollection add:(aBlock value:(self basicAt:(i + 1)))
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   353
        ]
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   354
    ].
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   355
    ^ newCollection
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   356
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   357
    "Created: 24.6.1996 / 17:41:41 / cg"
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   358
!
3e0f164f3f70 added #collect:
Claus Gittinger <cg@exept.de>
parents: 1465
diff changeset
   359
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   360
do:aBlock
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   361
    "evaluate the 1 arg block aBlock for each value (i.e. each Method)"
328
claus
parents:
diff changeset
   362
claus
parents:
diff changeset
   363
    |sz "{ Class: SmallInteger }"|
claus
parents:
diff changeset
   364
claus
parents:
diff changeset
   365
    sz := self basicSize.
claus
parents:
diff changeset
   366
    1 to:sz by:2 do:[:i |
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   367
        (self basicAt:i) notNil ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   368
            aBlock value:(self basicAt:(i + 1)).
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   369
        ]
328
claus
parents:
diff changeset
   370
    ].
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   371
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   372
    "Created: 7.6.1996 / 09:25:23 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   373
    "Modified: 7.6.1996 / 13:47:37 / stefan"
328
claus
parents:
diff changeset
   374
!
claus
parents:
diff changeset
   375
1703
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   376
findFirstKey:aBlock
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   377
    "find and return the first key, for which evaluation of the argument, aBlock
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   378
     returns true; return nil if none is detected."
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   379
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   380
    self keysDo:[:key |
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   381
        (aBlock value:key) ifTrue:[^ key].
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   382
    ].
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   383
    ^ nil
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   384
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   385
    "Created: 8.10.1996 / 22:01:31 / cg"
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   386
    "Modified: 8.10.1996 / 22:02:03 / cg"
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   387
!
9337c2c135d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1519
diff changeset
   388
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   389
keysAndValuesDo:aBlock
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   390
    "evaluate the 2 arg block aBlock for each key (i.e. each selector)
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   391
     and each value (i.e. each method)"
328
claus
parents:
diff changeset
   392
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   393
    |key sz "{ Class: SmallInteger }"|
328
claus
parents:
diff changeset
   394
claus
parents:
diff changeset
   395
    sz := self basicSize.
claus
parents:
diff changeset
   396
    1 to:sz by:2 do:[:i |
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   397
        key := self basicAt:i.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   398
        (key notNil) ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   399
            aBlock value:key value:(self basicAt:(i+1)).
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   400
        ]
328
claus
parents:
diff changeset
   401
    ].
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   402
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   403
    "Created: 7.6.1996 / 09:27:42 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   404
!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   405
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   406
keysDo:aBlock
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   407
    "evaluate the 1 arg block aBlock for each key (i.e. each selector)"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   408
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   409
    |key sz "{ Class: SmallInteger }"|
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
    sz := self basicSize.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   412
    1 to:sz by:2 do:[:i |
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   413
        key := self basicAt:i.
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   414
        (key notNil) ifTrue:[
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   415
            aBlock value:key.
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
    ].
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   418
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   419
    "Created: 7.6.1996 / 09:26:34 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   420
! !
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   421
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   422
!MethodDictionary methodsFor:'inspecting'!
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   423
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   424
inspectorClass
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   425
    "redefined to use DictionaryInspector
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   426
     (instead of the default Inspector)."
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   427
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   428
    ^ DictionaryInspectorView
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   429
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   430
    "Created: 12.6.1996 / 12:29:13 / stefan"
328
claus
parents:
diff changeset
   431
! !
claus
parents:
diff changeset
   432
claus
parents:
diff changeset
   433
!MethodDictionary methodsFor:'queries'!
claus
parents:
diff changeset
   434
claus
parents:
diff changeset
   435
keys
claus
parents:
diff changeset
   436
    "return a collection containing all keys of the receiver"
claus
parents:
diff changeset
   437
claus
parents:
diff changeset
   438
    ^ (1 to:self basicSize by:2) collect:[:index | self basicAt:index].
claus
parents:
diff changeset
   439
!
claus
parents:
diff changeset
   440
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   441
values
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   442
    "return a collection containing all values of the receiver"
328
claus
parents:
diff changeset
   443
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   444
    ^ (2 to:self basicSize by:2) collect:[:index | self basicAt:index].
328
claus
parents:
diff changeset
   445
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   446
    "Created: 7.6.1996 / 09:40:32 / stefan"
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   447
! !
328
claus
parents:
diff changeset
   448
2109
c019b0e813ec oops removeKey:ifAbsent: should send #value to the block
Claus Gittinger <cg@exept.de>
parents: 1703
diff changeset
   449
!MethodDictionary class methodsFor:'documentation'!
328
claus
parents:
diff changeset
   450
1461
dd25bb1e9973 Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents: 530
diff changeset
   451
version
2110
3c531e1ab7c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2109
diff changeset
   452
    ^ '$Header: /cvs/stx/stx/libbasic/MethodDictionary.st,v 1.12 1997-01-09 14:14:09 cg Exp $'
328
claus
parents:
diff changeset
   453
! !