#include "set.h"
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 |
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.
The destructor deallocates storage associated with set.
| int Set< ElemType >::size | ( | ) |
This member function returns the number of elements in this set.
| bool Set< ElemType >::isEmpty | ( | ) |
This member function returns true if this set contains no elements, false otherwise.
| 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.
| 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.
| bool Set< ElemType >::contains | ( | ElemType | elem | ) |
Returns true if the element in this set, false otherwise.
| 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.
This predicate function implements the equality relation on sets. It returns true if this set and set2 contain exactly the same elements, false otherwise.
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).
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.
| 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.
| 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.
| 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.
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.
| void Set< ElemType >::mapAll | ( | void(fn)(ElemType) | ) |
| void Set< ElemType >::mapAll | ( | void(fn)(ElemType, ClientDataType &) | , | |
| ClientDataType & | data | |||
| ) |
friend class Iterator [friend] |
1.5.1