IdentityDictionary.st
author Claus Gittinger <cg@exept.de>
Fri, 21 Dec 2001 11:59:16 +0100
changeset 6346 a69610ec89a0
parent 6233 0a79cbd07543
child 6916 1d7c11c94599
permissions -rw-r--r--
slotIsEmpty
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
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    13
"{ Package: 'stx:libbasic' }"
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
Dictionary subclass:#IdentityDictionary
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    16
	instanceVariableNames:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    17
	classVariableNames:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    18
	poolDictionaries:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    19
	category:'Collections-Unordered'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
!IdentityDictionary class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1992 by Claus Gittinger
175
82ba8d2e3569 *** empty log message ***
claus
parents: 92
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    same as a Dictionary but key must be identical - not just equal.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
    Since compare is on identical keys (using ==), hashing is also done via
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
    #identityHash instead of #hash.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
    IdentityDictionaries are especially useful, when symbols are used as keys.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    44
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    45
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    46
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
"
345
claus
parents: 175
diff changeset
    48
! !
claus
parents: 175
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
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    95
    index := key identityHash.
1975
c94a8e0b0251 avoid largeIntegers
Claus Gittinger <cg@exept.de>
parents: 1972
diff changeset
    96
    index < 16r1FFFFFFF ifTrue:[
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    97
        index := index * 2
1975
c94a8e0b0251 avoid largeIntegers
Claus Gittinger <cg@exept.de>
parents: 1972
diff changeset
    98
    ].
c94a8e0b0251 avoid largeIntegers
Claus Gittinger <cg@exept.de>
parents: 1972
diff changeset
    99
    index := index \\ length + 1.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   100
    startIndex := index.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   101
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
    [true] whileTrue:[
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   103
        probe := keyArray basicAt:index.
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   104
        probe == key ifTrue:[^ index].         "<<<< == is different from inherited"
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   105
        (self slotIsEmpty:probe) ifTrue:[^ aBlock value].
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   106
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   107
        index == length ifTrue:[
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   108
            index := 1
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   109
        ] ifFalse:[
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   110
            index := index + 1
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   111
        ].
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   112
        index == startIndex ifTrue:[^ aBlock value]
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
    ]
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   115
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
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
   117
    "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
   118
     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
   119
     Grow the receiver, if key was not found, and no unused slots were present"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   120
a27a279701f8 Initial revision
claus
parents:
diff changeset
   121
    |index  "{ Class:SmallInteger }"
375
claus
parents: 362
diff changeset
   122
     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
   123
     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
   124
     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
   125
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
   126
    delIndex := 0.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
    length := keyArray basicSize.
362
claus
parents: 345
diff changeset
   129
    index := key identityHash.
1975
c94a8e0b0251 avoid largeIntegers
Claus Gittinger <cg@exept.de>
parents: 1972
diff changeset
   130
    index < 16r1FFFFFFF ifTrue:[
c94a8e0b0251 avoid largeIntegers
Claus Gittinger <cg@exept.de>
parents: 1972
diff changeset
   131
        index := index * 2
c94a8e0b0251 avoid largeIntegers
Claus Gittinger <cg@exept.de>
parents: 1972
diff changeset
   132
    ].
c94a8e0b0251 avoid largeIntegers
Claus Gittinger <cg@exept.de>
parents: 1972
diff changeset
   133
    index := index \\ length + 1.
362
claus
parents: 345
diff changeset
   134
    startIndex := index.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
    [true] whileTrue:[
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   137
        probe := keyArray basicAt:index.
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   138
        key == probe ifTrue:[^ index].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   139
        (self slotIsEmpty:probe) ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   140
            delIndex == 0 ifTrue:[^ index].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   141
            keyArray basicAt:delIndex put:nil.
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   142
            ^ delIndex
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   143
        ].
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
   144
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   145
        probe == DeletedEntry ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   146
            delIndex == 0 ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   147
                delIndex := index
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   148
            ]
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   149
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   150
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   151
        index == length ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   152
            index := 1
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   153
        ] ifFalse:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   154
            index := index + 1
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   155
        ].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   156
        index == startIndex ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   157
            delIndex ~~ 0 ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   158
                keyArray basicAt:delIndex put:nil.
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   159
                ^ delIndex
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   160
            ].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   161
            ^ self grow findKeyOrNil:key
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   162
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
    ]
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
   164
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
   165
    "Modified: 26.3.1996 / 20:00:44 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
2460
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   168
hashFor:aKey
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   169
    "return an initial index given a key."
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   170
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   171
    ^ aKey identityHash
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   172
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   173
    "Created: 19.3.1997 / 15:03:36 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   174
! !
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   175
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   176
!IdentityDictionary methodsFor:'testing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   177
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   178
includesValue:aValue
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   179
    "return true, if the argument, aValue is stored in the dictionary,
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   180
     Redefined to use identity compare, NOT equality compare"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
5050
ea292b958108 allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents: 2474
diff changeset
   182
    ^ self includesIdenticalValue:aValue
77
6c38ca59927f *** empty log message ***
claus
parents: 39
diff changeset
   183
!
6c38ca59927f *** empty log message ***
claus
parents: 39
diff changeset
   184
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   185
occurrencesOf:anObject
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   186
    "count & return how often anObject is stored in the dictionary.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   187
     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
   188
     Redefined to use #== (identity compare), NOT equality compare."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   189
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   190
    |cnt|
175
82ba8d2e3569 *** empty log message ***
claus
parents: 92
diff changeset
   191
5050
ea292b958108 allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents: 2474
diff changeset
   192
    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
   193
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   194
    cnt := 0.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   195
    valueArray do:[:element |
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   196
       element == anObject ifTrue:[cnt := cnt + 1]
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   197
    ].
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   198
    ^ cnt
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   199
! !
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   200
634
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   201
!IdentityDictionary class methodsFor:'documentation'!
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   202
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   203
version
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   204
    ^ '$Header: /cvs/stx/stx/libbasic/IdentityDictionary.st,v 1.29 2001-12-21 10:59:16 cg Exp $'
634
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   205
! !