author | Stefan Vogel <sv@exept.de> |
Thu, 16 Apr 2020 16:57:05 +0200 | |
changeset 25362 | f1606835f9fb |
parent 20036 | c84dadf61250 |
child 20079 | 8d884971c2ed |
permissions | -rw-r--r-- |
20036 | 1 |
"{ Encoding: utf8 }" |
2 |
||
2093 | 3 |
" |
4 |
COPYRIGHT (c) 1997 by Claus Gittinger |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
5 |
All Rights Reserved |
2093 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
8031 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
20036 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
2093 | 18 |
WeakIdentityDictionary subclass:#WeakDependencyDictionary |
19 |
instanceVariableNames:'' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
4350 | 22 |
category:'Collections-Weak' |
2093 | 23 |
! |
24 |
||
25 |
!WeakDependencyDictionary class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1997 by Claus Gittinger |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
30 |
All Rights Reserved |
2093 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
||
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
A specialized WeakIdentityDictionary, which 'knowns' how |
|
45 |
to get rid of obsolete entries. This is only used with the |
|
46 |
dependency mechanism. |
|
47 |
||
48 |
[author:] |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
49 |
Claus Gittinger |
2093 | 50 |
|
51 |
[See also:] |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
52 |
WeakArray WeakIdentityDictionary WeakValueDictionary WeakIdentitySet |
2093 | 53 |
" |
54 |
! ! |
|
55 |
||
2297 | 56 |
!WeakDependencyDictionary methodsFor:'private'! |
57 |
||
58 |
keyContainerOfSize:n |
|
59 |
"return a container for keys of size n. |
|
20036 | 60 |
use WeakArrays here, but don't make me a dependent of it." |
2297 | 61 |
|
14305
a5626a16240d
changed: #keyContainerOfSize:
Claus Gittinger <cg@exept.de>
parents:
13746
diff
changeset
|
62 |
^ WeakArray new:n. |
2297 | 63 |
|
14305
a5626a16240d
changed: #keyContainerOfSize:
Claus Gittinger <cg@exept.de>
parents:
13746
diff
changeset
|
64 |
"Modified: / 07-01-1997 / 17:01:15 / stefan" |
a5626a16240d
changed: #keyContainerOfSize:
Claus Gittinger <cg@exept.de>
parents:
13746
diff
changeset
|
65 |
"Modified: / 04-08-2012 / 14:55:53 / cg" |
2297 | 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:[ |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
86 |
"/ get the size again - it could have changed |
2093 | 87 |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
88 |
wasBlocked := OperatingSystem blockInterrupts. |
2297 | 89 |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
90 |
keyArray ~~ originalKeyArray ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
91 |
index := 1. "/ start over |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
92 |
"/ 'restart removeEmpty' infoPrintCR. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
93 |
originalKeyArray := keyArray. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
94 |
]. |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
95 |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
96 |
index <= keyArray size ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
97 |
key := keyArray basicAt:index. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
98 |
key class == SmallInteger ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
99 |
"/ that one is gone |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
100 |
key := DeletedEntry. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
101 |
keyArray basicAt:index put:key. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
102 |
valueArray basicAt:index put:nil. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
103 |
tally := tally - 1. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
104 |
]. |
2297 | 105 |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
106 |
(key notNil and:[key ~~ DeletedEntry]) ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
107 |
deps := valueArray basicAt:index. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
108 |
deps notNil ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
109 |
"/ is it an empty WeakArray ? |
2093 | 110 |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
111 |
(deps isMemberOf:WeakArray) ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
112 |
t := deps findFirst:[:el | el notNil and:[el ~~ 0]]. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
113 |
t == 0 ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
114 |
"/ yes - nil it |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
115 |
valueArray basicAt:index put:nil. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
116 |
keyArray basicAt:index put:DeletedEntry. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
117 |
tally := tally - 1. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
118 |
] |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
119 |
] ifFalse:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
120 |
"/ is it an empty WeakIdSet ? |
2316
6b24c092456a
mhmh - be very careful when removing empty slots.
Claus Gittinger <cg@exept.de>
parents:
2300
diff
changeset
|
121 |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
122 |
(deps isMemberOf:WeakIdentitySet) ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
123 |
(t := deps size) == 0 ifTrue:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
124 |
"/ yes - nil it |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
125 |
valueArray basicAt:index put:nil. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
126 |
keyArray basicAt:index put:DeletedEntry. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
127 |
tally := tally - 1. |
2316
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 |
"/ ] |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
143 |
] |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
144 |
] |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
145 |
] |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
146 |
] ifFalse:[ |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
147 |
"/ 'oops: nil value for key' infoPrint. key infoPrintCR. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
148 |
keyArray basicAt:index put:DeletedEntry. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
149 |
tally := tally - 1. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
150 |
] |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
151 |
] |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
152 |
]. |
2093 | 153 |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
154 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
155 |
index := index + 1. |
2093 | 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 |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
14305
diff
changeset
|
170 |
^ '$Header$' |
2093 | 171 |
! ! |
20036 | 172 |