WeakIdentityDictionary.st
author Claus Gittinger <cg@exept.de>
Wed, 29 Jan 1997 15:29:04 +0100
changeset 2303 f19df2d4c238
parent 2298 e75dabb791dc
child 2306 3851fc553893
permissions -rw-r--r--
avoid creation of a blocks if possible - if not, cheap ones are now created
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
     1
"
62211a9bc04d Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
358
claus
parents: 159
diff changeset
     3
	      All Rights Reserved
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
     4
62211a9bc04d Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
62211a9bc04d Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
62211a9bc04d Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
62211a9bc04d Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
62211a9bc04d Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
62211a9bc04d Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
62211a9bc04d Initial revision
claus
parents:
diff changeset
    11
"
62211a9bc04d Initial revision
claus
parents:
diff changeset
    12
62211a9bc04d Initial revision
claus
parents:
diff changeset
    13
IdentityDictionary subclass:#WeakIdentityDictionary
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    14
	instanceVariableNames:''
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    15
	classVariableNames:''
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    16
	poolDictionaries:''
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
    17
	category:'Collections-Unordered'
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
    18
!
62211a9bc04d Initial revision
claus
parents:
diff changeset
    19
10
claus
parents: 6
diff changeset
    20
!WeakIdentityDictionary class methodsFor:'documentation'!
claus
parents: 6
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    24
 COPYRIGHT (c) 1992 by Claus Gittinger
358
claus
parents: 159
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    35
10
claus
parents: 6
diff changeset
    36
documentation
claus
parents: 6
diff changeset
    37
"
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    38
    WeakIdentityDictionaries behave like IdentityDictionaries, 
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
    39
    as long as the keys are still referenced by some 
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    40
    other (non-weak) object.
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    41
    However, once the last non-weak reference ceases to exist,
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    42
    the object will be automatically removed from the Weakcollection
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    43
    (with some delay: it will be removed after the next garbage collect).
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    44
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    45
    This class was added to support keeping track of dependents without
88
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    46
    keeping the values alive - values simply become nil when no one else
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    47
    references it. The original dependency mechanism used a regular Dictionary,
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    48
    which usually leads to a lot of garbage being kept due to a forgotten
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    49
    release. Using a WeakDictionary may be incompatible to ST-80 but is much
81dacba7a63a *** empty log message ***
claus
parents: 63
diff changeset
    50
    more comfortable, since no manual release of dependents is needed.
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    51
2260
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    52
    If you use this, be very careful since the collections size changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    53
    'magically' - for example, testing for being nonEmpty and then
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    54
    removing the first element may fail, since the element may vanish inbetween.
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    55
    In general, never trust the value as returned by the size/isEmpty messages.
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    56
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
    57
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    58
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    59
        Claus Gittinger
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1263
diff changeset
    60
1263
92c1db6b0776 commentary
Claus Gittinger <cg@exept.de>
parents: 1256
diff changeset
    61
    [See also:]
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
    62
        WeakArray WeakValueDictionary WeakIdentitySet
10
claus
parents: 6
diff changeset
    63
"
claus
parents: 6
diff changeset
    64
! !
claus
parents: 6
diff changeset
    65
359
claus
parents: 358
diff changeset
    66
!WeakIdentityDictionary methodsFor:'adding & removing'!
claus
parents: 358
diff changeset
    67
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    68
at:key
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    69
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
    70
    |val|
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    71
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
    72
    (OperatingSystem blockInterrupts) ifTrue:[
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    73
        "/ already blocked
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    74
        ^ super at:key.
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    75
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    76
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    77
    [
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    78
        val := super at:key.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    79
    ] valueNowOrOnUnwindDo:[
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
    80
        OperatingSystem unblockInterrupts.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    81
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    82
    ^ val
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    83
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    84
    "Modified: 6.5.1996 / 12:22:26 / stefan"
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
    85
    "Modified: 29.1.1997 / 15:07:44 / cg"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    86
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    87
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    88
at:key ifAbsent:exceptionBlock
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    89
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
    90
    |val|
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    91
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
    92
    (OperatingSystem blockInterrupts) ifTrue:[
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    93
        "/ already blocked
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    94
        ^ super at:key ifAbsent:exceptionBlock.
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    95
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
    96
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    97
    [
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    98
        val := super at:key ifAbsent:exceptionBlock.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
    99
    ] valueNowOrOnUnwindDo:[
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
   100
        OperatingSystem unblockInterrupts.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   101
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   102
    ^ val
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   103
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   104
    "Modified: 6.5.1996 / 12:22:26 / stefan"
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
   105
    "Modified: 29.1.1997 / 15:08:07 / cg"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   106
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   107
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   108
at:key put:anObject
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   109
    "add the argument anObject under key, aKey to the receiver.
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   110
     Return anObject (sigh).
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   111
     Redefined to block interrupts, to avoid trouble when dependencies
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   112
     are added within interrupting high prio processes."
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   113
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
   114
    |val|
359
claus
parents: 358
diff changeset
   115
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
   116
    (OperatingSystem blockInterrupts) ifTrue:[
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   117
        "/ already blocked
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   118
        ^ super at:key put:anObject.
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   119
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   120
1790
4187e9fc7357 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   121
    [
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
   122
        val := super at:key put:anObject.
1790
4187e9fc7357 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   123
    ] valueNowOrOnUnwindDo:[
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
   124
        OperatingSystem unblockInterrupts.
1790
4187e9fc7357 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   125
    ].
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
   126
    ^ val
1223
09d16bc18493 at:put: returns its arg
Claus Gittinger <cg@exept.de>
parents: 1054
diff changeset
   127
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   128
    "Modified: 6.5.1996 / 12:22:26 / stefan"
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
   129
    "Modified: 29.1.1997 / 15:08:45 / cg"
359
claus
parents: 358
diff changeset
   130
!
claus
parents: 358
diff changeset
   131
claus
parents: 358
diff changeset
   132
removeKey:aKey ifAbsent:aBlock
1256
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   133
    "remove the association under aKey from the collection,
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   134
     return the value previously stored there..
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   135
     If it was not in the collection return the result 
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   136
     from evaluating aBlock.
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   137
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   138
    Redefined to avoid synchronization problems, in case
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   139
    of interrupts (otherwise, there could be some other operation 
249fd57abee5 commentary
Claus Gittinger <cg@exept.de>
parents: 1223
diff changeset
   140
    on the receiver done by another process, which garbles my contents)."
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
   141
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
   142
    |ret|
359
claus
parents: 358
diff changeset
   143
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
   144
    (OperatingSystem blockInterrupts) ifTrue:[
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   145
        "/ already blocked
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
        ^ super removeKey:aKey ifAbsent:aBlock.
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   147
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   148
359
claus
parents: 358
diff changeset
   149
    [
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   150
        ret := super removeKey:aKey ifAbsent:aBlock
359
claus
parents: 358
diff changeset
   151
    ] valueNowOrOnUnwindDo:[
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
   152
        OperatingSystem unblockInterrupts
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   153
    ].
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   154
    ^ ret
1054
62ce964f1d2e commentary
Claus Gittinger <cg@exept.de>
parents: 635
diff changeset
   155
1343
b0ee705c63e0 Correct return value when removing elements.
Stefan Vogel <sv@exept.de>
parents: 1290
diff changeset
   156
    "Modified: 6.5.1996 / 12:44:51 / stefan"
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
   157
    "Modified: 29.1.1997 / 15:09:11 / cg"
359
claus
parents: 358
diff changeset
   158
! !
claus
parents: 358
diff changeset
   159
10
claus
parents: 6
diff changeset
   160
!WeakIdentityDictionary methodsFor:'element disposal'!
claus
parents: 6
diff changeset
   161
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   162
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
   163
    "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
   164
     disposed keys."
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
   165
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   166
    |wasBlocked|
358
claus
parents: 159
diff changeset
   167
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   168
    something == #ElementExpired ifTrue:[
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   169
        "
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   170
         have to block here - dispose may be done at a low priority
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
   171
         from the background finalizer. If new items are added by a 
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   172
         higher prio process, the dictionary might get corrupted otherwise
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   173
        "
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   174
        wasBlocked := OperatingSystem blockInterrupts.
10
claus
parents: 6
diff changeset
   175
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   176
        keyArray 
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   177
            forAllDeadIndicesDo:[:idx | 
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
   178
                                    valueArray basicAt:idx put:nil.
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   179
                                    tally := tally - 1.
2027
4a2cdf9946ae replace items with DeletedEntry, when objects are collected.
ca
parents: 1790
diff changeset
   180
                                ]
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   181
            replacingCorpsesWith:DeletedEntry.
358
claus
parents: 159
diff changeset
   182
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   183
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   184
    ]
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   185
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   186
    "Created: 7.1.1997 / 16:59:30 / stefan"
6
62211a9bc04d Initial revision
claus
parents:
diff changeset
   187
! !
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   188
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   189
!WeakIdentityDictionary methodsFor:'private'!
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   190
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   191
grow:newSize
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   192
    "grow the receiver.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   193
     Redefined to block interrupts, to avoid trouble when dependencies
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   194
     are added within interrupting high prio processes."
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   195
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
   196
"/ 'grow:' printCR.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   197
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
   198
    (OperatingSystem blockInterrupts) ifTrue:[
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   199
        "/ already blocked
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   200
        ^ super grow:newSize.
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   201
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   202
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   203
    [
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   204
        super grow:newSize
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   205
    ] valueNowOrOnUnwindDo:[
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
   206
        OperatingSystem unblockInterrupts
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   207
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   208
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   209
    "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
   210
    "Modified: 29.1.1997 / 15:10:12 / cg"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   211
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   212
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   213
keyContainerOfSize:n
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
    "return a container for keys of size n.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   215
     use WeakArrays here, but dont make me a depenent of it."
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   216
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   217
    |w|
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   219
    w := WeakArray new:n.
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   220
    w addDependent:self.
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   221
    ^ w
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   222
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 2027
diff changeset
   223
    "Modified: 7.1.1997 / 17:01:15 / stefan"
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   224
    "Modified: 29.1.1997 / 14:18:49 / cg"
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   225
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   226
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   227
rehash
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   228
    "grow the receiver.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   229
     Redefined to block interrupts, to avoid trouble when dependencies
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   230
     are added within interrupting high prio processes."
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   231
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   232
"/ 'rehash' printCR.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   233
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
   234
    (OperatingSystem blockInterrupts) ifTrue:[
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   235
        "/ already blocked
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   236
        ^ super rehash.
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   237
    ].
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
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   239
    [
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   240
        super rehash
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   241
    ] valueNowOrOnUnwindDo:[
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
   242
        OperatingSystem unblockInterrupts
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   243
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   244
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   245
    "Created: 29.1.1997 / 11:39:42 / cg"
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   246
    "Modified: 29.1.1997 / 14:18:52 / cg"
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   247
!
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   248
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   249
setTally:count
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   250
    "grow the receiver.
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   251
     Redefined to block interrupts, to avoid trouble when dependencies
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   252
     are added within interrupting high prio processes."
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   253
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
   254
"/ 'setTally:' printCR.
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   255
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
   256
    (OperatingSystem blockInterrupts) ifTrue:[
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   257
        "/ already blocked
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   258
        ^ super setTally:count.
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   259
    ].
f19df2d4c238 avoid creation of a blocks if possible - if not, cheap ones are now created
Claus Gittinger <cg@exept.de>
parents: 2298
diff changeset
   260
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   261
    [
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   262
        super setTally:count
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   263
    ] valueNowOrOnUnwindDo:[
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
   264
        OperatingSystem unblockInterrupts
2298
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   265
    ].
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   266
e75dabb791dc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2260
diff changeset
   267
    "Created: 29.1.1997 / 11:40:12 / 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
   268
    "Modified: 29.1.1997 / 15:11:11 / cg"
609
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   269
! !
12be97f6d5a7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   270
635
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   271
!WeakIdentityDictionary class methodsFor:'documentation'!
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   272
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   273
version
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
   274
    ^ '$Header: /cvs/stx/stx/libbasic/WeakIdentityDictionary.st,v 1.26 1997-01-29 14:28:36 cg Exp $'
635
86cbe76f5a20 version at the end
Claus Gittinger <cg@exept.de>
parents: 609
diff changeset
   275
! !