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