Set< ElemType > Class Template Reference

#include "set.h"

List of all members.

Public Member Functions

 Set (int(cmpFn)(ElemType, ElemType)=OperatorCmp)
 ~Set ()
int size ()
bool isEmpty ()
void add (ElemType elem)
void remove (ElemType elem)
bool contains (ElemType elem)
ElemType * find (ElemType elem)
bool equals (Set &otherSet)
bool isSubsetOf (Set &otherSet)
void unionWith (Set &otherSet)
void intersect (Set &otherSet)
void subtract (Set &otherSet)
void clear ()
void mapAll (void(fn)(ElemType elem))
template<typename ClientDataType>
void mapAll (void(fn)(ElemType elem, ClientDataType &data), ClientDataType &data)
Iterator iterator ()
template<typename ElemType>
void mapAll (void(fn)(ElemType))
template<typename ClientDataType>
void mapAll (void(fn)(ElemType, ClientDataType &), ClientDataType &data)

Friends

class Iterator

Classes

class  Iterator


Detailed Description

template<typename ElemType>
class Set< ElemType >

This interface defines a class template that stores a collection of distinct elements, using a sorted relation on the elements to provide efficient managaement of the collection. For maximum generality, the Set is supplied as a class template. The element type is determined by the client. The client configures the set to hold values of a specific type, e.g. Set<int> or Set<studentT>. The one requirement on the element type is that the client must supply a comparison function that compares two elements (or be willing to use the default comparison function that uses the built-on operators < and ==).


Constructor & Destructor Documentation

template<typename ElemType>
Set< ElemType >::Set ( int(cmpFn)(ElemType, ElemType)  = OperatorCmp  ) 

The constructor initializes an empty set. The optional argument is a function pointer that is applied to two elements to determine their relative ordering. The comparison function should return 0 if the two elements are equal, a negative result if first is "less than" second, and a positive resut if first is "greater than" second. If no argument is supplied, the OperatorCmp template is used as a default, which applies the bulit-in < and == to the elements to determine ordering.

template<typename ElemType>
Set< ElemType >::~Set (  ) 

The destructor deallocates storage associated with set.


Member Function Documentation

template<typename ElemType>
int Set< ElemType >::size (  ) 

This member function returns the number of elements in this set.

template<typename ElemType>
bool Set< ElemType >::isEmpty (  ) 

This member function returns true if this set contains no elements, false otherwise.

template<typename ElemType>
void Set< ElemType >::add ( ElemType  elem  ) 

This member function adds an element to this set. If the value was already contained in the set, the existing entry is overwritten by the new copy, and the set's size is unchanged. Otherwise, the value is added and set's size increases by one.

template<typename ElemType>
void Set< ElemType >::remove ( ElemType  elem  ) 

This member function removes an element from this set. If the element was not contained in the set, the set is unchanged. Otherwise, the element is removed and the set's size decreases by one.

template<typename ElemType>
bool Set< ElemType >::contains ( ElemType  elem  ) 

Returns true if the element in this set, false otherwise.

template<typename ElemType>
ElemType * Set< ElemType >::find ( ElemType  elem  ) 

If the element is contained in this set, returns a pointer to that elem. The pointer allows you to update that element in place. If element is not contained in this set, NULL is returned.

template<typename ElemType>
bool Set< ElemType >::equals ( Set< ElemType > &  otherSet  ) 

This predicate function implements the equality relation on sets. It returns true if this set and set2 contain exactly the same elements, false otherwise.

template<typename ElemType>
bool Set< ElemType >::isSubsetOf ( Set< ElemType > &  otherSet  ) 

This predicate function implements the subset relation on sets. It returns true if all of the elements in this set are contained in set2. The set2 does not have to be a proper subset (that is, it may be equals).

template<typename ElemType>
void Set< ElemType >::unionWith ( Set< ElemType > &  otherSet  ) 

These fmember unctions modify the receiver set as follows:

set.unionWith(set2); Adds all elements from set2 to this set. set.intersect(set2); Removes any element not in set2 from this set. set.subtract(set2); Removes all element in set2 from this set.

template<typename ElemType>
void Set< ElemType >::intersect ( Set< ElemType > &  otherSet  ) 

template<typename ElemType>
void Set< ElemType >::subtract ( Set< ElemType > &  otherSet  ) 

template<typename ElemType>
void Set< ElemType >::clear (  ) 

This member function removes all elements from this set. The set is made empty and will have size() = 0 after being cleared.

template<typename ElemType>
void Set< ElemType >::mapAll ( void(fn)(ElemType elem)   ) 

This member function iterates through this set's contents and calls the function fn once for each element.

template<typename ElemType>
template<typename ClientDataType>
void Set< ElemType >::mapAll ( void(fn)(ElemType elem, ClientDataType &data)  ,
ClientDataType &  data 
)

This member function iterates through this set's contents and calls the function fn once for each element, passing the element and the client's data. That data can be of whatever type is needed for the client's callback.

template<typename ElemType>
Set< ElemType >::Iterator Set< ElemType >::iterator (  ) 

This member function creates an iterator that allows the client to iterate through the elements in this set. The elements are accessed in order as determined by the elem comparison function.

template<typename ElemType>
template<typename ElemType>
void Set< ElemType >::mapAll ( void(fn)(ElemType)   ) 

template<typename ElemType>
template<typename ClientDataType>
void Set< ElemType >::mapAll ( void(fn)(ElemType, ClientDataType &)  ,
ClientDataType &  data 
)


Friends And Related Function Documentation

template<typename ElemType>
friend class Iterator [friend]


The documentation for this class was generated from the following file:
Generated on Mon Feb 12 23:30:08 2007 for CS 106B Libraries by  doxygen 1.5.1