author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 02:16:37 +0100 | |
changeset 605 | 8b17f96bf05a |
parent 530 | 07d0bce293c9 |
child 609 | 12be97f6d5a7 |
permissions | -rw-r--r-- |
6 | 1 |
" |
2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
358 | 3 |
All Rights Reserved |
6 | 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 |
IdentityDictionary subclass:#WeakIdentityDictionary |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
159 | 17 |
category:'Collections-Unordered' |
6 | 18 |
! |
19 |
||
10 | 20 |
!WeakIdentityDictionary class methodsFor:'documentation'! |
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
358 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
version |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakIdDict.st,v 1.11 1995-11-11 15:28:38 cg Exp $' |
88 | 38 |
! |
39 |
||
10 | 40 |
documentation |
41 |
" |
|
88 | 42 |
this is a special class to support keeping track of dependents without |
43 |
keeping the values alive - values simply become nil when no one else |
|
44 |
references it. The original dependency mechanism used a regular Dictionary, |
|
45 |
which usually leads to a lot of garbage being kept due to a forgotten |
|
46 |
release. Using a WeakDictionary may be incompatible to ST-80 but is much |
|
47 |
more comfortable, since no manual release of dependents is needed. |
|
10 | 48 |
" |
49 |
! ! |
|
50 |
||
6 | 51 |
!WeakIdentityDictionary methodsFor:'private'! |
52 |
||
10 | 53 |
keyContainerOfSize:n |
359 | 54 |
"return a container for keys of size n. |
10 | 55 |
use WeakArrays here." |
56 |
||
57 |
|w| |
|
58 |
||
59 |
w := WeakArray new:n. |
|
60 |
w watcher:self. |
|
61 |
^ w |
|
62 |
! ! |
|
63 |
||
359 | 64 |
!WeakIdentityDictionary methodsFor:'adding & removing'! |
65 |
||
66 |
at:key put:value |
|
67 |
|wasBlocked| |
|
68 |
||
69 |
wasBlocked := OperatingSystem blockInterrupts. |
|
70 |
super at:key put:value. |
|
71 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
|
72 |
! |
|
73 |
||
74 |
removeKey:aKey ifAbsent:aBlock |
|
75 |
|wasBlocked| |
|
76 |
||
77 |
wasBlocked := OperatingSystem blockInterrupts. |
|
78 |
[ |
|
79 |
super removeKey:aKey ifAbsent:aBlock |
|
80 |
] valueNowOrOnUnwindDo:[ |
|
81 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts] |
|
82 |
] |
|
83 |
! ! |
|
84 |
||
10 | 85 |
!WeakIdentityDictionary methodsFor:'element disposal'! |
86 |
||
87 |
informDispose |
|
88 |
"an element (either key or value) died - rehash" |
|
6 | 89 |
|
10 | 90 |
| sz "{ Class:SmallInteger }" |
358 | 91 |
any wasBlocked | |
92 |
||
93 |
" |
|
94 |
have to block here - dispose may be done at a low priority |
|
95 |
from the background finalizer. If new views are opened in |
|
96 |
the foreground, the dependency dictionary may get corrupted |
|
97 |
otherwise |
|
98 |
" |
|
99 |
wasBlocked := OperatingSystem blockInterrupts. |
|
10 | 100 |
|
101 |
sz := keyArray size. |
|
102 |
any := false. |
|
103 |
1 to:sz do:[:index | |
|
358 | 104 |
(keyArray at:index) isNil ifTrue:[ |
105 |
(valueArray at:index) notNil ifTrue:[ |
|
95 | 106 |
"/ soon to come; can then avoid rehash |
359 | 107 |
"/ " |
108 |
"/ if the next slot is not nil, it could be there due |
|
109 |
"/ to a hash collision. In this case we have to put a |
|
110 |
"/ DeletedMark into the slot. |
|
111 |
"/ " |
|
95 | 112 |
"/ |
113 |
"/ index == sz ifTrue:[ |
|
114 |
"/ next := 1 |
|
115 |
"/ ] ifFalse:[ |
|
116 |
"/ next := index + 1. |
|
117 |
"/ ]. |
|
118 |
"/ |
|
119 |
"/ (keyArray basicAt:next) notNil ifTrue:[ |
|
120 |
"/ (valueArray basicAt:next) notNil ifTrue:[ |
|
121 |
"/ keyArray basicAt:index put:DeletedEntry |
|
358 | 122 |
"/ ] |
95 | 123 |
"/ ]. |
124 |
||
358 | 125 |
valueArray at:index put:nil. |
126 |
tally := tally - 1. |
|
127 |
any := true |
|
128 |
] |
|
129 |
] |
|
10 | 130 |
]. |
358 | 131 |
any ifTrue:[self rehash]. |
132 |
||
359 | 133 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
6 | 134 |
! ! |