IdentityDictionary.st
author Claus Gittinger <cg@exept.de>
Mon, 08 Jun 2015 21:22:21 +0200
changeset 18465 e9e4bb62235f
parent 16246 d9c642250916
child 18120 e3a375d5f6a8
child 19547 562794fb6b7f
permissions -rw-r--r--
added isOrdered query
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
175
82ba8d2e3569 *** empty log message ***
claus
parents: 92
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    12
"{ Package: 'stx:libbasic' }"
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
Dictionary subclass:#IdentityDictionary
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    15
	instanceVariableNames:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    16
	classVariableNames:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    17
	poolDictionaries:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    18
	category:'Collections-Unordered'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    21
!IdentityDictionary class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
 COPYRIGHT (c) 1992 by Claus Gittinger
175
82ba8d2e3569 *** empty log message ***
claus
parents: 92
diff changeset
    26
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    36
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
    same as a Dictionary but key must be identical - not just equal.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    Since compare is on identical keys (using ==), hashing is also done via
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    #identityHash instead of #hash.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    IdentityDictionaries are especially useful, when symbols are used as keys.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    43
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    44
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    45
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
"
345
claus
parents: 175
diff changeset
    47
! !
claus
parents: 175
diff changeset
    48
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
    49
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    50
!IdentityDictionary methodsFor:'private'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    51
345
claus
parents: 175
diff changeset
    52
compareSame:element1 with:element2
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    53
    "compare two elements for being the same. Here, return true if the
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    54
     elements are identical (i.e. using #==)."
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    55
345
claus
parents: 175
diff changeset
    56
    ^ element1 == element2
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    57
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    58
    "Modified: 22.4.1996 / 17:34:48 / cg"
345
claus
parents: 175
diff changeset
    59
!
claus
parents: 175
diff changeset
    60
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    61
emptyCollectionForKeys
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    62
    "return an empty collection used for keys.
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    63
     Here, an IdentitySet is returned.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    64
     Made a separate method to allow redefinition for different kind of
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    65
     containers in subclasses."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    66
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    67
    ^ IdentitySet new:(self size)
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    68
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    69
    "Modified: 22.4.1996 / 17:35:40 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    70
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    71
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
find:key ifAbsent:aBlock
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    73
    "Look for the key in the receiver.  If it is found, return
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    74
     the index of the association containing the key, otherwise
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    75
     return the value of evaluating aBlock.
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    76
     Redefined - since we inherit this code from Set-Dictionary
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    77
     (one of the seldom cases, where I could make use of multiple inheritance
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    78
     and inherit from IdentitySet ... sigh)"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    79
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    80
    |index  "{ Class:SmallInteger }"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    81
     length "{ Class:SmallInteger }"
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    82
     startIndex probe|
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    83
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
    length := keyArray basicSize.
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
    85
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
    86
"/
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
    87
"/    length < 10 ifTrue:[
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    88
"/      "assuming, that for small dictionaries the overhead of hashing
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    89
"/       is large ... maybe that proves wrong (if overhead of comparing
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    90
"/       is high)"
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    91
"/      ^ keyArray identityIndexOf:key ifAbsent:aBlock.
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
    92
"/    ].
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
    93
"/
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    94
6916
1d7c11c94599 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6346
diff changeset
    95
    startIndex := index := self initialIndexForKey:key.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    96
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
    97
    [
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    98
        probe := keyArray basicAt:index.
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    99
        probe == key ifTrue:[^ index].         "<<<< == is different from inherited"
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   100
        (self slotIsEmpty:probe) ifTrue:[^ aBlock value].
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   101
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   102
        index == length ifTrue:[
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   103
            index := 1
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   104
        ] ifFalse:[
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   105
            index := index + 1
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   106
        ].
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   107
        index == startIndex ifTrue:[^ aBlock value]
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   108
    ] loop.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
findKeyOrNil:key
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   112
    "Look for the key in the receiver.  
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   113
     If it is found, return return the index of the first unused slot. 
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   114
     Grow the receiver, if key was not found, and no unused slots were present"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   115
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
    |index  "{ Class:SmallInteger }"
375
claus
parents: 362
diff changeset
   117
     length "{ Class:SmallInteger }"
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   118
     startIndex probe 
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   119
     delIndex "{ Class:SmallInteger }" |
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   120
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   121
    delIndex := 0.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   122
a27a279701f8 Initial revision
claus
parents:
diff changeset
   123
    length := keyArray basicSize.
6916
1d7c11c94599 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6346
diff changeset
   124
    startIndex := index := self initialIndexForKey:key.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   126
    [
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   127
        probe := keyArray basicAt:index.
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   128
        key == probe ifTrue:[^ index].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   129
        (self slotIsEmpty:probe) ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   130
            delIndex == 0 ifTrue:[^ index].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   131
            keyArray basicAt:delIndex put:nil.
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   132
            ^ delIndex
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   133
        ].
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   134
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   135
        probe == DeletedEntry ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   136
            delIndex == 0 ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   137
                delIndex := index
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   138
            ]
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   139
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   140
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   141
        index == length ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   142
            index := 1
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   143
        ] ifFalse:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   144
            index := index + 1
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   145
        ].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   146
        index == startIndex ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   147
            delIndex ~~ 0 ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   148
                keyArray basicAt:delIndex put:nil.
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   149
                ^ delIndex
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   150
            ].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   151
            ^ self grow findKeyOrNil:key
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   152
        ].
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   153
    ] loop.
1126
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   154
497de696dff0 OOPS - could add elements twice after a remove (shame on me: how could that go unnoticed for so long ...)
Claus Gittinger <cg@exept.de>
parents: 634
diff changeset
   155
    "Modified: 26.3.1996 / 20:00:44 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   156
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   157
2460
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   158
hashFor:aKey
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   159
    "return an initial index given a key."
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   160
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   161
    ^ aKey identityHash
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   162
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   163
    "Created: 19.3.1997 / 15:03:36 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   164
! !
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   165
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   166
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   167
!IdentityDictionary methodsFor:'testing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
includesValue:aValue
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   170
    "return true, if the argument, aValue is stored in the dictionary,
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   171
     Redefined to use identity compare, NOT equality compare"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   172
5050
ea292b958108 allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents: 2474
diff changeset
   173
    ^ self includesIdenticalValue:aValue
77
6c38ca59927f *** empty log message ***
claus
parents: 39
diff changeset
   174
!
6c38ca59927f *** empty log message ***
claus
parents: 39
diff changeset
   175
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
occurrencesOf:anObject
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   177
    "count & return how often anObject is stored in the dictionary.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
     This counts values - not keys.
5050
ea292b958108 allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents: 2474
diff changeset
   179
     Redefined to use #== (identity compare), NOT equality compare."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   181
    |cnt|
175
82ba8d2e3569 *** empty log message ***
claus
parents: 92
diff changeset
   182
5050
ea292b958108 allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents: 2474
diff changeset
   183
    anObject isNil ifTrue:[^ super occurrencesOf:anObject].
ea292b958108 allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents: 2474
diff changeset
   184
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
    cnt := 0.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
    valueArray do:[:element |
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
       element == anObject ifTrue:[cnt := cnt + 1]
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   188
    ].
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   189
    ^ cnt
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   190
! !
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
634
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   192
!IdentityDictionary class methodsFor:'documentation'!
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   193
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   194
version
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   195
    ^ '$Header: /cvs/stx/stx/libbasic/IdentityDictionary.st,v 1.31 2014-03-07 22:07:13 stefan Exp $'
634
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   196
! !
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   197