RWTValHashMultiSet(3C++)

RWTValHashMultiSet<T,H,EQ> - Rogue Wave library class

Showing IRIX 6.5.15. Unchanged since IRIX 6.5.

Name
     RWTValHashMultiSet<T,H,EQ> - Rogue Wave library class

Synopsis
              #include <rw/tvhasht.h>



              RWTValHashMultiSet<T,H,EQ>

Please Note!
     If you have the Standard C++ Library, use the interface described here.
     Otherwise, use the interface for RWTValHashTable described in Appendix A.






Description
     This class maintains a collection of values, which are stored according
     to a hash object of type H.  H must offer a hash function for elements of
     type T via a public member
        unsigned long operator()(const T& x) const Objects within the
     collection will be grouped together based on an equality object of type
     EQ. EQ must ensure this grouping via public member
        bool operator()(const T& x, const T& y) const which should return true
     if x and y are equivalent, false otherwise.  RWTValHashMultiSet<T,H,EQ>
     may contain multiple items that compare equal to each other.
     (RWTValHashSet<T,H,EQ> will not accept an item that compares equal to an
     item already in the collection.)

Persistence
     Isomorphic

Example
              //



              // tvhmsstr.cpp
          //
          #include <rw/tvhasht.h>
          #include <rw/cstring.h>
          #include <iostream.h>
          struct silly_hash{
             unsigned long operator()(RWCString x) const
             { return x.length() * (long)x[0]; }
          };
          main(){
          RWTValHashMultiSet<RWCString,silly_hash,equal_to<RWCString> > set1;
          RWTValHashMultiSet<RWCString,silly_hash,equal_to<RWCString> > set2;
            set1.insert("one");
            set1.insert("two");
            set1.insert("three");
            set1.insert("one");     // OK: duplicates allowed
            set1.insert("one");
            cout << set1.entries() << endl;  // Prints "5"
            set2.insert("one");
            set2.insert("five");
            set2.insert("one");
            cout << ((set1.isEquivalent(set2)) ? "TRUE" : "FALSE") << endl;
            // Prints "FALSE"
            set2.intersection(set1);
            set1.clear();
            cout << set1.entries() << endl;    // Prints "0"
            cout << set2.entries() << endl;    // Prints "2"
            return 0;

Related Classes
     }


     Class RWTValHashSet<T,H,EQ> offers the same interface to a collection
     that will not accept multiple items that compare equal to each other.
     Class rw_hashmultiset<T,H,EQ> is the C++-standard compliant collection
     that serves as the underlying implementation for
     RWTValHashMultiSet<T,H,EQ>.

Public Typedefs
              typedef rw_hashmultiset<T,H,EQ>                container_type;
          typedef container_type::iterator               iterator;
          typedef container_type::const_iterator         const_iterator;
          typedef container_type::size_type              size_type;
          typedef T                                      value_type;
          typedef T&                                     reference;
          typedef const T&                               const_reference;



Public Constructors
              RWTValHashMultiSet<T,H,EQ>
          (size_type sz = 1024,const H& h = H(),const EQ& eq = EQ());


     Constructs an empty set.  The underlying hash table representation will
     have sz buckets, will use h as its hashing function and will use eq to
     determine equivalence between elements.

              RWTValHashMultiSet<T,H,EQ>(const rw_hashmultiset<T,H,EQ>& s);


     Constructs a set by copying all elements of s.

              RWTValHashMultiSet<T,H,EQ>(const RWTValHashMultiSet<T,H,EQ>&);


     Copy constructor.

              RWTValHashMultiSet<T,H,EQ>
          (const H& h,size_type sz = RWDEFAULT_CAPACITY);


     Creates an empty hashed multi-set which uses the hash object h and has an
     initial hash table capacity of sz.

              RWTValHashMultiSet<T,H,EQ>(const T* first,const T* last,size_type sz = 1024,const H& h = H(),const EQ& eq = EQ());


     Constructs a set by copying elements from the array of Ts pointed to by
     first, up to, but not including, the element pointed to by last. The
     underlying hash table representation will have sz buckets, will use h as
     its hashing function and will use eq to determine equivalence between
     elements.

Public Member Operators
              RWTValHashMultiSet<T,H,EQ>&
          operator=(const RWTValHashMultiSet<T,H,EQ>& s);



              RWTValHashMultiSet<T,H,EQ>&
          operator=(const rw_hashmultiset<T,H,EQ>& s);


     Destroys all elements of self and replaces them by copying all elements
     of s.

              bool
          operator==(const RWTValHashMultiSet<T,H,EQ>& s) const;
          bool
          operator==(const rw_hashmultiset<T,H,EQ>& s) const;


     Returns true if self compares equal to s, otherwise returns false.  Two
     collections are equal if both have the same number of entries, and
     iterating through both collections produces, in turn, individual elements
     that compare equal to each other.

Public Member Functions
              void
          apply(void (*fn)(const_reference,void*), void* d) const;


     Applies the user-defined function pointed to by fn to every item in the
     collection.  This function must have prototype:
                 void yourfun(const_reference a, void* d);


      Client data may be passed through parameter d.

              iterator
          begin();
          const_iterator
          begin() const;


     Returns an iterator positioned at the first element of self.

              size_type
          capacity() const;


     Returns the number of buckets(slots) available in the underlying hash
     representation.  See resize below.

              void
          clear();


     Clears the collection by removing all items from self.  Each item will
     have its destructor called.

              bool
          contains(const_reference a) const;


     Returns true if there exists an element t in self that compares equal to
     a, otherwise returns false.

              bool
          contains(bool (*fn)(const_reference,void*), void* d) const;


     Returns true if there exists an element t in self such that the
     expression ((*fn)(t,d)) is true, otherwise returns false.  fn points to a
     user-defined tester function which must have prototype:

                 bool yourTester(const_reference a, void* d);


     Client data may be passed through parameter d.

              void
          difference(const RWTValHashMultiSet<T,H,EQ>& s);


     Sets self to the set-theoretic difference given by (self - s).

              iterator
          end();
          const_iterator
          end() const;


     Returns an iterator positioned "just past" the last element in self.

              size_type
          entries() const;


     Returns the number of items in self.

              float
          fillRatio() const;


     Returns the ratio entries()/capacity().

              bool
          find(const_reference a,T& k) const;


     If there exists an element t in self such that the expression (t == a) is
     true, assigns t to k and returns true.  Otherwise, returns false and
     leaves the value of k unchanged.

              bool
          find(bool (*fn)(const_reference,void*),void* d,T& k) const;


     If there exists an element t in self that compares equal to a, assigns t
     to k and returns true.  Otherwise, returns false and leaves the value of
     k unchanged.  fn points to a user-defined tester function which must have
     prototype:

                 bool yourTester(const_reference a, void* d);


     Client data may be passed through parameter d.

              bool
          insert(const_reference a);


     Adds the item a to the collection.  Returns true.

              void
          intersection(const RWTValHashMultiSet<T,H,EQ>& s);


     Destructively performs a set theoretic intersection of self and s,
     replacing the contents of self with the result.

              bool
          isEmpty() const;


     Returns true if there are no items in the collection, false otherwise.

              bool
          isEquivalent(const RWTValHashMultiSet<T,H,EQ>& s) const;


     Returns true if there is set equivalence between self and s, and returns
     false otherwise.

              bool
          isProperSubsetOf(const RWTValHashMultiSet<T,H,EQ>& s) const;


     Returns true if self is a proper subset of s, and returns  false
     otherwise.

              bool
          isSubsetOf(const RWTValHashMultiSet<T,H,EQ>& s) const;


     Returns true if self is a subset of s, and returns false otherwise.

              size_type
          occurrencesOf(const_reference a) const;


     Returns the number of elements t in self that compares equal to a.

              size_type
          occurrencesOf(bool (*fn)(const_reference,void*),void* d) const;


     Returns the number of elements t in self such that the
     expression((*fn)(t,d)) is true.   fn points to a user-defined tester
     function which must have prototype:





                 bool yourTester(const_reference a, void* d);


     Client data may be passed through parameter d.

              bool
          remove(const_reference a);


     Removes the first element t in self that compares equal to a and returns
     true.  Returns false if there is no such element.

              bool
          remove(bool (*fn)(const_reference,void*), void* d);


     Removes the first element t in self such that the expression ((*fn)(t,d))
     is true and returns true.  Returns false if there is no such element.  fn
     points to a user-defined tester function which must have prototype:





                 bool yourTester(const_reference a, void* d);


     Client data may be passed through parameter d.

              size_type
          removeAll(const_reference a);


     Removes all elements t in self that compare equal to a.  Returns the
     number of items removed.

              size_type
          removeAll(bool (*fn)(const_reference,void*), void* d);

     Removes all elements t in self such that the expression ((*fn)(t,d))is
     true.  Returns the number of items removed.  fn points to a user-defined
     tester function which must have prototype:





                  bool yourTester(const_reference a, void* d);


     Client data may be passed through parameter d.

              void
          resize(size_type sz);


     Changes the capacity of self by creating a new hashed multi-set with a
     capacity of  sz .  resize copies every element of self into the new
     container and finally swaps the internal representation of the new
     container with the internal representation of self.

              rw_hashmultiset<T,H,EQ>&
          std();
          const rw_hashmultiset<T,H,EQ>&
          std() const;


     Returns a reference to the underlying C++-standard collection that serves
     as the implementation for self.  This reference may be used freely,
     providing access to the C++-standard interface as well as
     interoperability with other software components that make use of the
     C++-standard collections.

              void
          symmetricDifference(const RWTValHashMultiSet<T,H,EQ>& s);


     Destructively performs a set theoretic symmetric difference operation on
     self and s.  Self is replaced by the result. A symmetric difference can
     be informally defined as (A_B)-(A_B).

              void
          Union(const RWTValHashMultiSet<T,H,EQ>& rhs);


     Destructively performs a set theoretic union operation on self and rhs.
     Self is replaced by the result. Note the uppercase "U" in Union to avoid

     conflict with the C++ reserved word.

Related Global Operators
              RWvostream&
          operator<<(RWvostream& strm,
                 const RWTValHashMultiSet<T,H,EQ>& coll);
          RWFile&
          operator<<(RWFile& strm,
                 const RWTValHashMultiSet<T,H,EQ>& coll);


     Saves the collection coll onto the output stream strm, or a reference to
     it if it has already been saved.

              RWvistream&
          operator>>(RWvistream& strm, RWTValHashMultiSet<T,H,EQ>& coll);
          RWFile&
          operator>>(RWFile& strm, RWTValHashMultiSet<T,H,EQ>& coll);


     Restores the contents of the collection coll from the input stream strm.

              RWvistream&
          operator>>(RWvistream& strm, RWTValHashMultiSet<T,H,EQ>*& p);
          RWFile&
          operator>>(RWFile& strm, RWTValHashMultiSet<T,H,EQ>*& p);


     Looks at the next object on the input stream strm and either creates a
     new collection off the heap and sets p to point to it, or sets p to point
     to a previously read instance.  If a collection is created off the heap,
     then you are responsible for deleting it.