Up

NSCountedSet class reference

Authors

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

Date: Generated at 2023-12-20 19:35:39 -0500

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: (GS_GENERIC_TYPE(ElementT))anObject;
Availability: OpenStep

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.

Software documentation for the NSMutableSet class

NSMutableSet : NSSet

Declared in:
Foundation/NSSet.h
Availability: OpenStep

Mutable version of NSSet .
Method summary

setWithCapacity: 

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

New autoreleased instance with given capacity.

addObject: 

- (void) addObject: (GS_GENERIC_TYPE(ElementT))anObject;
Availability: OpenStep

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

addObjectsFromArray: 

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

Adds all the objects in the array to the receiver.

initWithCapacity: 

- (instancetype) 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: (GS_GENERIC_CLASS(NSSet,ElementT)*)other;
Availability: OpenStep

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

minusSet: 

- (void) minusSet: (GS_GENERIC_CLASS(NSSet,ElementT)*)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: (GS_GENERIC_TYPE(ElementT))anObject;
Availability: OpenStep

Removes the anObject from the receiver.

setSet: 

- (void) setSet: (GS_GENERIC_CLASS(NSSet,ElementT)*)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: (GS_GENERIC_CLASS(NSSet,ElementT)*)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 

+ (instancetype) set;
Availability: OpenStep

New autoreleased empty set.

setWithArray: 

+ (instancetype) setWithArray: (GS_GENERIC_CLASS(NSArray,ElementT)*)objects;
Availability: OpenStep

New set containing (unique elements of) objects.

setWithObject: 

+ (instancetype) setWithObject: (GS_GENERIC_TYPE(ElementT))anObject;
Availability: OpenStep

New set containing single object anObject.

setWithObjects: ,...

+ (instancetype) setWithObjects: (GS_GENERIC_TYPE(ElementT))firstObject,...;
Availability: OpenStep

New set with objects in given nil-terminated list.

setWithObjects: count: 

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

New set containing (unique elements of) objects.

setWithSet: 

+ (instancetype) setWithSet: (GS_GENERIC_CLASS(NSSet,ElementT)*)aSet;
Availability: OpenStep

Copy constructor.

allObjects 

- (GS_GENERIC_CLASS(NSArray,ElementT)*) allObjects;
Availability: OpenStep

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

anyObject 

- (GS_GENERIC_TYPE(ElementT)) anyObject;
Availability: OpenStep

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

containsObject: 

- (BOOL) containsObject: (GS_GENERIC_TYPE(ElementT))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 

- (instancetype) 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: 

- (instancetype) initWithArray: (GS_GENERIC_CLASS(NSArray,ElementT)*)other;
Availability: OpenStep

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

initWithObjects: ,...

- (instancetype) initWithObjects: (GS_GENERIC_TYPE(ElementT))firstObject,...;
Availability: OpenStep

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

initWithObjects: count: 

- (instancetype) initWithObjects: (const GS_GENERIC_TYPE(ElementT)[])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: 

- (instancetype) initWithSet: (GS_GENERIC_CLASS(NSSet,ElementT)*)other;
Availability: OpenStep

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

initWithSet: copyItems: 

- (instancetype) initWithSet: (GS_GENERIC_CLASS(NSSet,ElementT)*)other copyItems: (BOOL)flag;
Availability: OpenStep

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

intersectsSet: 

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

Return whether set intersection with otherSet is non-empty.

isEqualToSet: 

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

Return whether each set is subset of the other.

isSubsetOfSet: 

- (BOOL) isSubsetOfSet: (GS_GENERIC_CLASS(NSSet,ElementT)*)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: 

- (GS_GENERIC_TYPE(ElementT)) member: (GS_GENERIC_TYPE(ElementT))anObject;
Availability: OpenStep

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

objectEnumerator 

- (GS_GENERIC_CLASS(NSEnumerator,ElementT)*) objectEnumerator;
Availability: OpenStep

Return enumerator over objects in set. Order is undefined.

objectsPassingTest: 

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

Description forthcoming.

objectsWithOptions: passingTest: 

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

Description forthcoming.

setByAddingObject: 

- (GS_GENERIC_CLASS(NSSet,ElementT)*) setByAddingObject: (GS_GENERIC_TYPE(ElementT))anObject;
Availability: MacOS-X 10.5.0

Return a set formed by adding anObject to the receiver.

setByAddingObjectsFromArray: 

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

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

setByAddingObjectsFromSet: 

- (GS_GENERIC_CLASS(NSSet,ElementT)*) setByAddingObjectsFromSet: (GS_GENERIC_CLASS(NSSet,ElementT)*)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: 

- (GS_GENERIC_TYPE(ElementT)) unique: (GS_GENERIC_TYPE(ElementT))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