Up

NSCountedSet class reference

Authors

Andrew Kachites McCallum (mccallum@gnu.ai.mit.edu)

Version: 35731

Date: 2012-10-22 05:38:47 +0100 (Mon, 22 Oct 2012)

Copyright: (C) 1995, 1996, 1998 Free Software Foundation, Inc.


Contents -

  1. Software documentation for the NSCountedSet class
  2. Software documentation for the NSMutableSet class
  3. Software documentation for the NSSet class
  4. Software documentation for the NSCountedSet(GNU_Uniquing) category

Software documentation for the NSCountedSet class

NSCountedSet : NSMutableSet

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

countForObject: 

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

Software documentation for the NSMutableSet class

NSMutableSet : NSSet

Declared in:
Foundation/NSSet.h
Availability: OpenStep

Mutable version of NSSet .
Method summary

setWithCapacity: 

+ (id) setWithCapacity: (NSUInteger)numItems;
Availability: OpenStep

New autoreleased instance with given capacity.

addObject: 

- (void) addObject: (id)anObject;
Availability: OpenStep

Adds anObject to the set.
The object is retained by the set.

addObjectsFromArray: 

- (void) addObjectsFromArray: (NSArray*)array;
Availability: OpenStep

Adds all the objects in the array to the receiver.

initWithCapacity: 

- (id) initWithCapacity: (NSUInteger)numItems;
Availability: OpenStep

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.

intersectSet: 

- (void) intersectSet: (NSSet*)other;
Availability: OpenStep

Removes from the receiver all the objects it contains which are not also in other.

minusSet: 

- (void) minusSet: (NSSet*)other;
Availability: OpenStep

Removes from the receiver all the objects that are in other.

removeAllObjects 

- (void) removeAllObjects;
Availability: OpenStep

Removes all objects from the receiver.

removeObject: 

- (void) removeObject: (id)anObject;
Availability: OpenStep

Removes the anObject from the receiver.

setSet: 

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

unionSet: 

- (void) unionSet: (NSSet*)other;
Availability: OpenStep

* Adds all the objects from other to the receiver.

Software documentation for the NSSet class

NSSet : NSObject

Declared in:
Foundation/NSSet.h
Conforms to:
NSCoding
NSCopying
NSMutableCopying
NSFastEnumeration
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

set 

+ (id) set;
Availability: OpenStep

New autoreleased empty set.

setWithArray: 

+ (id) setWithArray: (NSArray*)objects;
Availability: OpenStep

New set containing (unique elements of) objects.

setWithObject: 

+ (id) setWithObject: (id)anObject;
Availability: OpenStep

New set containing single object anObject.

setWithObjects: ,...

+ (id) setWithObjects: (id)firstObject,...;
Availability: OpenStep

New set with objects in given nil-terminated list.

setWithObjects: count: 

+ (id) setWithObjects: (const id[])objects count: (NSUInteger)count;
Availability: MacOS-X 10.0.0

New set containing (unique elements of) objects.

setWithSet: 

+ (id) setWithSet: (NSSet*)aSet;
Availability: OpenStep

Copy constructor.

allObjects 

- (NSArray*) allObjects;
Availability: OpenStep

Return array of all objects in set. Order is undefined.

anyObject 

- (id) anyObject;
Availability: OpenStep

Return an arbitrary object from set, or nil if this is empty set.

containsObject: 

- (BOOL) containsObject: (id)anObject;
Availability: OpenStep

Return whether set contains an object equal to this one according to [NSObject -isEqual:] .

count 

- (NSUInteger) count;
Availability: OpenStep

Returns the number of objects stored in the set.

description 

- (NSString*) description;
Availability: OpenStep

Returns listing of objects in set.

descriptionWithLocale: 

- (NSString*) descriptionWithLocale: (id)locale;
Availability: OpenStep

Returns listing of objects in set.

enumerateObjectsUsingBlock: 

- (void) enumerateObjectsUsingBlock: (GSSetEnumeratorBlock)aBlock;
Availability: MacOS-X 10.6.0

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.

enumerateObjectsWithOptions: usingBlock: 

- (void) enumerateObjectsWithOptions: (NSEnumerationOptions)opts usingBlock: (GSSetEnumeratorBlock)aBlock;
Availability: MacOS-X 10.6.0

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.

init 

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


initWithArray: 

- (id) initWithArray: (NSArray*)other;
Availability: OpenStep

Initialises a newly allocated set by adding all the objects in the supplied array to the set.

initWithObjects: ,...

- (id) initWithObjects: (id)firstObject,...;
Availability: OpenStep

Initialize with (unique elements of) objects in given nil-terminated list.

initWithObjects: count: 

- (id) initWithObjects: (const id[])objects count: (NSUInteger)count;
Availability: OpenStep

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.

initWithSet: 

- (id) initWithSet: (NSSet*)other;
Availability: OpenStep

Initialize with same items as other (items not copied).

initWithSet: copyItems: 

- (id) initWithSet: (NSSet*)other copyItems: (BOOL)flag;
Availability: OpenStep

Initialises a newly allocated set by adding all the objects in the supplied set.

intersectsSet: 

- (BOOL) intersectsSet: (NSSet*)otherSet;
Availability: OpenStep

Return whether set intersection with otherSet is non-empty.

isEqualToSet: 

- (BOOL) isEqualToSet: (NSSet*)other;
Availability: OpenStep

Return whether each set is subset of the other.

isSubsetOfSet: 

- (BOOL) isSubsetOfSet: (NSSet*)otherSet;
Availability: OpenStep

Return whether subset of otherSet.

makeObjectsPerform: 

- (void) makeObjectsPerform: (SEL)aSelector;
Availability: OpenStep

Send each object given message (with no arguments). Identical to -makeObjectsPerformSelector: .

makeObjectsPerform: withObject: 

- (void) makeObjectsPerform: (SEL)aSelector withObject: (id)argument;
Availability: OpenStep

Send each object given message with given argument. Identical to -makeObjectsPerformSelector:withObject: .

makeObjectsPerformSelector: 

- (void) makeObjectsPerformSelector: (SEL)aSelector;
Availability: MacOS-X 10.0.0

Send each object given message (with no arguments). Identical to -makeObjectsPerform: .

makeObjectsPerformSelector: withObject: 

- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: (id)argument;
Availability: MacOS-X 10.0.0

Send each object given message with given argument. Identical to -makeObjectsPerform:withObject: .

member: 

- (id) member: (id)anObject;
Availability: OpenStep

If anObject is in set, return it (the copy in the set).

objectEnumerator 

- (NSEnumerator*) objectEnumerator;
Availability: OpenStep

Return enumerator over objects in set. Order is undefined.

objectsPassingTest: 

- (NSSet*) objectsPassingTest: (GSSetFilterBlock)aBlock;
Availability: MacOS-X 10.6.0

Description forthcoming.

objectsWithOptions: passingTest: 

- (NSSet*) objectsWithOptions: (NSEnumerationOptions)opts passingTest: (GSSetFilterBlock)aBlock;
Availability: MacOS-X 10.6.0

Description forthcoming.

setByAddingObject: 

- (NSSet*) setByAddingObject: (id)anObject;
Availability: MacOS-X 10.5.0

Return a set formed by adding anObject to the receiver.

setByAddingObjectsFromArray: 

- (NSSet*) setByAddingObjectsFromArray: (NSArray*)other;
Availability: MacOS-X 10.5.0

Return a set formed by adding the contents of other to the receiver.

setByAddingObjectsFromSet: 

- (NSSet*) setByAddingObjectsFromSet: (NSSet*)other;
Availability: MacOS-X 10.5.0

Return a set formed as a union of the receiver and other.

Software documentation for the NSCountedSet(GNU_Uniquing) category

NSCountedSet(GNU_Uniquing)

Declared in:
Foundation/NSSet.h
Availability: Not in OpenStep/MacOS-X

Utility methods for using a counted set to handle uniquing of objects.
Method summary

purge: 

- (void) purge: (NSInteger)level;
Availability: Not in OpenStep/MacOS-X

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.


unique: 

- (id) unique: (id)anObject;
Availability: Not in OpenStep/MacOS-X

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