mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 18:21:04 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9698 72102866-910b-0410-8b05-ffd578937521
213 lines
7 KiB
HTML
213 lines
7 KiB
HTML
<html><head>
|
|
<title>NSCountedSet</title>
|
|
</head>
|
|
<body>
|
|
<a href ="NSConnection.html">[Previous] </a>
|
|
<a href ="Base.html">[Up] </a>
|
|
<a href ="NSDate.html">[Next] </a>
|
|
<h1>NSCountedSet</h1>
|
|
<h3>Authors </h3>
|
|
<dl>
|
|
<dt><a href ="http://www.gnustep.org/developers/whoiswho.html">Richard Frith-Macdonald</a>
|
|
<dd>
|
|
</dl>
|
|
<p>Version: $Revision$</p>
|
|
<p>Date: $Date$</p>
|
|
<h2><a name ="cont-0">NSCountedSet</a></h2>
|
|
<h2><a name ="NSCountedSet">NSCountedSet</a></h2>
|
|
<p><b>Declared in: </b> Foundation/NSSet.h</p>
|
|
<p><b>Inherits from: </b> NSMutableSet</p>
|
|
<p><b>Conforms to: </b> NSCoding
|
|
</p>
|
|
<hr>
|
|
|
|
<p>
|
|
|
|
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.
|
|
</p>
|
|
|
|
<p>
|
|
|
|
In GNUstep, extra methods are provided to make use of a counted
|
|
set for <em>uniquing</em> objects easier.
|
|
</p>
|
|
|
|
|
|
<h2>Instance Variables </h2>
|
|
<ul>
|
|
</ul>
|
|
<h2>Methods </h2>
|
|
<ul>
|
|
<li ><a href ="NSCountedSet.html#method-0">-addObject:</a>
|
|
<li ><a href ="NSCountedSet.html#method-1">-allObjects</a>
|
|
<li ><a href ="NSCountedSet.html#method-2">-count</a>
|
|
<li ><a href ="NSCountedSet.html#method-3">-countForObject:</a>
|
|
<li ><a href ="NSCountedSet.html#method-4">-initWithArray:</a>
|
|
<li ><a href ="NSCountedSet.html#method-5">-initWithCapacity:</a>
|
|
<li ><a href ="NSCountedSet.html#method-6">-initWithSet:</a>
|
|
<li ><a href ="NSCountedSet.html#method-7">-objectEnumerator</a>
|
|
<li ><a href ="NSCountedSet.html#method-8">-purge:</a>
|
|
<li ><a href ="NSCountedSet.html#method-9">-removeObject:</a>
|
|
<li ><a href ="NSCountedSet.html#method-10">-unique:</a>
|
|
</ul>
|
|
<hr><h2>Instances Methods </h2>
|
|
<h3><a name ="method-0">addObject:</a></h3>
|
|
- (void) <b>addObject:</b> (id)anObject;<br>
|
|
|
|
Adds an object to the set. If the set already contains an object
|
|
equal to the specified object (as determined by the [-isEqual:]
|
|
method) then the count for that object is incremented rather
|
|
than the new object being added.
|
|
|
|
<hr>
|
|
<h3><a name ="method-1">allObjects</a></h3>
|
|
- (NSArray*) <b>allObjects</b>;<br>
|
|
|
|
Returns an array containing all the objects stored in the set.
|
|
|
|
<hr>
|
|
<h3><a name ="method-2">count</a></h3>
|
|
- (unsigned int) <b>count</b>;<br>
|
|
|
|
Returns the number of objects stored in the set.
|
|
|
|
<hr>
|
|
<h3><a name ="method-3">countForObject:</a></h3>
|
|
- (unsigned int) <b>countForObject:</b> (id)anObject;<br>
|
|
|
|
Returns the number of times that an object that is equal to the
|
|
specified object (as determined byt the [-isEqual:] method) has
|
|
been added to the set and not removed from it.
|
|
|
|
<hr>
|
|
<h3><a name ="method-4">initWithArray:</a></h3>
|
|
- (id) <b>initWithArray:</b> (NSArray*)anArray;<br>
|
|
|
|
Initialises a newly allocated set by adding all the objects
|
|
in the supplied array to the set. Each object is added to
|
|
the set as many times as it occurs in the array.
|
|
|
|
<hr>
|
|
<h3><a name ="method-5">initWithCapacity:</a></h3>
|
|
- (id) <b>initWithCapacity:</b> (unsigned int)numItems;<br>
|
|
|
|
Initialises a newly allocated set to contain no objects but
|
|
to have space available to hold the specified number of items.
|
|
|
|
<hr>
|
|
<h3><a name ="method-6">initWithSet:</a></h3>
|
|
- (id) <b>initWithSet:</b> (NSSet*)aSet;<br>
|
|
|
|
Initialises a newly allocated set by adding all the objects
|
|
in the supplied set.
|
|
|
|
<hr>
|
|
<h3><a name ="method-7">objectEnumerator</a></h3>
|
|
- (NSEnumerator*) <b>objectEnumerator</b>;<br>
|
|
|
|
Returns an NSEnumerator object able to step through all the
|
|
objects in the set.
|
|
|
|
<hr>
|
|
<h3><a name ="method-8">purge:</a></h3>
|
|
- (void) <b>purge:</b> (int)count;<br>
|
|
Standards: NotOpenStep NotMacOS-X<br>
|
|
|
|
<p>
|
|
|
|
This method removes from the set all objects whose count is
|
|
less than or equal to the specified value.
|
|
</p>
|
|
|
|
<p>
|
|
|
|
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.
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h3><a name ="method-9">removeObject:</a></h3>
|
|
- (void) <b>removeObject:</b> (id)anObject;<br>
|
|
|
|
Decrements the count of the number of times that the specified
|
|
object (or an object qequal to it as determined by the
|
|
[-isEqual:] method) has been added to the set. If the count
|
|
becomes zero, the object is removed from the set.
|
|
|
|
<hr>
|
|
<h3><a name ="method-10">unique:</a></h3>
|
|
- (id) <b>unique:</b> (id)anObject;<br>
|
|
Standards: NotOpenStep NotMacOS-X<br>
|
|
|
|
<p>
|
|
|
|
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.
|
|
</p>
|
|
|
|
<p>
|
|
|
|
This method is useful for uniquing objects - the init method of
|
|
a class need simply end with -
|
|
<code>
|
|
return [myUniquingSet unique: self];
|
|
</code>
|
|
</p>
|
|
|
|
|
|
<hr>
|
|
<h2><a name ="cont-1">NSCountedSet related functions</a></h2>
|
|
<p>
|
|
|
|
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.
|
|
</p>
|
|
<h2><a name ="function-11">GSUniquing</a></h2>
|
|
<b>Prototype: </b> void GSUniquing(BOOL flag)<br>
|
|
|
|
This function sets the state of a flag that determines the
|
|
behavior of the GSUnique() function. If the flag is on,
|
|
uniquing is performed, if it is off the function has no effect.
|
|
The default is for uniquing to be turned off.
|
|
|
|
<hr>
|
|
<h2><a name ="function-12">GSUnique</a></h2>
|
|
<b>Prototype: </b> id GSUnique(id anObject)<br>
|
|
|
|
This function <em>uniques</em> the supplied argument, returning
|
|
the result. It works by using the [-unique:] method of a global
|
|
NSCountedSet object. It handles locking as necessary.
|
|
If uniquing is turned off, it simply returns its argument.
|
|
|
|
<hr>
|
|
<h2><a name ="function-13">GSUPurge</a></h2>
|
|
<b>Prototype: </b> void GSUPurge(unsigned int count)<br>
|
|
|
|
This function purges the global NSCountedSet object used for
|
|
uniquing. It handles locking as necessary. It can be used to
|
|
purge the set even when uniquing is turned off.
|
|
|
|
<hr>
|
|
<h2><a name ="function-14">GSUSet</a></h2>
|
|
<b>Prototype: </b> id GSUSet(id anObject, unsigned int count)<br>
|
|
|
|
This function sets the count for the specified object. If the
|
|
count for the object is set to zero then the object is removed
|
|
from the global uniquing set. The object is added to the set
|
|
if necessary. The object returned is the one stored in the set.
|
|
The function handles locking as necessary. It can be used to
|
|
alter the set even when uniquing is turned off.
|
|
|
|
<hr>
|
|
</body>
|
|
|
|
</html>
|