6
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1992 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 |
IdentityDictionary subclass:#WeakIdentityDictionary
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
WeakIdentityDictionary comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
63
|
25 |
$Header: /cvs/stx/stx/libbasic/WeakIdentityDictionary.st,v 1.3 1994-02-25 13:07:07 claus Exp $
|
6
|
26 |
|
|
27 |
written dec 92 by claus
|
|
28 |
'!
|
|
29 |
|
10
|
30 |
!WeakIdentityDictionary class methodsFor:'documentation'!
|
|
31 |
|
|
32 |
documentation
|
|
33 |
"
|
|
34 |
this is a special class to support keeping track of dependents without
|
|
35 |
keeping the values alive - values simply become nil when no one else
|
|
36 |
references it. The original dependency mechanism used a regular Dictionary,
|
63
|
37 |
which usually leads to a lot of garbage being kept due to a forgotten
|
10
|
38 |
release. Using a WeakDictionary may be incompatible to ST-80 but is much
|
|
39 |
more comfortable.
|
|
40 |
"
|
|
41 |
! !
|
|
42 |
|
6
|
43 |
!WeakIdentityDictionary methodsFor:'private'!
|
|
44 |
|
10
|
45 |
keyContainerOfSize:n
|
|
46 |
"return a container for keys and values of size n.
|
|
47 |
use WeakArrays here."
|
|
48 |
|
|
49 |
|w|
|
|
50 |
|
|
51 |
w := WeakArray new:n.
|
|
52 |
w watcher:self.
|
|
53 |
^ w
|
|
54 |
! !
|
|
55 |
|
|
56 |
!WeakIdentityDictionary methodsFor:'element disposal'!
|
|
57 |
|
|
58 |
informDispose
|
|
59 |
"an element (either key or value) died - rehash"
|
6
|
60 |
|
10
|
61 |
| sz "{ Class:SmallInteger }"
|
|
62 |
any |
|
|
63 |
|
|
64 |
sz := keyArray size.
|
|
65 |
any := false.
|
|
66 |
1 to:sz do:[:index |
|
|
67 |
(keyArray at:index) isNil ifTrue:[
|
|
68 |
(valueArray at:index) notNil ifTrue:[
|
|
69 |
valueArray at:index put:nil.
|
|
70 |
tally := tally - 1.
|
|
71 |
any := true
|
|
72 |
]
|
|
73 |
]
|
|
74 |
].
|
|
75 |
any ifTrue:[self rehash]
|
6
|
76 |
! !
|