The NSCountedSet class is used to maintain a set of objects where the number of times each object has been added (wiithout a corresponding removal) is kept track of.
In GNUstep, extra methods are provided to make use of a counted set for uniquing objects easier.
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 [-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];
GNUstep provides some functions that may be using to maintain a global NSCountedSet object for usin in uniquing objects. In a multi-threaded application, accesses to this global set are automatically protected by locks.