You can also choose not to add duplicate entries. The addNTest: method adds if the object was absent and returns a value that can be used to test whether the object was found or not. The filter: method frees a new entry when it's a duplicate. The replace: method always replaces duplicates (returning the object that was previously in the collection).
+ newReturns a new instance that sorts its contents with respect to compare:.
+ newDictCompareReturns a new instance that sorts its contents with respect to dictCompare:.
- copyReturns a new copy of the object (without copying the elements).
- deepCopyReturns a new copy of the object. The elements in the new copy are deep copies of the elements in the original object.
- emptyYourselfEmpties all the members of the object (without freeing them). Returns the receiver.
- freeContentsRemoves and frees the contents of the object, but doesn't free the object itself. Returns the receiver.
- freeFrees the object, but not its contents. Returns nil. Do :
if you want to free the object and its contents.aSort = [[aSort freeObjects] free];
- (unsigned) sizeReturns the number of elements in the object.
- (BOOL) isEmptyWhether the number of elements is equal to zero.
- eachElementReturns a sequence of sorted elements. The first element in the sequence is the smallest with respect to the ordering.
aSeq = [aSort eachElement]; while ((anElement = [aSeq next])) { /* do something */ } aSeq = [aSeq free];
- (unsigned) hashReturns a hash value based on the receiver's address and the results of sending the hash message to the contents.
- (BOOL) isEqual : aSortReturns YES if aSort is an ObjSort instance, and if each member of its contents responds affirmatively to the message isEqual: when compared to the corresponding member of the receiver's contents.
- add : anObjectAdds anObject to the receiver, keeping the contents of the object sorted. Duplicate entries are allowed. Returns the receiver.
- addNTest : anObjectAdds anObject if it was not previously in the set. Returns anObject if the addition takes place, otherwise returns nil.
- filter : anObjectIf anObject compares equally to some object in the contents of the receiver, then anObject is freed, and the matching object is returned. Otherwise, anObject is added and returned.
- replace : anObjectIf a matching object is found, then anObject replaces that object, and the matching object is returned. If there is no matching object, anObject is added to the receiver, and nil is returned.
- remove : oldObjectRemoves oldObject or the element that matches (when the compare method returns zero). Returns the removed entry, or nil if there is no matching entry.
Note: Not implemented
- addContentsTo : aColAdds every element of the receiver to aCol and returns aCol. If aCol is nil, returns nil. The argument aCol need not actually be a collection, as long as it responds to add: in the same way as collections do.
- addContentsOf : aColAdds each member of aCol to the receiver. Returns the receiver. If aCol is nil, no action is taken. The argument aCol need not be a collection, so long as it responds to eachElement in the same way as collections do.
- removeContentsOf : aColRemoves each of the members of aCol from the receiver. Returns the receiver. The argument aCol need not be a collection, as long as it responds to eachElement as collections do.
If aCol is the same object as the receiver, it empties itself using emptyYourself and returns the receiver.
- removeContentsFrom : aColRemoves each of the members of the receiver from aCol. Returns the receiver. The argument aCol need not be a collection, as long as it responds to remove: in the same way as collections.
- find : anObjectReturns any element in the receiver which isEqual: to anObject. Otherwise, returns nil.
- (BOOL) contains : anObjectReturns YES if the receiver contains anObject. Otherwise, returns NO. Implementation is in terms of the receiver's find: method.
- printToFile :(FILE *) aFilePrints a comma separated list of the objects in the set by sending each individual object a printToFile: message. Returns the receiver.
- write :(NXTypedStream *) streamWrites the set and all its elements to the typed stream stream. Returns the receiver.
- read :(NXTypedStream *) streamReads the set and all its elements from the typed stream stream. Returns the receiver.