IdentityDictionary.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 23844 77d509832234
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23844
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
     1
"{ Encoding: utf8 }"
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
 COPYRIGHT (c) 1992 by Claus Gittinger
175
82ba8d2e3569 *** empty log message ***
claus
parents: 92
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    14
"{ Package: 'stx:libbasic' }"
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
    15
19547
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
    16
"{ NameSpace: Smalltalk }"
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
    17
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
Dictionary subclass:#IdentityDictionary
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    19
	instanceVariableNames:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    20
	classVariableNames:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    21
	poolDictionaries:''
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    22
	category:'Collections-Unordered'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
!IdentityDictionary class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 COPYRIGHT (c) 1992 by Claus Gittinger
175
82ba8d2e3569 *** empty log message ***
claus
parents: 92
diff changeset
    30
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    31
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    40
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
"
20087
ac9df4df5981 #DOCUMENTATION by mawalch
mawalch
parents: 20039
diff changeset
    43
    Same as a Dictionary, but key must be identical - not just equal.
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    44
    Since compare is on identical keys (using ==), hashing is also done via
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    45
    #identityHash instead of #hash.
20087
ac9df4df5981 #DOCUMENTATION by mawalch
mawalch
parents: 20039
diff changeset
    46
    IdentityDictionaries are especially useful when symbols are used as keys.
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    47
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    48
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    49
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    50
"
345
claus
parents: 175
diff changeset
    51
! !
claus
parents: 175
diff changeset
    52
23844
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    53
!IdentityDictionary methodsFor:'copying'!
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    54
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    55
copyWithout:anAssociation 
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    56
    "Return a copy of the dictionary that is 1 smaller than the receiver and 
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    57
     does not include the argument, anAssociation
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    58
     No error is reported, if elementToSkip is not in the collection."
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    59
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    60
    |newDict keyToIgnore valueToIgnore|
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    61
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    62
    newDict := self species new:self size - 1.
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    63
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    64
    keyToIgnore := anAssociation key.
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    65
    valueToIgnore := anAssociation value.
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    66
    self keysAndValuesDo:[:k :v |
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    67
        (keyToIgnore == k and:[valueToIgnore = v]) ifFalse:[
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    68
            newDict at:k put:v
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    69
        ]
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    70
    ].
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    71
    ^ newDict.
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    72
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    73
    "
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    74
     |d d2|
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    75
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    76
     d := IdentityDictionary new
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    77
            at:1 put:'1';
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    78
            at:2 put:'2';
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    79
            at:3 put:'3';
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    80
            at:4 put:'4';
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    81
            at:4.0 put:'4';
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    82
            at:5 put:'5';
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    83
            yourself.
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    84
     d2 := d copyWithout:(4->'4').
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    85
     d2   
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    86
    "
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    87
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    88
    "Created: / 05-03-2019 / 12:45:38 / Stefan Vogel"
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    89
! !
77d509832234 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23698
diff changeset
    90
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
!IdentityDictionary methodsFor:'private'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
345
claus
parents: 175
diff changeset
    93
compareSame:element1 with:element2
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    94
    "compare two elements for being the same. Here, return true if the
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    95
     elements are identical (i.e. using #==)."
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    96
345
claus
parents: 175
diff changeset
    97
    ^ element1 == element2
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    98
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
    99
    "Modified: 22.4.1996 / 17:34:48 / cg"
345
claus
parents: 175
diff changeset
   100
!
claus
parents: 175
diff changeset
   101
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   102
emptyCollectionForKeys
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   103
    "return an empty collection used for keys.
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
   104
     Here, an IdentitySet is returned.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   105
     Made a separate method to allow redefinition for different kind of
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
   106
     containers in subclasses."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
    ^ IdentitySet new:(self size)
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
   109
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1126
diff changeset
   110
    "Modified: 22.4.1996 / 17:35:40 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   113
find:key ifAbsent:aBlock
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   114
    "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
   115
     the index of the association containing the key, otherwise
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   116
     return the value of evaluating aBlock.
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   117
     Redefined - since we inherit this code from Set-Dictionary
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   118
     (one of the seldom cases, where I could make use of multiple inheritance
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   119
     and inherit from IdentitySet ... sigh)"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   120
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   121
    |index  "{ Class:SmallInteger }"
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   122
     length "{ Class:SmallInteger }"
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   123
     startIndex probe|
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   124
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   125
    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
   126
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
   127
"/
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
   128
"/    length < 10 ifTrue:[
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   129
"/      "assuming, that for small dictionaries the overhead of hashing
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   130
"/       is large ... maybe that proves wrong (if overhead of comparing
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   131
"/       is high)"
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   132
"/      ^ 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
   133
"/    ].
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
"/
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   135
6916
1d7c11c94599 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6346
diff changeset
   136
    startIndex := index := self initialIndexForKey:key.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   137
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   138
    [
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   139
        probe := keyArray basicAt:index.
19999
7500bbb495ca #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19547
diff changeset
   140
        probe == key ifTrue:[^ index].         "<--- == is different from inherited"
19547
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   141
        probe isNil ifTrue:[^ aBlock value].
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   142
6233
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   143
        index == length ifTrue:[
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   144
            index := 1
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   145
        ] ifFalse:[
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   146
            index := index + 1
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   147
        ].
0a79cbd07543 *** empty log message ***
martin
parents: 5050
diff changeset
   148
        index == startIndex ifTrue:[^ aBlock value]
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   149
    ] loop.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   150
!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   151
20232
6a5149a6d6e6 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20087
diff changeset
   152
findIdentical:key ifAbsent:aBlock
6a5149a6d6e6 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20087
diff changeset
   153
    "IdentityDictionary does identity compare anyway..."
6a5149a6d6e6 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20087
diff changeset
   154
6a5149a6d6e6 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20087
diff changeset
   155
    ^ self find:key ifAbsent:aBlock
6a5149a6d6e6 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20087
diff changeset
   156
!
6a5149a6d6e6 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 20087
diff changeset
   157
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
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
   159
    "Look for the key in the receiver.  
19547
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   160
     If it is found, return the index of the first unused slot. 
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   161
     Grow the receiver, if key was not found, and no unused slots were present
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   162
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   163
     Warning: an empty slot MUST be filled by the sender - it is only to be sent
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   164
              by at:put: / add: - like methods."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
    |index  "{ Class:SmallInteger }"
375
claus
parents: 362
diff changeset
   167
     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
   168
     startIndex probe 
19547
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   169
     delIndex "{ 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
   170
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
   171
    delIndex := 0.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   172
a27a279701f8 Initial revision
claus
parents:
diff changeset
   173
    length := keyArray basicSize.
6916
1d7c11c94599 refactored to invoke #hash/#identityHash only from one place
Claus Gittinger <cg@exept.de>
parents: 6346
diff changeset
   174
    startIndex := index := self initialIndexForKey:key.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   176
    [
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   177
        probe := keyArray basicAt:index.
19999
7500bbb495ca #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19547
diff changeset
   178
        key == probe ifTrue:[^ index].              "<--- == is different from inherited"   
19547
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   179
        probe isNil ifTrue:[
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   180
            delIndex == 0 ifTrue:[^ index].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   181
            keyArray basicAt:delIndex put:nil.
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   182
            ^ delIndex
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   183
        ].
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
   184
20039
cd328445cac7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19999
diff changeset
   185
        (delIndex == 0 and:[probe == DeletedEntry]) ifTrue:[
cd328445cac7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19999
diff changeset
   186
            delIndex := index
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   187
        ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   188
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   189
        index == length ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   190
            index := 1
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   191
        ] ifFalse:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   192
            index := index + 1
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   193
        ].
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   194
        index == startIndex ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   195
            delIndex ~~ 0 ifTrue:[
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   196
                keyArray basicAt:delIndex put:nil.
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   197
                ^ delIndex
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   198
            ].
20039
cd328445cac7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19999
diff changeset
   199
            self grow.
cd328445cac7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19999
diff changeset
   200
            length := keyArray basicSize.
cd328445cac7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19999
diff changeset
   201
            startIndex := index := self initialIndexForKey:key.
6346
a69610ec89a0 slotIsEmpty
Claus Gittinger <cg@exept.de>
parents: 6233
diff changeset
   202
        ].
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   203
    ] 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
   204
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
   205
    "Modified: 26.3.1996 / 20:00:44 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   206
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   207
20233
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   208
findKeyOrNilOrDeletedEntry:key
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   209
    "Look for the key in the receiver.  
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   210
     If it is found, return the index of the first unused slot. 
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   211
     Grow the receiver, if key was not found, and no unused slots were present."
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   212
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   213
    |index  "{ Class:SmallInteger }"
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   214
     length "{ Class:SmallInteger }"
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   215
     startIndex probe 
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   216
     delIndex "{ Class:SmallInteger }"|
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   217
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   218
    delIndex := 0.
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   219
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   220
    length := keyArray basicSize.
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   221
    startIndex := index := self initialIndexForKey:key.
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   222
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   223
    [
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   224
        probe := keyArray basicAt:index.
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   225
        key == probe ifTrue:[^ index].              "<--- == is different from inherited"   
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   226
        probe isNil ifTrue:[
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   227
            delIndex == 0 ifTrue:[^ index].
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   228
            ^ delIndex
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   229
        ].
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   230
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   231
        (delIndex == 0 and:[probe == DeletedEntry]) ifTrue:[
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   232
            delIndex := index
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   233
        ].
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   234
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   235
        index == length ifTrue:[
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   236
            index := 1
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   237
        ] ifFalse:[
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   238
            index := index + 1
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   239
        ].
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   240
        index == startIndex ifTrue:[
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   241
            delIndex ~~ 0 ifTrue:[
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   242
                ^ delIndex
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   243
            ].
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   244
            self grow.
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   245
            length := keyArray basicSize.
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   246
            startIndex := index := self initialIndexForKey:key.
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   247
        ].
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   248
    ] loop.
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   249
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   250
    "Modified: 26.3.1996 / 20:00:44 / cg"
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   251
!
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   252
2460
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   253
hashFor:aKey
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   254
    "return an initial index given a key."
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   255
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   256
    ^ aKey identityHash
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   257
1d7caef5f5ed added #hashFor:
Claus Gittinger <cg@exept.de>
parents: 1975
diff changeset
   258
    "Created: 19.3.1997 / 15:03:36 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   259
! !
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   260
23698
3b186751f0f4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20233
diff changeset
   261
!IdentityDictionary methodsFor:'queries'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   263
includesValue:aValue
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   264
    "return true, if the argument, aValue is stored in the dictionary,
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   265
     Redefined to use identity compare, NOT equality compare"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   266
5050
ea292b958108 allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents: 2474
diff changeset
   267
    ^ self includesIdenticalValue:aValue
77
6c38ca59927f *** empty log message ***
claus
parents: 39
diff changeset
   268
!
6c38ca59927f *** empty log message ***
claus
parents: 39
diff changeset
   269
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   270
occurrencesOf:anObject
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   271
    "count & return how often anObject is stored in the dictionary.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   272
     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
   273
     Redefined to use #== (identity compare), NOT equality compare."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   274
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   275
    |cnt|
175
82ba8d2e3569 *** empty log message ***
claus
parents: 92
diff changeset
   276
5050
ea292b958108 allow for nil to be stored as a value.
Claus Gittinger <cg@exept.de>
parents: 2474
diff changeset
   277
    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
   278
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   279
    cnt := 0.
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   280
    valueArray do:[:element |
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
       element == anObject ifTrue:[cnt := cnt + 1]
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
    ].
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   283
    ^ cnt
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
! !
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   285
23698
3b186751f0f4 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20233
diff changeset
   286
634
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   287
!IdentityDictionary class methodsFor:'documentation'!
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   288
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   289
version
19547
562794fb6b7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 16246
diff changeset
   290
    ^ '$Header$'
20233
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   291
!
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   292
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   293
version_CVS
2c51422816be #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20232
diff changeset
   294
    ^ '$Header$'
634
e15218d09420 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   295
! !
16246
d9c642250916 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 6916
diff changeset
   296