next up previous contents
Next: MSetBase and MSet Up: Discussion Previous: Set Primitive Operations

Interface

The following methods are available to pointers and references to Collection objects. Those that are pure virtual are defined in class MSet.

 
Figure 3.24: Set Primitives with Set and Sequence Operands
virtual ~Collection<item> ()



The virtual destructor in the Collection class ensures that the proper subclass destructor will be called when the object referenced or pointed to is deleted. The new data structure must define its own destructor (or inherit one from a parent Collection).









int size () const = 0;



Return the number of stored elements.









Bool emptyQ () const = 0;



Return TRUE if there are no stored elements.









Bool fullQ () const = 0;



Return TRUE if there are no space left for additional elements.









Bool memberQ (const Item&e) const = 0;



Return TRUE if e is stored.









Bool sortedQ () const = 0;



Does the Container used to store the elements store them in sorted order?









DataType type () const = 0;



Return the type of this structure (DataType is an enumerated type defined in general.h).









Item first () const = 0;



Return the first element in the Container in which the Collection stores its elements.









Item last () const = 0;



Return the last element in the Container in which the Collection stores its elements.









void insert (Item e) = 0;



Insert e into the Container in which the Collection stores its elements.









void append (Item e) = 0;



Insert e as the last element of the Container which stores the elements if this is possible. Otherwise, i.e. the Container is sorted, just call insert()









void remove (Item e) = 0;



Remove e from the Container in which the Collection stores its elements.









void clear () = 0;



Remove all elements from the Container used to store the elements.









int iterate (Iterator<Item>& it, Item& e) const = 0;



This method is used by Iterator objects to obtain the successor of e. Typically, a Collection object will implement this by calling its Container's iterate() method.









Item ref (int i) = 0;



Return the element with index i.









int rank (Item it) = 0;



Return the index of item it.









int occurrences (Item) = 0;



Returns the number of occurrences of the passed item.









Bool subsetQ (Collection<Item>& c) = 0;



Return TRUE if every occurrence of an element e in the current collection is matched with an occurrence of the same element in c.









Bool properSubsetQ (Collection<Item>& c) = 0;



Return TRUE is the current collection is a subset of c and has fewer elements.









int permutationQ ();



Returns FALSE if duplicate elements exist.









void concatenate (const Collection<Item>& = 0);



Add the elements of the passed Collection by iterating through them and using append().









ostream& display (ostream&os) = 0;



This will be called when operator<<(ostream&,Collection<Item>&) is invoked.









Collection<Item>* newEmpty()  const = 0;



Dynamically allocates a new Collection of the same type as the current one and returns it. This is useful in copying graphs and other situations, where the only access to the Collection is through a Collection pointer (i.e. the type of Collection is not known). O(1)









Bool operator==(const Collection<Item>&) const = 0;  
Bool operator<=(const Collection<Item>&) const = 0;  
Bool operator< (const Collection<Item>&) const = 0;  
Bool operator>=(const Collection<Item>&) const = 0;  
Bool operator> (const Collection<Item>&) const = 0;  
Bool operator!=(const Collection<Item>&) const = 0;  
Bool operator==(const Container<Item>&) const = 0;  
Bool operator<=(const Container<Item>&) const = 0;  
Bool operator< (const Container<Item>&) const = 0;  
Bool operator>=(const Container<Item>&) const = 0;  
Bool operator> (const Container<Item>&) const = 0;  
Bool operator!=(const Container<Item>&) const = 0;  



Compare the Collection with a Collection or Container argument (by calling Container::operator...())








next up previous contents
Next: MSetBase and MSet Up: Discussion Previous: Set Primitive Operations
RHS Linux User
1/26/1998