Name

Set -- collection of members each having a defined identity


Synopsis

//
// Set -- collection of members each having a defined identity
//
@deftype Set <KeyedCollection, CREATABLE>
CREATING
- (void)	setKeyFunction: (id (*)(id))aFunction;
USING
- (id (*)(id))	getKeyFunction;

- (BOOL)	add: anObject;
- (BOOL)	add: anObject setIndex: anIndex;
-		replace: anObject;
@end

Description

Set is a subtype of KeyedCollection in which the key value associated with each member is determined by the member value itself. The key value may be identical to the member itself, or may be defined as a a function of the member using a create-time option.

Inherited behavior

@deftype Set <KeyedCollection, CREATABLE>
The Set type inherits most of its interface from the KeyedCollection supertype. Set defines no create-time options beyond those already defined by KeyedCollection. If a custom compare or bucket function is specified, the member value is passed as the key value arguments of these functions. These functions determine what part of the member value is part of the key value, by determining which key values will compare equal to any member.

Set behavior

- (BOOL)	add: anObject;
- (BOOL)	add: anObject setIndex: anIndex;
-		replace: anObject;
@end
The add: message adds a new member to a set. It returns true if member added matched the key of any member already contained in the Set. Whether or not the member was actually added to the collection or not depends on the setting of DupOption.

The add:setIndex: message adds a new member to a set just like add:, but also has a side effect of setting the position of the index passed as the setIndex: argument to the member which was just added. If an index positioned to the new member is needed anyway, setting the index in the same operation avoids repeating a search for the position at which the member key belongs.

The replace: message replaces a member stored at a given key with another member value that matches the same key. The new value to replace the existing one is passed as the argument. replace: returns the member value that was replaced, or nil if the collection contained no member with a matching key.


Roger Burkhart <rmb@santafe.edu>
Last modified: