|
Class: WeakIdentitySet
Object
|
+--Collection
|
+--Set
|
+--IdentitySet
|
+--WeakIdentitySet
- Package:
- stx:libbasic
- Category:
- Collections-Weak
- Version:
- rev:
1.45
date: 2019/02/12 19:46:53
- user: stefan
- file: WeakIdentitySet.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
WeakIdentitySets behave like IdentitySets, as long as the contained
objects are still referenced by some other (non-weak) object.
However, once the last non-weak reference ceases to exist,
the object will be automatically removed from the Weakcollection
(with some delay: it will be removed after the next garbage collect).
This class was added to support dependencies which do not
prevent objects from dying. (i.e. which do not fill up your memory
if you forget to #release it).
If you use this, be very careful since the collections size changes
'magically' - for example, testing for being nonEmpty and then
removing the first element may fail, since the element may vanish inbetween.
In general, never trust the value as returned by the size/isEmpty messages.
WeakIdentitySet is not meant as a 'public' class.
WeakArray
WeakIdentityDictionary
instance creation
-
new
-
return a new empty WeakIdentitySet
queries
-
goodSizeFrom: arg
-
return a good array size for the given argument.
Since WeakIdentitySets are mostly used for dependency management, we typically
have only a small number of elements in the set.
Therefore use exact size for small sets
(instead of rounding up to the next prime 11).
accessing
-
firstIfEmpty: exceptionValue
-
return the first element of the collection or the
value of the exceptionBlock, if empty.
Redefine, since the inherited method does not work if
elements change silently to nil
adding & removing
-
add: newElement
-
add the argument, newElement to the receiver.
Returns the argument, newElement (sigh).
Redefined to avoid synchronization problems, in case of interrupts
(otherwise, there could be some other operation on the receiver
done by another process, which garbles my contents)
-
remove: anObject ifAbsent: exceptionBlock
-
redefined to avoid synchronization problems, in case of interrupts
(otherwise, there could be some other operation on the receiver
done by another process, which garbles my contents)
element disposal
-
update: something with: aParameter from: changedObject
-
an element died - must rehash
enumerating
-
do: aBlock
-
perform the block for all members in the collection.
This method has been rewritten to be more robust about
changed contents while enumerating elements (which might
happen during change&update processing, if dependents
are added or removed within the update).
private
-
findKeyOrNil: key
-
Look for the key in the receiver.
If it is found, return return the index, otherwise
the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present.
Warning: an empty slot MUST be filled by the sender - it is only to be sent
by at:put: / add: - like methods.
-
findKeyOrNilOrDeletedEntry: key
-
Look for the key in the receiver.
If it is found, return return the index, otherwise
the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present
-
isWeakCollection
-
return true, if the receiver has weak references to its elements.
-
keyContainerOfSize: n
-
return a container for keys and values of size n.
use WeakArrays here.
|