eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'WeakIdentitySet':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: WeakIdentitySet


Inheritance:

   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

Description:


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).


Warning:


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.

Related information:

    WeakArray
    WeakIdentityDictionary

Class protocol:

instance creation
o  new
return a new empty WeakIdentitySet

queries
o  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).


Instance protocol:

accessing
o  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
o  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)

o  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
o  update: something with: aParameter from: changedObject
an element died - must rehash

enumerating
o  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
o  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.

o  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

o  isWeakCollection
return true, if the receiver has weak references to its elements.

o  keyContainerOfSize: n
return a container for keys and values of size n.
use WeakArrays here.



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 25 Apr 2024 04:09:11 GMT