OLSet Class Reference
[Containers]

A set of unique objects. More...

#import <ObjectiveLib/Set.h>

Inheritance diagram for OLSet:

Inheritance graph
[legend]
List of all members.

Public Member Functions

(OLAssociativeIterator *) - begin
 Return an iterator pointing to the beginning of the sequence.
(void) - clear
 Remove all elements.
(int) - compare:
 Compare this set to another object.
(id) - copy
 Make a copy of this set.
(unsigned) - count:
 Return the number of elements equal to key.
(BOOL) - empty
 Test whether the set is empty.
(OLAssociativeIterator *) - end
 Return an iterator pointing to one position beyond the end of the sequence.
(OLPair *) - equalRange:
 Return a range whose elements are equal to key.
(void) - erase:
 Remove the element designated by where.
(void) - eraseFrom:to:
 Remove a range of elements.
(unsigned) - eraseKey:
 Erase all instances of key.
(OLAssociativeIterator *) - find:
 Find an element.
(id) - insert:
 Insert an object into the set.
(OLAssociativeIterator *) - insertAt:value:
 Insert an object into the set.
(void) - insertFrom:to:
 Insert a range of objects into the set.
(BOOL) - isEqual:
 Test whether another set is equal to this one.
(OLStreamableFunctor< OLBoolBinaryFunction > *) - keyComp
 Return the function used to compare keys in the set.
(OLAssociativeIterator *) - lowerBound:
 Find the lower bound of a given key.
(unsigned) - maxSize
 Return the maxiumum number of objects that can be stored in a set.
(OLReverseBidiIterator *) - rbegin
 Return a reverse iterator pointing to the end of the sequence.
(OLReverseBidiIterator *) - rend
 Return a reverse iterator pointing to the beginning of the sequence.
(unsigned) - size
 Return the number of elements in the set.
(void) - swap:
 Swap this set with another one.
(OLAssociativeIterator *) - upperBound:
 Find the upper bound of a given key.
(OLStreamableFunctor< OLBoolBinaryFunction > *) - valueComp
 Return the function used to compare values.
(void) - writeSelfToStream:
 Write the object to a stream.
Initializers and Deallocators
(id) - free
 Finalize the set and deallocate any allocated memory.
(id) - init
 Initialize the set.
(id) - initFrom:to:
 Initialize the set.
(id) - initFrom:to:compare:
 Initialize the set.
(id) - initWithCompare:
 Initialize the set.
(id) - initWithObjectInStream:
 Initialize the object.
(id) - initWithOLSet:
 Initialize the set.

Static Public Member Functions

(id) + set
 Create and return a new set.
(id) + setFrom:to:
 Create and return a new set.
(id) + setWithCompare:
 Create and return a new set.
(id) + setWithOLSet:
 Create and return a new set.

Protected Attributes

OLTree * tree
 The underlying data structure.

Detailed Description

A set of unique objects.

A set is a sorted associative container of objects. Each object is unique; if an object is inserted into the set and another object that is equal is already in the set, then the insertion will fail. Sets are, due to their underlying data structure, sorted by definition, and the sorting order is determined by a comparison function that is passed during intialization. If no function is given to the set, then OLLess is used, thus ordering the set in ascending order.

See also:
OLAssociativeIterator


Member Function Documentation

- (OLAssociativeIterator*) begin  

Return an iterator pointing to the beginning of the sequence.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Returns:
an iterator pointing to the first element

- (void) clear  

Remove all elements.

- (int) compare: (id)  other  

Compare this set to another object.

If the other object is of type OLSet, each of the contained objects is compared to the corresponding object in other by calling the compare: method.

Parameters:
other the object with which to compare this one
Returns:
a value greater than, equal to, or less than zero accoringly as this object is greater than, equal to, or less than other

- (id) copy  

Make a copy of this set.

Returns:
the copy

- (unsigned) count: (id)  key  

Return the number of elements equal to key.

Parameters:
key the key to search for in the set
Returns:
the number of instances of key

- (BOOL) empty  

Test whether the set is empty.

Returns:
YES if the set is empty, NO otherwise

- (OLAssociativeIterator*) end  

Return an iterator pointing to one position beyond the end of the sequence.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Returns:
an iterator pointing to one position beyond the last element

- (OLPair*) equalRange: (id)  key  

Return a range whose elements are equal to key.

The returned pair contains two instances of OLAssociativeIterator delimiting the range of elements.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
key the value for which to search
Returns:
a pair of OLAssociativeIterator instances that define the range of elements in the set equal to key

- (void) erase: (OLAssociativeIterator *)  where  

Remove the element designated by where.

Precondition:
where must point to an element in this set.
Parameters:
where an iterator designating the element to remove

- (void) eraseFrom: (OLAssociativeIterator *)  first
to: (OLAssociativeIterator *)  last 

Remove a range of elements.

All elements in the range [first, last) will be removed from the set.

Precondition:
first and last must refer to elements in this set.
Parameters:
first the first in the range of elements to remove
last one position beyond the last in the range of elements to remove

- (unsigned) eraseKey: (id)  key  

Erase all instances of key.

The set is searched for key, all instances are removed from the set and the number removed is returned.

Parameters:
key the key to remove from the set
Returns:
the number of elements removed

- (OLAssociativeIterator*) find: (id)  key  

Find an element.

The element key is searched for in the set and an iterator to its location is returned. If the element does not exist in the set, then the returned iterator will be equal to the iterator returned by end.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
key the key for which to search
Returns:
an iterator pointing to the location of key, or an iterator equal to that returned by end if key does not exist

- (id) free  

Finalize the set and deallocate any allocated memory.

- (id) init  

Initialize the set.

The set is initially empty.

Returns:
a reference to this set

- (id) initFrom: (OLForwardIterator *)  first
to: (OLForwardIterator *)  last 

Initialize the set.

The set uses the comparison function OLLess for sorting and inserts all elements referred to in the range [first, last). It doesn't matter whether the elements are already sorted using OLLess because the set will sort them, anyway.

Parameters:
first the first in the range of elements to insert
last one beyond the last in the range of elements to insert
Returns:
a reference to this set

- (id) initFrom: (OLForwardIterator *)  first
to: (OLForwardIterator *)  last
compare: (OLStreamableFunctor< OLBoolBinaryFunction > *)  comp 

Initialize the set.

The set uses the given comparison function for sorting, comp, and inserts all elements referred to in the range [first, last). It doesn't matter whether the elements are already sorted using comp because the set will sort them, anyway.

Parameters:
first the first in the range of elements to insert
last one beyond the last in the range of elements to insert
comp the function to use to sort the set
Returns:
a reference to this set

- (id) initWithCompare: (OLStreamableFunctor< OLBoolBinaryFunction > *)  comp  

Initialize the set.

The set uses the given comparison function, comp, for sorting. The set is initially empty.

Parameters:
comp the comparison function used to maintain the sorting order
Returns:
a reference to this set

- (id) initWithObjectInStream: (OLObjectInStream *)  stream  

Initialize the object.

Each instance variable is read from stream and all other initialization is performed.

Parameters:
stream the stream from which to read
Returns:
a reference to this object

Reimplemented from < OLStreamable >.

- (id) initWithOLSet: (OLSet *)  set  

Initialize the set.

The comparison function and all the elements are copied from set into this set.

Parameters:
set the set to copy
Returns:
a reference to this set

- (id) insert: (id)  object  

Insert an object into the set.

An attempt is made to insert object into the set, and an instance of OLPair is returned indicating the state of the insertion. The first element in the returned pair is an instance of OLAssociativeIterator indicating the position of object in the set, and the second element of the returned pair is an object that responds to the message boolValue. The message boolValue will return YES if the insertion was successful, or NO if not.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
object the element to insert
Returns:
an instance of OLPair indicating the position of object in the set and whether the insertion succeeded or failed

Reimplemented in OLMultiSet.

- (OLAssociativeIterator*) insertAt: (OLAssociativeIterator *)  where
value: (id)  object 

Insert an object into the set.

The object is inserted and the position indicated by where is used as a hint about where in the set the object should be placed. There is no guarantee that the object will ultimately placed anywhere close to where. Note that the insertion may fail if the object is already in the set. An iterator is returned that points to object.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
where a hint as to where in the set the object should be located
object the object to insert
Returns:
the iterator indicating where object is now located in the set

Reimplemented in OLMultiSet.

- (void) insertFrom: (OLForwardIterator *)  first
to: (OLForwardIterator *)  last 

Insert a range of objects into the set.

An attempt is made to insert all objects in the range [first, last), however there is no guarantee that any of the elements in the range will actually be inserted if they already exist in the set.

Parameters:
first the first in the range of objects to insert
last one position beyond the last in the range of objects to insert

Reimplemented in OLMultiSet.

- (BOOL) isEqual: (id)  object  

Test whether another set is equal to this one.

Two sets are considered equal if they contain the same number of objects and the objects are in the same order and each object is equal to the corresponding object in the other set.

Parameters:
object the object to test
Returns:
YES if object is equal to this set

Reimplemented from < OLInserter >.

Reimplemented in OLMultiSet.

- (OLStreamableFunctor<OLBoolBinaryFunction>*) keyComp  

Return the function used to compare keys in the set.

Returns:
the function object that is used to compare keys

- (OLAssociativeIterator*) lowerBound: (id)  key  

Find the lower bound of a given key.

The lower bound is the first position in the set at which key can be inserted without disturbing the sorting order. An iterator pointing to the lower bound is returned.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
key the key for which to find the lower bound
Returns:
an iterator indicating the lower bound

- (unsigned) maxSize  

Return the maxiumum number of objects that can be stored in a set.

This limit is theoretical, meaning that there is no guarantee that you can insert this many objects into any given set. The memory conditions of the run-time system play an important role.

Returns:
the maximum number of objects for a set

- (OLReverseBidiIterator*) rbegin  

Return a reverse iterator pointing to the end of the sequence.

Advancing the returned iterator will move backwards through the sequence to the point indicated by the iterator returned by rend.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Returns:
a reverse iterator for the end of the sequence

- (OLReverseBidiIterator*) rend  

Return a reverse iterator pointing to the beginning of the sequence.

This iterator indicates one position beyond the last position that may be referenced by a reverse iterator.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Returns:
a reverse iterator for the beginning of the sequence

+ (id) set  

Create and return a new set.

An instance of OLLess is used to compare items for the purposes of sorting.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Returns:
a new set

+ (id) setFrom: (OLForwardIterator *)  first
to: (OLForwardIterator *)  last 

Create and return a new set.

The set is initialized with the contents of the range [first, last). An instance of OLLess is used to compare items for the purposes of sorting.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
first the first in the range of elements to insert
last one beyond the last in the range of elements to insert
Returns:
a new set

+ (id) setWithCompare: (OLStreamableFunctor< OLBoolBinaryFunction > *)  comp  

Create and return a new set.

The set is empty and the comparison function comp is used to sort keys.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
comp the comparison function used to sort keys
Returns:
a new set

+ (id) setWithOLSet: (OLSet *)  right  

Create and return a new set.

The set is initialized with the contents of right.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
right the set to copy
Returns:
a new set

- (unsigned) size  

Return the number of elements in the set.

Returns:
the number of elements

- (void) swap: (OLSet *)  right  

Swap this set with another one.

All elements in right will be placed into this set, and all elements in this set will be placed in right.

Parameters:
right the set with which to swap this one

- (OLAssociativeIterator*) upperBound: (id)  key  

Find the upper bound of a given key.

The upper bound is the last position in the set at which key can be inserted without disturbing the sorting order. An iterator pointing to the upper bound is returned.

Note:
If OpenStep is present the returned object will be autoreleased before being returned.
Parameters:
key the key for which to find the upper bound
Returns:
an iterator indicating the upper bound

- (OLStreamableFunctor<OLBoolBinaryFunction>*) valueComp  

Return the function used to compare values.

This returns the same function as the message keyComp.

Returns:
the function object for comparing values

- (void) writeSelfToStream: (OLObjectOutStream *)  stream  

Write the object to a stream.

All instance variables are written to stream.

Parameters:
stream the stream to which to write.

Reimplemented from < OLStreamable >.


Member Data Documentation

- (OLTree*) tree [protected]

The underlying data structure.


The documentation for this class was generated from the following file:
ObjectiveLibGenerated Sun Apr 22 15:19:03 2007, © 2004-2007 Will Mason
SourceForge.net Logo