ObjectiveLib  1.0.0
Public Member Functions | Static Public Member Functions | Protected Attributes
OLSet Class Reference

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) - copyWithZone:
 Make a copy of this set allocating memory from the given zone.
(unsigned) - count:
 Return the number of elements equal to key.
(BOOL) - empty
 Test whether the set is empty.
(void) - encodeWithCoder:
 Encode the set.
(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) - init
 Initialize the set.
(id) - initFrom:to:
 Initialize the set.
(id) - initFrom:to:compare:
 Initialize the set.
(id) - initWithCoder:
 Initialize the set.
(id) - initWithCompare:
 Initialize the set.
(id) - initWithObjectInStream:
 Initialize the object.
(id) - initWithOLSet:
 Initialize the set.
(void) - dealloc
 Finalize the set and deallocate any allocated memory.

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

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:
otherthe 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) copyWithZone: (NSZone *)  zone

Make a copy of this set allocating memory from the given zone.

Parameters:
zonethe zone from which to allocate memory
Returns:
the copy
- (unsigned) count: (id)  key

Return the number of elements equal to key.

Parameters:
keythe key to search for in the set
Returns:
the number of instances of key
- (void) dealloc

Finalize the set and deallocate any allocated memory.

- (BOOL) empty

Test whether the set is empty.

Returns:
YES if the set is empty, NO otherwise
- (void) encodeWithCoder: (NSCoder *)  encoder

Encode the set.

The set is saved to an archive using encoder. The set will be retrieved from the archive using the initializer initWithCoder:.

Parameters:
encoderthe coder which will save the bit set to the archive

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:
keythe 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:
wherean 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:
firstthe first in the range of elements to remove
lastone 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:
keythe 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:
keythe 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) 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:
firstthe first in the range of elements to insert
lastone 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:
firstthe first in the range of elements to insert
lastone beyond the last in the range of elements to insert
compthe function to use to sort the set
Returns:
a reference to this set
- (id) initWithCoder: (NSCoder *)  decoder

Initialize the set.

This initializer creates a new set from an archive and returns it.

Postcondition:
The set returned will be identical to the set saved to the archive using the encodeWithCoder: message.
Parameters:
decoderthe coder which will decode the archived set
Returns:
a reference to this set

Initialize the set.

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

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

Initialize the object.

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

Parameters:
streamthe 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:
setthe 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:
objectthe 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:
wherea hint as to where in the set the object should be located
objectthe 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:
firstthe first in the range of objects to insert
lastone 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:
objectthe object to test
Returns:
YES if object is equal to this set

Reimplemented from <OLInserter>.

Reimplemented in OLMultiSet.

Return the function used to compare keys in the set.

Returns:
the function object that is used to compare keys

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:
keythe 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

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

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:
firstthe first in the range of elements to insert
lastone beyond the last in the range of elements to insert
Returns:
a new set

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:
compthe 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:
rightthe 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:
rightthe set with which to swap this one

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:
keythe key for which to find the upper bound
Returns:
an iterator indicating the upper bound

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:
streamthe 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 Sat Feb 15 2014 07:45:35, © 2004-2007 Will Mason