author | Claus Gittinger <cg@exept.de> |
Fri, 24 Jan 1997 19:16:48 +0100 | |
changeset 2256 | ffd565c6e084 |
parent 2101 | 516fedf50916 |
child 2261 | 61096f935f76 |
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 |
" |
|
12 |
||
13 |
||
14 |
WeakIdentityDictionary subclass:#WeakDependencyDictionary |
|
15 |
instanceVariableNames:'' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Unordered' |
|
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 |
||
52 |
!WeakDependencyDictionary methodsFor:'special dependency support'! |
|
53 |
||
54 |
removeEmptyDependencyValues |
|
55 |
"special entry for dependency management: |
|
56 |
remove any empty (due to finalization) value WeakArray elements." |
|
57 |
||
58 |
|index t wasBlocked val| |
|
59 |
||
60 |
"/ careful: this is sent by the finalizer at low prio. |
|
61 |
"/ be prepared for the receiver to change while we walk over |
|
62 |
"/ the value array here ... |
|
63 |
||
64 |
index := 1. |
|
65 |
[index <= keyArray size] whileTrue:[ |
|
66 |
"/ get the size again - it could have changed |
|
67 |
||
68 |
wasBlocked := OperatingSystem blockInterrupts. |
|
69 |
index <= keyArray size ifTrue:[ |
|
70 |
val := valueArray basicAt:index. |
|
71 |
val notNil ifTrue:[ |
|
72 |
"/ is it an empty WeakArray ? |
|
73 |
||
74 |
(val isMemberOf:WeakArray) ifTrue:[ |
|
75 |
t := val findFirst:[:el | el notNil and:[el ~~ 0]]. |
|
76 |
t == 0 ifTrue:[ |
|
77 |
"/ yes - nil it |
|
78 |
valueArray basicAt:index put:nil. |
|
79 |
(keyArray basicAt:index) notNil ifTrue:[ |
|
80 |
keyArray basicAt:index put:DeletedEntry. |
|
81 |
tally := tally - 1. |
|
82 |
] |
|
83 |
] |
|
84 |
] ifFalse:[ |
|
85 |
"/ is it an empty WeakIdSet ? |
|
86 |
||
87 |
(val isMemberOf:WeakIdentitySet) ifTrue:[ |
|
2101
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
88 |
(t := val size) == 0 ifTrue:[ |
2093 | 89 |
"/ yes - nil it |
90 |
valueArray basicAt:index put:nil. |
|
91 |
(keyArray basicAt:index) notNil ifTrue:[ |
|
92 |
keyArray basicAt:index put:DeletedEntry. |
|
93 |
tally := tally - 1. |
|
94 |
] |
|
2101
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
95 |
] ifFalse:[ |
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
96 |
t == 1 ifTrue:[ |
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
97 |
"/ the set lost an object, and shrunk to size 1 |
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
98 |
"/ can now use a WeakArray |
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
99 |
valueArray basicAt:index put:(WeakArray with:val first) |
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
100 |
] |
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
101 |
] |
2093 | 102 |
] |
103 |
] |
|
104 |
] |
|
105 |
]. |
|
106 |
||
107 |
wasBlocked ifTrue:[OperatingSystem unblockInterrupts]. |
|
108 |
index := index + 1. |
|
109 |
]. |
|
110 |
||
111 |
" |
|
112 |
Dependencies removeEmptyDependencyValues |
|
113 |
" |
|
114 |
||
115 |
"Modified: 8.1.1997 / 23:57:56 / cg" |
|
116 |
"Created: 9.1.1997 / 00:00:28 / cg" |
|
117 |
! ! |
|
118 |
||
119 |
!WeakDependencyDictionary class methodsFor:'documentation'! |
|
120 |
||
121 |
version |
|
2101
516fedf50916
make 1-entry sets into an array
Claus Gittinger <cg@exept.de>
parents:
2093
diff
changeset
|
122 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakDepDict.st,v 1.2 1997-01-09 00:31:33 cg Exp $' |
2093 | 123 |
! ! |