The NSCountedSet class is used to maintain
a set of objects where the number of times each object
has been added (without a corresponding removal) is
kept track of.
In GNUstep, the purge and
unique methods are provided to make use
of a counted set for uniquing objects easier.
Returns the number of times that an object that is
equal to the specified object (as determined by the
[NSObject -isEqual:]
method) has been added to the set and not removed
from it.
This is a designated initialiser for the class.
Subclasses must override this method.
Initialises a newly allocated set to contain no
objects but to have space available to hold the
specified number of items. Additions of
items to a set initialised with an appropriate
capacity will be more efficient than addition of
items otherwise. Calls
-init
(which does nothing but maintain MacOS-X
compatibility), and needs to be
re-implemented in subclasses in order to
have all other initialisers work.
NSSet maintains an unordered collection
of unique objects (according to
[NSObject -isEqual:]
). When a duplicate object is added to the set, it
replaces its old copy.
Enumerate over the collection using a given
block. The first argument is the object. The second
argument is a pointer to a BOOL indicating whether
the enumeration should stop. Setting this to
YES will interupt the enumeration.
Enumerate over the collection using the given
block. The first argument is the object. The second
argument is a pointer to a BOOL indicating whether
the enumeration should stop. Setting this to
YES will interrupt the enumeration. The
opts argument is a bitfield. Setting the
NSNSEnumerationConcurrent flag
specifies that it is thread-safe. The
NSEnumerationReverse bit specifies
that it should be enumerated in reverse order.
In MacOS-X class clusters do not have designated
initialisers, and there is a general rule
that -init
is
treated as the designated initialiser of the
class cluster, but that other intitialisers may not
work s expected an would need to be individually
overridden in any subclass.
GNUstep tries to make it easier to subclass a
class cluster, by making class clusters follow the
same convention as normal classes, so the designated
initialiser is the richest
initialiser. This means that all other
initialisers call the documented designated
initialiser (which calls
-init
only for MacOS-X compatibility), and anyone writing
a subclass only needs to override that one initialiser
in order to have all the other ones work.
For MacOS-X compatibility, you may also need to
override various other initialisers. Exactly
which ones, you will need to determine by trial on
a MacOS-X system... and may vary between releases of
MacOS-X. So to be safe, on MacOS-X you probably
need to re-implement all the class cluster
initialisers you might use in conjunction
with your subclass.
This is a designated initialiser for the class.
Subclasses must override this method.
Initialize to contain (unique elements of)
objects. Calls
-init
(which does nothing but maintain MacOS-X
compatibility), and needs to be
re-implemented in subclasses in order to
have all other initialisers work.
This method removes from the set all objects whose
count is less than or equal to the specified value.
This is useful where a counted set is used for
uniquing objects. The set can be periodically
purged of objects that have only been added once -
and are therefore simply wasting space.
If the supplied object (or one equal to it as
determined by the
[NSObject -isEqual:]
method) is already present in the set, the count
for that object is incremented, the supplied object
is released, and the object in the set is retained and
returned. Otherwise, the supplied object is
added to the set and returned.
This method is useful for uniquing objects - the
init method of a class need simply end with -
return [myUniquingSet unique: self];