WeakIdentityDictionary.st
author Stefan Vogel <sv@exept.de>
Wed, 11 Mar 2020 10:09:01 +0100
changeset 25334 8f44c9352333
parent 24689 5d687a4944c5
permissions -rw-r--r--
#BUGFIX by stefan class: Smalltalk class changed: #hello Fix welcome messages for kanguages != #en
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
     1
"{ Encoding: utf8 }"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
     2
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
     3
"
62211a9bc04d Initial revision
claus
parents:
diff changeset
     4
 COPYRIGHT (c) 1992 by Claus Gittinger
358
claus
parents: 159
diff changeset
     5
	      All Rights Reserved
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
     6
62211a9bc04d Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
62211a9bc04d Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
62211a9bc04d Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
62211a9bc04d Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
62211a9bc04d Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
62211a9bc04d Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
62211a9bc04d Initial revision
claus
parents:
diff changeset
    13
"
6233
0a79cbd07543 *** empty log message ***
martin
parents: 4530
diff changeset
    14
"{ Package: 'stx:libbasic' }"
0a79cbd07543 *** empty log message ***
martin
parents: 4530
diff changeset
    15
18333
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
    16
"{ NameSpace: Smalltalk }"
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
    17
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
    18
IdentityDictionary subclass:#WeakIdentityDictionary
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    19
	instanceVariableNames:''
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    20
	classVariableNames:''
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    21
	poolDictionaries:''
4350
5aa2a3b9fd5b category change
Claus Gittinger <cg@exept.de>
parents: 2988
diff changeset
    22
	category:'Collections-Weak'
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
    23
!
62211a9bc04d Initial revision
claus
parents:
diff changeset
    24
10
claus
parents: 6
diff changeset
    25
!WeakIdentityDictionary class methodsFor:'documentation'!
claus
parents: 6
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    29
 COPYRIGHT (c) 1992 by Claus Gittinger
358
claus
parents: 159
diff changeset
    30
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    31
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    39
!
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    40
10
claus
parents: 6
diff changeset
    41
documentation
claus
parents: 6
diff changeset
    42
"
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
    43
    WeakIdentityDictionaries behave like IdentityDictionaries,
24689
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    44
    as long as the keys are still referenced by some other (non-weak) object.
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    45
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    46
    However, once the last non-weak reference ceases to exist,
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    47
    the object will be automatically removed from the Weakcollection
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    48
    (with some delay: it will be removed after the next garbage collect).
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    49
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    50
    This class was added to support keeping track of dependents without
24689
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    51
    keeping the values alive - a value simply become nil when no one else references it. 
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    52
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    53
    The original dependency mechanism used a regular Dictionary,
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    54
    which usually leads to a lot of garbage being kept due to a forgotten release. 
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    55
    Using a WeakDictionary may be incompatible to ST-80 but is much
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    56
    more comfortable, since no manual release of dependents is needed.
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    57
2306
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    58
    [Warning:]
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    59
      If you use this, be very careful since the collections size changes
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    60
      'magically' - for example, testing for being nonEmpty and then
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    61
      removing the first element may fail, since the element may vanish inbetween.
3851fc553893 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2303
diff changeset
    62
      In general, never trust the value as returned by the size/isEmpty messages.
2260
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    63
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    64
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    65
    [author:]
24689
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    66
        Claus Gittinger
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    67
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    68
    [See also:]
24689
5d687a4944c5 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24271
diff changeset
    69
        WeakArray WeakValueDictionary WeakIdentitySet
10
claus
parents: 6
diff changeset
    70
"
claus
parents: 6
diff changeset
    71
! !
claus
parents: 6
diff changeset
    72
21006
076293e19939 #OTHER by mawalch
mawalch
parents: 20992
diff changeset
    73
!WeakIdentityDictionary methodsFor:'accessing'!
20990
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    74
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    75
keys
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    76
    "return a collection containing all valid keys of the receiver"
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    77
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    78
    |keySet|
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    79
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    80
    keySet := self emptyCollectionForKeys.
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    81
    keyArray validElementsDo:[:key |
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    82
        (key notNil and:[key ~~ DeletedEntry]) ifTrue:[
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    83
            key == NilEntry ifTrue:[
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    84
                keySet add:nil.
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    85
            ] ifFalse:[
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    86
                keySet add:key.
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    87
            ]
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    88
        ]
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    89
    ].
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    90
    ^ keySet
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    91
! !
38e8d0c58aa1 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20702
diff changeset
    92
359
claus
parents: 358
diff changeset
    93
!WeakIdentityDictionary methodsFor:'adding & removing'!
claus
parents: 358
diff changeset
    94
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    95
at:key ifAbsent:exceptionBlock
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
    96
    "redefined to block interrupts
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
    97
     (avoid change of the dictionary while accessing)"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    98
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
    99
    key class == SmallInteger ifTrue:[  
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   100
        "SmallIntegers cannot be stored into a WeakArray"
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   101
        ^ exceptionBlock value.
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   102
    ].
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   103
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   104
    (OperatingSystem blockInterrupts) ifTrue:[
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   105
        "/ already blocked
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   106
        ^ super at:key ifAbsent:exceptionBlock.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   107
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   108
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   109
    ^ [super at:key ifAbsent:exceptionBlock] ensure:[OperatingSystem unblockInterrupts].
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   110
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   111
    "Modified: / 06-05-1996 / 12:22:26 / stefan"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   112
    "Modified: / 01-07-1997 / 10:45:47 / cg"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   113
    "Modified: / 12-02-2019 / 20:42:51 / Stefan Vogel"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   114
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   115
19193
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   116
at:key ifAbsentPut:replacementBlock
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   117
    "redefined to block interrupts
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   118
     (avoid change of the dictionary while accessing)"
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   119
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   120
    key class == SmallInteger ifTrue:[  
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   121
        "SmallIntegers cannot be stored into a WeakArray"
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   122
        self error:'WeakidentityDictionary: cannot store a SmallInteger'.
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   123
    ].
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   124
19193
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   125
    (OperatingSystem blockInterrupts) ifTrue:[
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   126
        "/ already blocked
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   127
        ^ super at:key ifAbsentPut:replacementBlock.
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   128
    ].
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   129
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   130
    ^ [super at:key ifAbsentPut:replacementBlock] ensure:[OperatingSystem unblockInterrupts].
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   131
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   132
    "Modified: / 12-02-2019 / 20:43:18 / Stefan Vogel"
19193
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   133
!
27e9b8923aa7 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
   134
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   135
at:key put:anObject
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   136
    "add the argument anObject under key, aKey to the receiver.
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   137
     Return anObject (sigh).
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   138
     Redefined to block interrupts, to avoid trouble when dependencies
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   139
     are added within interrupting high prio processes."
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   140
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   141
    key class == SmallInteger ifTrue:[  
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   142
        "SmallIntegers cannot be stored into a WeakArray"
24271
4d111f8bc587 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23724
diff changeset
   143
        ArgumentError raiseErrorString:'WeakidentityDictionary: cannot store a SmallInteger'.
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   144
    ].
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   145
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   146
    (OperatingSystem blockInterrupts) ifTrue:[
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   147
        "/ already blocked
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   148
        ^ super at:key put:anObject.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   149
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   150
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   151
    ^ [super at:key put:anObject] ensure:[OperatingSystem unblockInterrupts].
1223
09d16bc18493 at:put: returns its arg
Claus Gittinger <cg@exept.de>
parents: 1054
diff changeset
   152
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   153
    "Modified: / 06-05-1996 / 12:22:26 / stefan"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   154
    "Modified: / 29-01-1997 / 15:08:45 / cg"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   155
    "Modified: / 12-02-2019 / 20:43:49 / Stefan Vogel"
24271
4d111f8bc587 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23724
diff changeset
   156
    "Modified: / 06-06-2019 / 23:26:07 / Claus Gittinger"
359
claus
parents: 358
diff changeset
   157
!
claus
parents: 358
diff changeset
   158
claus
parents: 358
diff changeset
   159
removeKey:aKey ifAbsent:aBlock
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   160
    "remove the association under aKey from the collection,
2910
1a3e44b10f9b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2741
diff changeset
   161
     return the value previously stored there.
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   162
     If it was not in the collection return the result
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   163
     from evaluating aBlock.
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   164
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   165
    Redefined to avoid synchronization problems, in case
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   166
    of interrupts (otherwise, there could be some other operation
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   167
    on the receiver done by another process, which garbles my contents)."
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
   168
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   169
    aKey class == SmallInteger ifTrue:[  
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   170
        "SmallIntegers cannot be stored into a WeakArray"
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   171
        ^ aBlock value.
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   172
    ].
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   173
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   174
    (OperatingSystem blockInterrupts) ifTrue:[
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   175
        "/ already blocked
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   176
        ^ super removeKey:aKey ifAbsent:aBlock.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   177
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   178
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   179
    ^ [super removeKey:aKey ifAbsent:aBlock] ensure:[OperatingSystem unblockInterrupts ].
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
   180
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   181
    "Modified: / 06-05-1996 / 12:44:51 / stefan"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   182
    "Modified: / 29-01-1997 / 15:09:11 / cg"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   183
    "Modified: / 12-02-2019 / 20:45:26 / Stefan Vogel"
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   184
!
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   185
16513
Stefan Vogel <sv@exept.de>
parents: 16244
diff changeset
   186
safeRemoveKey:key
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   187
    "redefined to block interrupts
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   188
     (avoid change of the dictionary while accessing)"
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   189
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   190
    key class == SmallInteger ifTrue:[  
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   191
        "SmallIntegers cannot be stored into a WeakArray"
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   192
        ^ nil.
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   193
    ].
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   194
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   195
    (OperatingSystem blockInterrupts) ifTrue:[
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   196
        "/ already blocked
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   197
        ^ super safeRemoveKey:key.
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   198
    ].
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   199
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   200
    ^ [super safeRemoveKey:key] ensure:[OperatingSystem unblockInterrupts].
2738
2546e06df154 more interrupt blocking (paranoia)
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
   201
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   202
    "Modified: / 06-05-1996 / 12:22:26 / stefan"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   203
    "Created: / 01-07-1997 / 10:46:34 / cg"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   204
    "Modified: / 12-02-2019 / 20:46:05 / Stefan Vogel"
359
claus
parents: 358
diff changeset
   205
! !
claus
parents: 358
diff changeset
   206
10
claus
parents: 6
diff changeset
   207
!WeakIdentityDictionary methodsFor:'element disposal'!
claus
parents: 6
diff changeset
   208
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   209
clearDeadSlots
20702
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   210
    |wasBlocked anyChange|
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   211
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   212
    "
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   213
     have to block here - dispose may be done at a low priority
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   214
     from the background finalizer. If new items are added by a
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   215
     higher prio process, the dictionary might get corrupted otherwise
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   216
    "
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   217
    wasBlocked := OperatingSystem blockInterrupts.
20702
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   218
    anyChange := false.
6469
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   219
    [
20702
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   220
        keyArray
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   221
            forAllDeadIndicesDo:[:idx |
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   222
                                    valueArray basicAt:idx put:nil.
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   223
                                    tally := tally - 1.
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   224
                                    anyChange := true.
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   225
                                ]
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   226
            replacingCorpsesWith:DeletedEntry.
6469
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   227
    ] ensure:[
20702
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   228
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
6469
b9f198f122a6 Ensure #unblockInterrupts
Stefan Vogel <sv@exept.de>
parents: 6421
diff changeset
   229
    ].
20702
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   230
    anyChange ifTrue:[
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   231
        self changed:#ElementExpired
5dfa0631a814 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20237
diff changeset
   232
    ].    
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   233
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   234
    "Modified: / 13.12.2001 / 14:18:17 / martin"
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   235
!
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   236
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   237
update:something with:aParameter from:changedObject
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   238
    "an element (either key or value) died - clear out slots for
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   239
     disposed keys."
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
   240
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   241
    something == #ElementExpired ifTrue:[
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   242
	self clearDeadSlots.
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   243
    ]
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   244
6309
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   245
    "Created: / 7.1.1997 / 16:59:30 / stefan"
9832d6941a4a extracted clearDeadSlots
martin
parents: 6233
diff changeset
   246
    "Modified: / 13.12.2001 / 14:17:58 / martin"
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
   247
! !
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   248
20992
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   249
!WeakIdentityDictionary methodsFor:'enumerating'!
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   250
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   251
keysDo:aBlock
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   252
    "evaluate aBlock for each registered object"
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   253
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   254
    "#Dictionary>>keysDo: would not work, since the keyArray instvar may change if
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   255
     elements are unregistered while looping."
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   256
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   257
    ^ keyArray validElementsDo:[:each|
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   258
        each ~~ DeletedEntry ifTrue:[
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   259
            each == NilEntry ifTrue:[
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   260
                aBlock value:nil.
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   261
            ] ifFalse:[
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   262
                aBlock value:each.
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   263
            ]
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   264
        ].
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   265
    ]
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   266
! !
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   267
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   268
!WeakIdentityDictionary methodsFor:'private'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   269
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   270
findKeyOrNil:key
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   271
    "Look for the key in the receiver.
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   272
     If it is found, return the index,
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   273
     otherwise the index of the first unused slot.
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   274
     Grow the receiver, if key was not found, and no unused slots were present.
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   275
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   276
     Warning: an empty slot MUST be filled by the sender - it is only to be sent
20037
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   277
              by at:put: / add: - like methods."
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   278
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   279
    |index  "{ Class:SmallInteger }"
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   280
     length "{ Class:SmallInteger }"
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   281
     startIndex probe
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   282
     delIndex "{ Class:SmallInteger }"|
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   283
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   284
    (OperatingSystem blockInterrupts) ifFalse:[
20037
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   285
        "/
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   286
        "/ may never be entered with interrupts enabled
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   287
        "/
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   288
        OperatingSystem unblockInterrupts.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   289
        self error:'unblocked call of findKeyOrNil'.
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   290
    ].
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   291
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   292
    delIndex := 0.
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   293
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   294
    length := keyArray basicSize.
6953
6b3a197638f0 invoke hash/idHash only in one place (initialIndexFor..)
Claus Gittinger <cg@exept.de>
parents: 6469
diff changeset
   295
    startIndex := index := self initialIndexForKey:key.
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   296
16244
584d9f48f6c1 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 13747
diff changeset
   297
    [
20037
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   298
        probe := keyArray basicAt:index.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   299
        key == probe ifTrue:[^ index].
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   300
        probe isNil ifTrue:[
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   301
            delIndex == 0 ifTrue:[^ index].
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   302
            keyArray basicAt:delIndex put:nil.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   303
            ^ delIndex
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   304
        ].
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   305
20037
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   306
        probe class == SmallInteger ifTrue:[
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   307
            probe := DeletedEntry.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   308
            keyArray basicAt:index put:probe.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   309
            valueArray basicAt:index put:nil.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   310
            tally := tally - 1.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   311
        ].
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   312
20037
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   313
        (delIndex == 0 and:[probe == DeletedEntry]) ifTrue:[
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   314
            delIndex := index
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   315
        ].
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   316
20037
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   317
        index == length ifTrue:[
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   318
            index := 1
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   319
        ] ifFalse:[
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   320
            index := index + 1
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   321
        ].
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   322
        index == startIndex ifTrue:[
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   323
            delIndex ~~ 0 ifTrue:[
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   324
                keyArray basicAt:delIndex put:nil.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   325
                ^ delIndex
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   326
            ].
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   327
            self grow.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   328
            length := keyArray basicSize.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   329
            startIndex := index := self initialIndexForKey:key.
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   330
        ].
16244
584d9f48f6c1 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 13747
diff changeset
   331
    ] loop.
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   332
2329
937fc97d5544 must always nil empty slots in #findKeyOrNil:
Claus Gittinger <cg@exept.de>
parents: 2315
diff changeset
   333
    "Modified: 30.1.1997 / 15:04:34 / cg"
2988
c6550b3e9b3c Fix spelling.
Stefan Vogel <sv@exept.de>
parents: 2910
diff changeset
   334
    "Modified: 1.10.1997 / 11:25:32 / stefan"
2315
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   335
!
a9ff2fda8bae mhmh - be very careful when searching for some item.
Claus Gittinger <cg@exept.de>
parents: 2306
diff changeset
   336
20237
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   337
findKeyOrNilOrDeletedEntry:key
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   338
    "Look for the key in the receiver.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   339
     If it is found, return the index,
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   340
     otherwise the index of the first unused slot.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   341
     Grow the receiver, if key was not found, and no unused slots were present."
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   342
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   343
    |index  "{ Class:SmallInteger }"
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   344
     length "{ Class:SmallInteger }"
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   345
     startIndex probe
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   346
     delIndex "{ Class:SmallInteger }"|
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   347
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   348
    (OperatingSystem blockInterrupts) ifFalse:[
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   349
        "/
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   350
        "/ may never be entered with interrupts enabled
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   351
        "/
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   352
        OperatingSystem unblockInterrupts.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   353
        self error:'unblocked call of findKeyOrNil'.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   354
    ].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   355
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   356
    delIndex := 0.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   357
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   358
    length := keyArray basicSize.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   359
    startIndex := index := self initialIndexForKey:key.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   360
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   361
    [
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   362
        probe := keyArray basicAt:index.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   363
        key == probe ifTrue:[^ index].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   364
        probe isNil ifTrue:[
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   365
            delIndex == 0 ifTrue:[^ index].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   366
            ^ delIndex
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   367
        ].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   368
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   369
        probe class == SmallInteger ifTrue:[
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   370
            probe := DeletedEntry.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   371
            keyArray basicAt:index put:probe.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   372
            valueArray basicAt:index put:nil.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   373
            tally := tally - 1.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   374
        ].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   375
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   376
        (delIndex == 0 and:[probe == DeletedEntry]) ifTrue:[
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   377
            delIndex := index
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   378
        ].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   379
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   380
        index == length ifTrue:[
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   381
            index := 1
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   382
        ] ifFalse:[
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   383
            index := index + 1
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   384
        ].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   385
        index == startIndex ifTrue:[
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   386
            delIndex ~~ 0 ifTrue:[
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   387
                ^ delIndex
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   388
            ].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   389
            self grow.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   390
            length := keyArray basicSize.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   391
            startIndex := index := self initialIndexForKey:key.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   392
        ].
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   393
    ] loop.
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   394
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   395
    "Modified: 30.1.1997 / 15:04:34 / cg"
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   396
    "Modified: 1.10.1997 / 11:25:32 / stefan"
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   397
!
855a12ebe6f9 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20166
diff changeset
   398
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   399
grow:newSize
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   400
    "grow the receiver.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   401
     Redefined to block interrupts, to avoid trouble when dependencies
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   402
     are added within interrupting high prio processes."
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   403
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   404
"/ 'grow:' printCR.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   405
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   406
    (OperatingSystem blockInterrupts) ifTrue:[
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   407
	"/ already blocked
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   408
	^ super grow:newSize.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   409
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   410
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   411
    [
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   412
	super grow:newSize
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   413
    ] ensure:[
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   414
	OperatingSystem unblockInterrupts
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   415
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   416
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   417
    "Created: 28.1.1997 / 23:41:39 / cg"
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   418
    "Modified: 29.1.1997 / 15:10:12 / cg"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   419
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   420
18333
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   421
initializeForCapacity:minSize
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   422
    "reset the receiver's contents.
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   423
     Redefined to block interrupts, to avoid trouble when dependencies
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   424
     are added within interrupting high prio processes."
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   425
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   426
"/ 'setTally:' printCR.
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   427
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   428
    (OperatingSystem blockInterrupts) ifTrue:[
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   429
	"/ already blocked
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   430
	super initializeForCapacity:minSize.
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   431
	^ self.
18333
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   432
    ].
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   433
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   434
    [
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   435
	super initializeForCapacity:minSize
18333
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   436
    ] ensure:[
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   437
	OperatingSystem unblockInterrupts
18333
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   438
    ].
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   439
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   440
    "Created: 29.1.1997 / 11:40:12 / cg"
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   441
    "Modified: 29.1.1997 / 15:11:11 / cg"
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   442
!
854cf4f00536 class: WeakIdentityDictionary
Claus Gittinger <cg@exept.de>
parents: 16513
diff changeset
   443
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   444
keyContainerOfSize:n
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   445
    "return a container for keys of size n.
20037
a00968eea064 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19193
diff changeset
   446
     use WeakArrays here."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   447
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   448
    |w|
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   449
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   450
    w := WeakArray new:n.
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   451
    w addDependent:self.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   452
    ^ w
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   453
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   454
    "Modified: 7.1.1997 / 17:01:15 / stefan"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   455
    "Modified: 29.1.1997 / 14:18:49 / cg"
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   456
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   457
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   458
rehash
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   459
    "grow the receiver.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   460
     Redefined to block interrupts, to avoid trouble when dependencies
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   461
     are added within interrupting high prio processes."
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   462
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   463
"/ 'rehash' printCR.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   464
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   465
    (OperatingSystem blockInterrupts) ifTrue:[
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   466
	"/ already blocked
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   467
	super rehash.
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   468
	^ self.
2303
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   469
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   470
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   471
    [
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   472
	super rehash
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6309
diff changeset
   473
    ] ensure:[
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   474
	OperatingSystem unblockInterrupts
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   475
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   476
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   477
    "Created: 29.1.1997 / 11:39:42 / cg"
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   478
    "Modified: 29.1.1997 / 14:18:52 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   479
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   480
23691
1fa11cfb492e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21006
diff changeset
   481
!WeakIdentityDictionary methodsFor:'queries'!
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   482
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   483
includes:anObject
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   484
    "redefined to block interrupts
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   485
     (avoid change of the dictionary while accessing)"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   486
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   487
    (OperatingSystem blockInterrupts) ifTrue:[
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   488
        "/ already blocked
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   489
        ^ super includes:anObject.
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   490
    ].
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   491
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   492
    ^ [super includes:anObject] ensure:[OperatingSystem unblockInterrupts].
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   493
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   494
    "Modified: / 06-05-1996 / 12:22:26 / stefan"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   495
    "Created: / 01-07-1997 / 10:47:13 / cg"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   496
    "Modified: / 12-02-2019 / 20:44:29 / Stefan Vogel"
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   497
!
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   498
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   499
includesKey:key
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   500
    "redefined to block interrupts
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   501
     (avoid change of the dictionary while accessing)"
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   502
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   503
    key class == SmallInteger ifTrue:[  
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   504
        "SmallIntegers cannot be stored into a WeakArray"
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   505
        ^ false.
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   506
    ].
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   507
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   508
    (OperatingSystem blockInterrupts) ifTrue:[
20166
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   509
        "/ already blocked
40f9f1f07a68 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20037
diff changeset
   510
        ^ super includesKey:key.
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   511
    ].
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   512
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   513
    ^ [super includesKey:key] ensure:[OperatingSystem unblockInterrupts].
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   514
23724
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   515
    "Modified: / 06-05-1996 / 12:22:26 / stefan"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   516
    "Created: / 01-07-1997 / 10:45:14 / cg"
8320f885588f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23691
diff changeset
   517
    "Modified: / 12-02-2019 / 20:44:54 / Stefan Vogel"
23691
1fa11cfb492e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21006
diff changeset
   518
! !
1fa11cfb492e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21006
diff changeset
   519
1fa11cfb492e #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21006
diff changeset
   520
!WeakIdentityDictionary methodsFor:'testing'!
9243
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   521
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   522
isWeakCollection
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   523
    "return true, if the receiver has weak references to its elements."
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   524
a4ea5c29fe53 +isWeakCollection
Claus Gittinger <cg@exept.de>
parents: 8493
diff changeset
   525
    ^ true
2741
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   526
! !
7af858fd7296 category changes
Claus Gittinger <cg@exept.de>
parents: 2738
diff changeset
   527
635
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   528
!WeakIdentityDictionary class methodsFor:'documentation'!
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   529
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   530
version
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18333
diff changeset
   531
    ^ '$Header$'
20992
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   532
!
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   533
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   534
version_CVS
a2eba1cff036 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20990
diff changeset
   535
    ^ '$Header$'
635
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   536
! !
16244
584d9f48f6c1 [true] whileTrue: -> #loop
Stefan Vogel <sv@exept.de>
parents: 13747
diff changeset
   537