author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 19 Jan 2013 01:30:00 +0000 | |
branch | jv |
changeset 18011 | deb0c3355881 |
parent 17966 | 8b5df02e171f |
parent 14305 | a5626a16240d |
child 18630 | a74d669db937 |
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 |
||
14305
a5626a16240d
changed: #keyContainerOfSize:
Claus Gittinger <cg@exept.de>
parents:
13746
diff
changeset
|
58 |
^ WeakArray new:n. |
2297 | 59 |
|
14305
a5626a16240d
changed: #keyContainerOfSize:
Claus Gittinger <cg@exept.de>
parents:
13746
diff
changeset
|
60 |
"Modified: / 07-01-1997 / 17:01:15 / stefan" |
a5626a16240d
changed: #keyContainerOfSize:
Claus Gittinger <cg@exept.de>
parents:
13746
diff
changeset
|
61 |
"Modified: / 04-08-2012 / 14:55:53 / cg" |
2297 | 62 |
! ! |
63 |
||
2093 | 64 |
!WeakDependencyDictionary methodsFor:'special dependency support'! |
65 |
||
66 |
removeEmptyDependencyValues |
|
67 |
"special entry for dependency management: |
|
68 |
remove any empty (due to finalization) value WeakArray elements." |
|
69 |
||
2512 | 70 |
|index t wasBlocked deps o key originalKeyArray| |
2093 | 71 |
|
72 |
"/ careful: this is sent by the finalizer at low prio. |
|
73 |
"/ be prepared for the receiver to change while we walk over |
|
74 |
"/ the value array here ... |
|
75 |
||
2297 | 76 |
"/ 'removeEmptyDependencyValues ...' printCR. |
77 |
||
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
78 |
originalKeyArray := keyArray. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
79 |
|
2093 | 80 |
index := 1. |
81 |
[index <= keyArray size] whileTrue:[ |
|
82 |
"/ get the size again - it could have changed |
|
83 |
||
84 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2297 | 85 |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
86 |
keyArray ~~ originalKeyArray ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
87 |
index := 1. "/ start over |
8031 | 88 |
"/ 'restart removeEmpty' infoPrintCR. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
89 |
originalKeyArray := keyArray. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
90 |
]. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
91 |
|
2093 | 92 |
index <= keyArray size ifTrue:[ |
2297 | 93 |
key := keyArray basicAt:index. |
94 |
key == 0 ifTrue:[ |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
95 |
"/ that one is gone |
2512 | 96 |
key := DeletedEntry. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
97 |
keyArray basicAt:index put:key. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
98 |
valueArray basicAt:index put:nil. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
99 |
tally := tally - 1. |
2297 | 100 |
]. |
101 |
||
2512 | 102 |
(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
|
103 |
deps := valueArray basicAt:index. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
104 |
deps notNil ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
105 |
"/ is it an empty WeakArray ? |
2093 | 106 |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
107 |
(deps isMemberOf:WeakArray) ifTrue:[ |
2508 | 108 |
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
|
109 |
t == 0 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
110 |
"/ yes - nil it |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
111 |
valueArray basicAt:index put:nil. |
2512 | 112 |
keyArray basicAt:index put:DeletedEntry. |
2093 | 113 |
tally := tally - 1. |
114 |
] |
|
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
115 |
] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
116 |
"/ is it an empty WeakIdSet ? |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
117 |
|
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
118 |
(deps isMemberOf:WeakIdentitySet) ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
119 |
(t := deps size) == 0 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
120 |
"/ yes - nil it |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
121 |
valueArray basicAt:index put:nil. |
2512 | 122 |
keyArray basicAt:index put:DeletedEntry. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
123 |
tally := tally - 1. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
124 |
"/ ] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
125 |
"/ t == 1 ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
126 |
"/ "/ careful - it could actually be empty |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
127 |
"/ o := deps firstIfEmpty:nil. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
128 |
"/ o notNil ifTrue:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
129 |
"/ "/ 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
|
130 |
"/ "/ can now use a WeakArray |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
131 |
"/ 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
|
132 |
"/ ] ifFalse:[ |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
133 |
"/ key notNil ifTrue:[ |
2512 | 134 |
"/ keyArray basicAt:index put:DeletedEntry. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
135 |
"/ tally := tally - 1. |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
136 |
"/ ] |
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
137 |
"/ ] |
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 |
] |
2093 | 141 |
] |
142 |
] ifFalse:[ |
|
8031 | 143 |
"/ 'oops: nil value for key' infoPrint. key infoPrintCR. |
2512 | 144 |
keyArray basicAt:index put:DeletedEntry. |
2297 | 145 |
tally := tally - 1. |
146 |
] |
|
2093 | 147 |
] |
148 |
]. |
|
149 |
||
2279
ef0f7f5216c4
oops - irqBlockingstate was corrupted
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
150 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2093 | 151 |
index := index + 1. |
152 |
]. |
|
153 |
||
2297 | 154 |
"/ 'done' printCR. |
2093 | 155 |
" |
156 |
Dependencies removeEmptyDependencyValues |
|
157 |
" |
|
158 |
||
159 |
"Created: 9.1.1997 / 00:00:28 / cg" |
|
2512 | 160 |
"Modified: 27.3.1997 / 15:55:12 / cg" |
2299 | 161 |
! ! |
162 |
||
2093 | 163 |
!WeakDependencyDictionary class methodsFor:'documentation'! |
164 |
||
165 |
version |
|
14305
a5626a16240d
changed: #keyContainerOfSize:
Claus Gittinger <cg@exept.de>
parents:
13746
diff
changeset
|
166 |
^ '$Header: /cvs/stx/stx/libbasic/WeakDependencyDictionary.st,v 1.14 2012-08-06 12:38:10 cg Exp $' |
2093 | 167 |
! ! |