Collections-Weak

WeakArray
WeakArray is an array which holds only weakly on its elements. This means whenever an object is only referenced by instances of WeakArray it will be garbage collected.
addWeakDependent:
finalizationProcess
initialize
Subclasses should redefine this method to perform initializations on instance creation
isFinalizationSupported
pvtCreateTemporaryObjectIn:
removeWeakDependent:
restartFinalizationProcess
runningFinalizationProcess
startUp:
WeakIdentityKeyDictionary
This class represents an identity dictionary with weak keys.
scanFor:
ar 10/21/2000: The method has been copied to this location to indicate that whenever #scanFor: changes #scanForNil: must be changed in the receiver as well.
scanForNil:
Private. Scan the key array for the first slot containing nil (indicating an empty slot). Answer the index of that slot.
WeakKeyDictionary
I am a dictionary holding only weakly on my keys. This is a bit dangerous since at any time my keys can go away. Clients are responsible to register my instances by WeakArray such that the appropriate actions can be taken upon loss of any keys.
See WeakRegistry for an example of use.
add:
Include newObject as one of the receiver's elements, but only if
not already present. Answer newObject.
at:put:
Set the value at key to be anObject. If key is not found, create a new
entry for key and set is value to anObject. Answer anObject.
finalizeValues
remove all nil keys and rehash the receiver afterwards
finalizeValues:
Remove all associations with key == nil and value is in finiObjects.
This method is folded with #rehash for efficiency.
fixCollisionsFrom:
The element at index has been removed and replaced by nil.
keysDo:
Evaluate aBlock for each of the receiver's keys.
rehash
Rehash the receiver. Reimplemented to allow for multiple nil keys
scanFor:
ar 10/21/2000: The method has been copied to this location to indicate that whenever #scanFor: changes #scanForNil: must be changed in the receiver as well.
scanForNil:
Private. Scan the key array for the first slot containing nil (indicating an empty slot). Answer the index of that slot.
WeakKeyToCollectionDictionary
This class represents an identity dictionary with weak keys, whose values are collections.
Keys not in the dictionary are mapped to the empty collection. Conversely, if a collection becomes empty, the mapping can be removed to save time and space. However, because this requires re-hashing, it does not pay to do this to eagerly.
finalizeValues
remove all nil keys and rehash the receiver afterwards
rehash
Rehash the receiver. Reimplemented to remove nils from the collections
that appear as values, and to entirely remove associations with empty collections
as values.
WeakRegistry
I am a registry for objects needing finalization. When an object is added the object as well as its executor is stored. When the object is garbage collected, the executor can take the appropriate action for any resources associated with the object.
See also:
Object executor
Object actAsExecutor
Object finalize
add:
Add anObject to the receiver. Store the object as well as the associated executor.
add:executor:
Add anObject to the receiver. Store the object as well as the associated executor.
default
do:
Evaluate aBlock with each of the receiver's elements as the argument.
finalizeValues
Some of our elements may have gone away. Look for those and activate the associated executors.
initialize:
keys
new
new:
printElementsOn:
The original code used #skip:, but some streams do not support that,
and we don't really need it.
protected:
Execute aBlock protected by the accessLock
remove:ifAbsent:
Remove oldObject as one of the receiver's elements.
removeAll
See super
size
Answer how many elements the receiver contains.
species
Answer the preferred class for reconstructing the receiver. For example,
collections create new collections whenever enumeration messages such as
collect: or select: are invoked. The new kind of collection is determined by
the species of the original collection. Species and class are not always the
same. For example, the species of Interval is Array.
WeakSet
A WeakSet is xxxxxxxxx.
Instance Variables
flag: <Object>
flag
- xxxxx
add:
Include newObject as one of the receiver's elements, but only if
not already present. Answer newObject
collect:
Evaluate aBlock with each of the receiver's elements as the argument.
Collect the resulting values into a collection like the receiver. Answer
the new collection.
do:
Evaluate aBlock with each of the receiver's elements as the argument.
do:after:
fixCollisionsFrom:
The element at index has been removed and replaced by nil.
This method moves forward from there, relocating any entries
that had been placed below due to collisions with this one
grow
Grow the elements array if needed.
Since WeakSets just nil their slots, alot of the occupied (in the eyes of the set) slots are usually empty. Doubling size if unneeded can lead to BAD performance, therefore we see if reassigning the <live> elements to a Set of similiar size leads to a sufficiently (50% used here) empty set first.
and reinsert the old elements
growTo:
Grow the elements array and reinsert the old elements
includes:
Answer whether anObject is one of the receiver's elements.
initialize:
Initialize array to an array size of n
inspectorClass
Answer the class of the inspector to be used on the receiver. Called by inspect;
use basicInspect to get a normal (less useful) type of inspector.
like:
Answer an object in the receiver that is equal to anObject,
nil if no such object is found. Relies heavily on hash properties
printElementsOn:
The original code used #skip:, but some streams do not support that,
and we don't really need it.
rehash
Do nothing. Here so sending this to a Set does not have to do a time consuming respondsTo:
remove:ifAbsent:
Remove oldObject from the receiver's elements. If several of the
elements are equal to oldObject, only one is removed. If no element is
equal to oldObject, answer the result of evaluating anExceptionBlock.
Otherwise, answer the argument, oldObject. ArrayedCollections cannot
respond to this message.
scanFor:
Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or zero if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements
scanForLoadedSymbol:
Scan the key array for the first slot containing either a nil (indicating an empty slot) or an element that matches anObject. Answer the index of that slot or zero if no slot is found. This method will be overridden in various subclasses that have different interpretations for matching elements
size
Careful! Answer the maximum amount
of elements in the receiver, not the
exact amount
slowSize
Careful! Answer the maximum amount
of elements in the receiver, not the
exact amount
WeakValueDictionary
I am a dictionary holding only weakly on my values. Clients may expect to get a nil value for any object they request.
add:
Include newObject as one of the receiver's elements, but only if
not already present. Answer newObject.
at:put:
Set the value at key to be anObject. If key is not found, create a new
entry for key and set is value to anObject. Answer anObject.