author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 18 Jul 2011 16:22:09 +0100 | |
branch | jv |
changeset 17846 | 24edc476ac18 |
parent 17845 | 7e0cfaac936d |
child 17865 | 598963c6ff8e |
permissions | -rw-r--r-- |
2093 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
" |
|
17845 | 12 |
|
13 |
||
8031 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
2093 | 16 |
WeakIdentityDictionary subclass:#WeakDependencyDictionary |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
4350 | 20 |
category:'Collections-Weak' |
2093 | 21 |
! |
22 |
||
23 |
!WeakDependencyDictionary class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1997 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
A specialized WeakIdentityDictionary, which 'knowns' how |
|
43 |
to get rid of obsolete entries. This is only used with the |
|
44 |
dependency mechanism. |
|
45 |
||
46 |
[author:] |
|
47 |
Claus Gittinger |
|
48 |
||
49 |
[See also:] |
|
50 |
WeakArray WeakIdentityDictionary WeakValueDictionary WeakIdentitySet |
|
51 |
" |
|
52 |
! ! |
|
53 |
||
2297 | 54 |
!WeakDependencyDictionary methodsFor:'private'! |
55 |
||
56 |
keyContainerOfSize:n |
|
57 |
"return a container for keys of size n. |
|
58 |
use WeakArrays here." |
|
59 |
||
60 |
|w| |
|
61 |
||
62 |
w := WeakArray new:n. |
|
63 |
^ w |
|
64 |
||
65 |
"Modified: 7.1.1997 / 17:01:15 / stefan" |
|
66 |
! ! |
|
67 |
||
2093 | 68 |
!WeakDependencyDictionary methodsFor:'special dependency support'! |
69 |
||
70 |
removeEmptyDependencyValues |
|
71 |
"special entry for dependency management: |
|
72 |
remove any empty (due to finalization) value WeakArray elements." |
|
73 |
||
2512 | 74 |
|index t wasBlocked deps o key originalKeyArray| |
2093 | 75 |
|
76 |
"/ careful: this is sent by the finalizer at low prio. |
|
77 |
"/ be prepared for the receiver to change while we walk over |
|
78 |
"/ the value array here ... |
|
79 |
||
2297 | 80 |
"/ 'removeEmptyDependencyValues ...' printCR. |
81 |
||
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
82 |
originalKeyArray := keyArray. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
83 |
|
2093 | 84 |
index := 1. |
85 |
[index <= keyArray size] whileTrue:[ |
|
86 |
"/ get the size again - it could have changed |
|
87 |
||
88 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2297 | 89 |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
90 |
keyArray ~~ originalKeyArray ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
91 |
index := 1. "/ start over |
8031 | 92 |
"/ 'restart removeEmpty' infoPrintCR. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
93 |
originalKeyArray := keyArray. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
94 |
]. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
95 |
|
2093 | 96 |
index <= keyArray size ifTrue:[ |
2297 | 97 |
key := keyArray basicAt:index. |
98 |
key == 0 ifTrue:[ |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
99 |
"/ that one is gone |
2512 | 100 |
key := DeletedEntry. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
101 |
keyArray basicAt:index put:key. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
102 |
valueArray basicAt:index put:nil. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
103 |
tally := tally - 1. |
2297 | 104 |
]. |
105 |
||
2512 | 106 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
107 |
deps := valueArray basicAt:index. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
108 |
deps notNil ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
109 |
"/ is it an empty WeakArray ? |
2093 | 110 |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
111 |
(deps isMemberOf:WeakArray) ifTrue:[ |
2508 | 112 |
t := deps findFirst:[:el | el notNil and:[el ~~ 0]]. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
113 |
t == 0 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
114 |
"/ yes - nil it |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
115 |
valueArray basicAt:index put:nil. |
2512 | 116 |
keyArray basicAt:index put:DeletedEntry. |
2093 | 117 |
tally := tally - 1. |
118 |
] |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
119 |
] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
120 |
"/ is it an empty WeakIdSet ? |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
121 |
|
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
122 |
(deps isMemberOf:WeakIdentitySet) ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
123 |
(t := deps size) == 0 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
124 |
"/ yes - nil it |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
125 |
valueArray basicAt:index put:nil. |
2512 | 126 |
keyArray basicAt:index put:DeletedEntry. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
127 |
tally := tally - 1. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
128 |
"/ ] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
129 |
"/ t == 1 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
130 |
"/ "/ careful - it could actually be empty |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
131 |
"/ o := deps firstIfEmpty:nil. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
132 |
"/ o notNil ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
133 |
"/ "/ the set lost an object, and shrunk to size 1 |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
134 |
"/ "/ can now use a WeakArray |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
135 |
"/ valueArray basicAt:index put:(WeakArray with:o) |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
136 |
"/ ] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
137 |
"/ key notNil ifTrue:[ |
2512 | 138 |
"/ keyArray basicAt:index put:DeletedEntry. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
139 |
"/ tally := tally - 1. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
140 |
"/ ] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
141 |
"/ ] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
142 |
"/ ] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
143 |
] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
144 |
] |
2093 | 145 |
] |
146 |
] ifFalse:[ |
|
8031 | 147 |
"/ 'oops: nil value for key' infoPrint. key infoPrintCR. |
2512 | 148 |
keyArray basicAt:index put:DeletedEntry. |
2297 | 149 |
tally := tally - 1. |
150 |
] |
|
2093 | 151 |
] |
152 |
]. |
|
153 |
||
2279
ef0f7f5216c4
oops - irqBlockingstate was corrupted
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
154 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2093 | 155 |
index := index + 1. |
156 |
]. |
|
157 |
||
2297 | 158 |
"/ 'done' printCR. |
2093 | 159 |
" |
160 |
Dependencies removeEmptyDependencyValues |
|
161 |
" |
|
162 |
||
163 |
"Created: 9.1.1997 / 00:00:28 / cg" |
|
2512 | 164 |
"Modified: 27.3.1997 / 15:55:12 / cg" |
2299 | 165 |
! ! |
166 |
||
2093 | 167 |
!WeakDependencyDictionary class methodsFor:'documentation'! |
168 |
||
169 |
version |
|
17846 | 170 |
^ '$Id: WeakDependencyDictionary.st 10660 2011-07-18 15:22:09Z vranyj1 $' |
171 |
! ! |