RWTValHashMap(3C++)

RWTValHashMap<K,T,H,EQ> - Rogue Wave library class

As shipped in IRIX 6.5. First release of IRIX 6.5.

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

Synopsis
              #include <rw/tvhdict.h>
          RWTValHashMap<K,T,H,EQ> m;



Please Note!



     If you have the Standard C++ Library, use the interface described here.
     Otherwise, use the interface for RWTValHashDictionary described in
     Appendix A.


Description
     This class maintains a collection of keys, each with an associated item
     of type T.  These pairs are stored according to a hash object of type H.
     H must provide a hash function on elements of type K via a public member
          unsigned long operator()(const K& x) Equivalent keys 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 K& x, const K& y) which should return true if
     x and y are equivalent.  RWTValHashMap<K,T,H,EQ> will not accept a key
     that compares equal to any key already in the collection.
     (RWTValHashMultiMap<K,T,H,EQ> may contain multiple keys that compare
     equal to each other.)  Equality is based on the equality object and not
     on the == operator.

Persistence
     Isomorphic

Related Classes
     Class RWTValHashMultiMap<K,T,H,EQ> offers the same interface to a
     collection that accepts multiple keys that compare equal to each other.
     Class rw_hashmap<K,T,H,EQ> is the C++-standard compliant collection that
     serves as the underlying implementation for this collection.

Public Typedefs
              typedef rw_hashmap<K,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 pair <const K,T>                       value_type;
          typedef K                                      key_type;
          typedef T                                      data_type;
          typedef pair <const K,T>&                      reference;
          typedef pair <const K,T>&                      const_reference;

Public Constructors
              RWTValHashMap<K,T,H,EQ>();


     Constructs an empty map.

              RWTValHashMap<K,T,H,EQ>(const rw_hashmap<K,T,H,EQ>& m);


     Constructs a map by copying all elements of m.

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


     Creates an empty hashed map which uses the hash object h and has an
     initial capacity of sz.

              RWTValHashMap<K,T,H,EQ>(const RWTValHashMap<K,T,H,EQ>& rwm);


     Copy constructor.

              RWTValHashMap<K,T,H,EQ>(const value_type* first,
               const value_type* last);


     Constructs a map by copying elements from the array of value_type pairs
     pointed to by first, up to, but not including, the pair pointed to by
     last.

Public Member Operators
              RWTValHashMap<K,T,H,EQ>&
          operator=(const RWTValHashMap<K,T,H,EQ>& m);
          RWTValHashMap<K,T,H,EQ>&
          operator=(const rw_hashmap<K,T,H,EQ>& m);


     Destroys all elements of self and replaces them by copying all
     associations from m.

              bool
          operator==(const RWTValHashMap<K,T,H,EQ>& m) const;
          bool
          operator==(const rw_hashmap<K,T,H,EQ>& m) const;


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

              T&
          operator[](const K& key);


     Looks up key and returns a reference to its associated item.  If the key
     is not in the dictionary, then it will be added with an associated item
     provided by the default constructor for type T.

Public Member Functions
              void
          apply(void (*fn)(const K&, T&, void*),void* d);
          void
          apply(void (*fn)(const K&,const T&,void*),void* d) const;


     Applies the user-defined function pointed to by fn to every association
     in the collection.  This function must have one of the prototypes:





                 void yourfun(const K& key, T& a, void* d);
             void yourfun(const K& key, const T& a,void* d);


     Client data may be passed through parameter d.

              void
          applyToKeyAndValue(void (*fn)(const K&, T&,void*),void* d);
          void
          applyToKeyAndValue
          (void (*fn)(const K&, const T, void*),void* d) const;


     This is a deprecated version of the apply member above.  It behaves
     exactly the same as apply.

              iterator
          begin();
          const_iterator
          begin() const;


     Returns an iterator positioned at the first pair in 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 key and its
     associated item will have its destructor called.

              bool
          contains(const K& key) const;


     Returns true if there exists a key j in self that compares equal to key;
     otherwise returns false.

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


     Returns true if there exists an association a in self such that the
     expression ((*fn)(a,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.

              iterator
          end();
          const_iterator
          end() const;


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

              size_type
          entries() const;


     Returns the number of associations in self.

              float
          fillRatio() const;


     Returns the ratio entries()/capacity().

              bool
          find(const K& key, K& r) const;


     If there exists a key j in self that compares equal to key, assigns j to
     r and returns true.  Otherwise, returns false and leaves the value of r
     unchanged.

              bool
          find(bool (*fn)(const_reference,void*),void* d,
                          pair<K,T>& r) const;


     If there exists an association a in self such that the expression
     ((*fn)(a,d)) is true, assigns a to r 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 K& a, void* d);


     Client data may be passed through parameter d.

              bool
          findValue(const K& key, T& r) const;


     If there exists a key j in self that compares equal to key, assigns the
     item associated with j to r and returns true.  Otherwise, returns false
     and leaves the value of r unchanged.

              bool
          findKeyValue(const K& key, K& kr, T& tr) const;


     If there exists a key j in self that compares equal to key, assigns j to
     kr, assigns the item associated with j to tr, and returns true.
     Otherwise, returns false and leaves the values of kr and tr unchanged.

              bool
          insert(const K& key, const T& a);


     Adds key with associated item a to the collection.  Returns true if the
     insertion is successful, otherwise returns false.  The function will
     return true unless the collection already holds an association with the
     equivalent key.

              bool
          insertKeyAndValue(const K& key,const T& a);


     This is a deprecated version of the insert member above.  It behaves
     exactly the same as insert.

              bool
          isEmpty() const;


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

              size_type
          occurrencesOf(const K& key) const;


     Returns the number of keys j in self that compare equal to key.

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


     Returns the number of associations a in self such that the
     expression((*fn)(a,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 K& key);


     Removes the first association with key j in self such that the expression
     (j == key) is true and returns true.  Returns false if there is no such
     association.

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


     Removes the first association a in self such that the expression
     ((*fn)(a,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 K& key);


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

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


     Removes all associations a in self such that the expression
     ((*fn)(a,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 map 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_hashmap<K,T,H,EQ>&
          std();
          const rw_hashmap<K,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 compliant collections.

Related Global Operators
              RWvostream&
          operator<<(RWvostream& strm,
                 const RWTValHashMap<K,T,H,EQ>& coll);
          RWFile&
          operator<<(RWFile& strm, const RWTValHashMap<K,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, RWTValHashMap<K,T,H,EQ>& coll);
          RWFile&
          operator>>(RWFile& strm, RWTValHashMap<K,T,H,EQ>& coll);


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

              RWvistream&
          operator>>(RWvistream& strm, RWTValHashMap<K,T,H,EQ>*& p);
          RWFile&
          operator>>(RWFile& strm, RWTValHashMap<K,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.