author | Claus Gittinger <cg@exept.de> |
Thu, 21 Mar 1996 16:33:40 +0100 | |
changeset 1113 | 840b03d131d7 |
parent 1054 | 62ce964f1d2e |
child 1232 | 25b756de5c51 |
permissions | -rw-r--r-- |
94 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
187 | 3 |
All Rights Reserved |
94 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
IdentitySet subclass:#WeakIdentitySet |
|
1054 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Collections-Unordered' |
|
94 | 18 |
! |
19 |
||
20 |
!WeakIdentitySet class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
187 | 25 |
All Rights Reserved |
94 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
this is a special class to support dependencies which do not |
|
39 |
prevent objects from dying. |
|
40 |
" |
|
41 |
! ! |
|
42 |
||
111 | 43 |
!WeakIdentitySet class methodsFor:'instance creation'! |
44 |
||
45 |
new |
|
46 |
"return a new empty Set" |
|
47 |
||
48 |
^ self new:1 |
|
49 |
! ! |
|
50 |
||
609 | 51 |
!WeakIdentitySet class methodsFor:'queries'! |
52 |
||
53 |
goodSizeFrom:arg |
|
54 |
"return a good array size for the given argument. |
|
55 |
Since WeakIdentitySets are mostly used for dependency management, we typically |
|
56 |
have only one element in the set. Therefore use exact size for small sets |
|
57 |
(instead of rounding up to the prime 11)." |
|
58 |
||
59 |
arg <= 10 ifTrue:[ |
|
60 |
arg < 1 ifTrue:[^ 1]. |
|
61 |
^ arg. |
|
62 |
]. |
|
63 |
^ super goodSizeFrom:arg |
|
64 |
! ! |
|
65 |
||
359 | 66 |
!WeakIdentitySet methodsFor:'adding & removing'! |
67 |
||
68 |
add:newElement |
|
69 |
"redefined to avoid synchronization promlems, in case |
|
70 |
of interrupts |
|
71 |
(otherwise, there could be some other operation on the receiver |
|
72 |
done by another process, which garbles my contents)" |
|
73 |
||
74 |
|wasBlocked| |
|
75 |
||
76 |
wasBlocked := OperatingSystem blockInterrupts. |
|
77 |
super add:newElement. |
|
78 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
|
79 |
! |
|
80 |
||
81 |
remove:anObject ifAbsent:exceptionBlock |
|
1054 | 82 |
"redefined to avoid synchronization problems, in case |
359 | 83 |
of interrupts |
84 |
(otherwise, there could be some other operation on the receiver |
|
85 |
done by another process, which garbles my contents)" |
|
86 |
||
87 |
|wasBlocked| |
|
88 |
||
89 |
wasBlocked := OperatingSystem blockInterrupts. |
|
90 |
[ |
|
1054 | 91 |
super remove:anObject ifAbsent:exceptionBlock |
359 | 92 |
] valueNowOrOnUnwindDo:[ |
1054 | 93 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
359 | 94 |
] |
1054 | 95 |
|
96 |
"Modified: 1.3.1996 / 21:16:10 / cg" |
|
359 | 97 |
! ! |
98 |
||
609 | 99 |
!WeakIdentitySet methodsFor:'element disposal'! |
94 | 100 |
|
609 | 101 |
informDispose |
102 |
"an element died - must rehash" |
|
103 |
||
924
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
104 |
|wasBlocked cnt| |
111 | 105 |
|
609 | 106 |
" |
107 |
must block interrupts here - finalization |
|
108 |
may be done at low prio in the background |
|
109 |
finalizer, we do not want to be interrupted |
|
110 |
while rehashing |
|
111 |
" |
|
112 |
wasBlocked := OperatingSystem blockInterrupts. |
|
924
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
113 |
|
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
114 |
"/ |
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
115 |
"/ recompute my tally |
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
116 |
"/ |
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
117 |
cnt := 0. |
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
118 |
keyArray nonNilElementsDo:[:el | cnt := cnt + 1]. |
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
119 |
tally := cnt. |
5745a1132511
oops - size was not updated when elements were disposed (update tally)
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
120 |
|
609 | 121 |
self rehash. |
122 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
94 | 123 |
! ! |
124 |
||
216 | 125 |
!WeakIdentitySet methodsFor:'enumerating'! |
126 |
||
127 |
do:aBlock |
|
128 |
"perform the block for all members in the collection. |
|
129 |
This method has been rewritten to be more robust about |
|
130 |
changed contents while enumerating elements (which might |
|
131 |
happen during change&update processing, if dependents |
|
132 |
are added or removed within the update." |
|
133 |
||
134 |
|index "{ Class: SmallInteger }" |
|
135 |
element| |
|
136 |
||
137 |
index := 1. |
|
138 |
[index <= keyArray size] whileTrue:[ |
|
139 |
element := keyArray at:index. |
|
140 |
(element notNil and:[element ~~ DeletedEntry]) ifTrue:[ |
|
141 |
aBlock value:element |
|
142 |
]. |
|
143 |
index := index + 1 |
|
144 |
] |
|
145 |
! ! |
|
146 |
||
609 | 147 |
!WeakIdentitySet methodsFor:'private'! |
94 | 148 |
|
609 | 149 |
keyContainerOfSize:n |
150 |
"return a container for keys and values of size n. |
|
151 |
use WeakArrays here." |
|
359 | 152 |
|
609 | 153 |
|w| |
154 |
||
155 |
w := WeakArray new:n. |
|
156 |
w watcher:self. |
|
157 |
^ w |
|
94 | 158 |
! ! |
609 | 159 |
|
636 | 160 |
!WeakIdentitySet class methodsFor:'documentation'! |
161 |
||
162 |
version |
|
1054 | 163 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakIdSet.st,v 1.14 1996-03-01 20:26:42 cg Exp $' |
636 | 164 |
! ! |