Up
Authors
- Andrew Kachites McCallum (
mccallum@gnu.ai.mit.edu
)
-
Version: 1.59
Date: 2005/07/08 11:48:35
Copyright: (C) 1995, 1996, 1998 Free Software Foundation, Inc.
- Declared in:
- Foundation/NSSet.h
Availability: OpenStep
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.
Method summary
- (unsigned int)
countForObject: (id)anObject;
Availability: OpenStep
Returns the number of times that an object that is equal to the specified object (as determined by the
[-isEqual:]
method) has been added to the set and not removed from it.
- Declared in:
- Foundation/NSSet.h
Availability: OpenStep
Mutable version of
NSSet
.
Method summary
+ (id)
setWithCapacity: (unsigned)numItems;
Availability: OpenStep
New autoreleased instance with given capacity.
- (void)
addObject: (id)anObject;
Availability: OpenStep
Adds anObject to the set.
The object is retained by the set.
- (void)
addObjectsFromArray: (
NSArray*)array;
Availability: OpenStep
Adds all the objects in the array to the receiver.
- (id)
initWithCapacity: (unsigned)numItems;
Availability: OpenStep
This is a designated initialiser for the class.
Subclasses
should 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.
- (void)
intersectSet: (
NSSet*)other;
Availability: OpenStep
Removes from the receiver all the objects it contains which are not also in other.
- (void)
minusSet: (
NSSet*)other;
Availability: OpenStep
Removes from the receiver all the objects that are in other.
- (void)
removeAllObjects;
Availability: OpenStep
Removes all objects from the receiver.
- (void)
removeObject: (id)anObject;
Availability: OpenStep
Removes the anObject from the receiver.
- (void)
setSet: (
NSSet*)other;
Availability: MacOS-X 10.0.0
Removes all objects from the receiver then adds the objects from other. If the receiver is other, the method has no effect.
- (void)
unionSet: (
NSSet*)other;
Availability: OpenStep
* Adds all the objects from other to the receiver.
- Declared in:
- Foundation/NSSet.h
- Conforms to:
- NSCoding
- NSCopying
- NSMutableCopying
Availability: OpenStep
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.
Method summary
+ (id)
set;
Availability: OpenStep
New autoreleased empty set.
+ (id)
setWithArray: (
NSArray*)objects;
Availability: OpenStep
New set containing (unique elements of) objects.
+ (id)
setWithObject: (id)anObject;
Availability: OpenStep
New set containing single object anObject.
+ (id)
setWithObjects: (id)firstObject
,...;
Availability: OpenStep
New set with objects in given nil-terminated list.
+ (id)
setWithObjects: (id*)objects
count: (unsigned)count;
Availability: MacOS-X 10.0.0
New set containing (unique elements of) objects.
+ (id)
setWithSet: (
NSSet*)aSet;
Availability: OpenStep
Copy constructor.
- (
NSArray*)
allObjects;
Availability: OpenStep
Return array of all objects in set. Order is undefined.
- (id)
anyObject;
Availability: OpenStep
Return an arbitrary object from set, or nil
if this is empty set.
- (BOOL)
containsObject: (id)anObject;
Availability: OpenStep
- (unsigned)
count;
Availability: OpenStep
Returns the number of objects stored in the set.
- (
NSString*)
description;
Availability: OpenStep
Returns listing of objects in set.
- (
NSString*)
descriptionWithLocale: (
NSDictionary*)locale;
Availability: OpenStep
Returns listing of objects in set.
- (id)
init;
Availability: OpenStep
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.
- (id)
initWithArray: (
NSArray*)other;
Availability: OpenStep
Initialises a newly allocated set by adding all the objects in the supplied array to the set.
- (id)
initWithObjects: (id)firstObject
,...;
Availability: OpenStep
Initialize with (unique elements of) objects in given nil-terminated list.
- (id)
initWithObjects: (id*)objects
count: (unsigned)count;
Availability: OpenStep
This is a designated initialiser for the class.
Subclasses
should 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.
- (id)
initWithSet: (
NSSet*)other;
Availability: OpenStep
Initialize with same items as other (items not copied).
- (id)
initWithSet: (
NSSet*)other
copyItems: (BOOL)flag;
Availability: OpenStep
Initialises a newly allocated set by adding all the objects in the supplied set.
- (BOOL)
intersectsSet: (
NSSet*)otherSet;
Availability: OpenStep
Return whether set intersection with otherSet is non-empty.
- (BOOL)
isEqualToSet: (
NSSet*)other;
Availability: OpenStep
Return whether each set is subset of the other.
- (BOOL)
isSubsetOfSet: (
NSSet*)otherSet;
Availability: OpenStep
Return whether subset of otherSet.
- (void)
makeObjectsPerform: (SEL)aSelector;
Availability: OpenStep
- (void)
makeObjectsPerform: (SEL)aSelector
withObject: (id)argument;
Availability: OpenStep
- (void)
makeObjectsPerformSelector: (SEL)aSelector;
Availability: MacOS-X 10.0.0
- (void)
makeObjectsPerformSelector: (SEL)aSelector
withObject: (id)argument;
Availability: MacOS-X 10.0.0
- (id)
member: (id)anObject;
Availability: OpenStep
If anObject is in set, return it (the copy in the set).
- (
NSEnumerator*)
objectEnumerator;
Availability: OpenStep
Return enumerator over objects in set. Order is undefined.
- Declared in:
- Foundation/NSSet.h
Availability: Base 0.0.0
Utility methods for using a counted set to handle uniquing of objects.
Method summary
- (void)
purge: (int)level;
Availability: Base 0.0.0
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.
- (id)
unique: (id)anObject;
Availability: Base 0.0.0
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];
Up