94
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
187
|
3 |
All Rights Reserved
|
94
|
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 |
IdentitySet subclass:#WeakIdentitySet
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
159
|
17 |
category:'Collections-Unordered'
|
94
|
18 |
!
|
|
19 |
|
|
20 |
WeakIdentitySet comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
187
|
22 |
All Rights Reserved
|
94
|
23 |
|
252
|
24 |
$Header: /cvs/stx/stx/libbasic/Attic/WeakIdSet.st,v 1.6 1995-02-15 10:25:16 claus Exp $
|
94
|
25 |
'!
|
|
26 |
|
|
27 |
!WeakIdentitySet class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
187
|
32 |
All Rights Reserved
|
94
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
252
|
45 |
$Header: /cvs/stx/stx/libbasic/Attic/WeakIdSet.st,v 1.6 1995-02-15 10:25:16 claus Exp $
|
94
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this is a special class to support dependencies which do not
|
|
52 |
prevent objects from dying.
|
|
53 |
"
|
|
54 |
! !
|
|
55 |
|
111
|
56 |
!WeakIdentitySet class methodsFor:'instance creation'!
|
|
57 |
|
|
58 |
new
|
|
59 |
"return a new empty Set"
|
|
60 |
|
|
61 |
^ self new:1
|
|
62 |
! !
|
|
63 |
|
252
|
64 |
!WeakIdentitySet class methodsFor:'queries'!
|
94
|
65 |
|
252
|
66 |
goodSizeFrom:arg
|
111
|
67 |
"return a good array size for the given argument.
|
|
68 |
Since WeakIdentitySets are mostly used for dependency management, we typically
|
|
69 |
have only one element in the set. Therefore use exact size for small sets
|
|
70 |
(instead of rounding up to the prime 11)."
|
|
71 |
|
187
|
72 |
arg <= 10 ifTrue:[
|
|
73 |
arg < 1 ifTrue:[^ 1].
|
|
74 |
^ arg.
|
|
75 |
].
|
252
|
76 |
^ super goodSizeFrom:arg
|
|
77 |
! !
|
|
78 |
|
|
79 |
!WeakIdentitySet methodsFor:'private'!
|
111
|
80 |
|
94
|
81 |
keyContainerOfSize:n
|
|
82 |
"return a container for keys and values of size n.
|
|
83 |
use WeakArrays here."
|
|
84 |
|
|
85 |
|w|
|
|
86 |
|
|
87 |
w := WeakArray new:n.
|
|
88 |
w watcher:self.
|
|
89 |
^ w
|
|
90 |
! !
|
|
91 |
|
216
|
92 |
!WeakIdentitySet methodsFor:'enumerating'!
|
|
93 |
|
|
94 |
do:aBlock
|
|
95 |
"perform the block for all members in the collection.
|
|
96 |
This method has been rewritten to be more robust about
|
|
97 |
changed contents while enumerating elements (which might
|
|
98 |
happen during change&update processing, if dependents
|
|
99 |
are added or removed within the update."
|
|
100 |
|
|
101 |
|index "{ Class: SmallInteger }"
|
|
102 |
element|
|
|
103 |
|
|
104 |
index := 1.
|
|
105 |
[index <= keyArray size] whileTrue:[
|
|
106 |
element := keyArray at:index.
|
|
107 |
(element notNil and:[element ~~ DeletedEntry]) ifTrue:[
|
|
108 |
aBlock value:element
|
|
109 |
].
|
|
110 |
index := index + 1
|
|
111 |
]
|
|
112 |
! !
|
|
113 |
|
94
|
114 |
!WeakIdentitySet methodsFor:'element disposal'!
|
|
115 |
|
|
116 |
informDispose
|
|
117 |
"an element died - must rehash"
|
|
118 |
|
|
119 |
self rehash
|
|
120 |
! !
|