**Module:** Essential Tools Module **Group:** STL Extension-based Collection

Does not inherit

- Local Index
- Synopsis
- Description
- Persistence
- Public Typedefs
- Public Constructors
- Public Destructor
- Public Operators
- Accessors
- Const Public Member Functions
- Mutators
- Special Methods for Maps

#include <rw/rwstdex/hashmap.h> rw_hashmap<K,T,H,EQ,A=std::allocator<std::pair<const K,T>>>;

** rw_hashmap<K,T,H,EQ,A>** requires the Standard C++ Library.

Class ** rw_hashmap<K,T,H,EQ,A>** maintains a collection of mappings between

Since this is a *value* based collection, objects are *copied* into and out of the collection.

As with all classes that meet the ANSI *associative container* specification, ** rw_hashmap<K,T,H,EQ,A>** provides for iterators that reference its elements. Operations that alter the contents of

None

typedef Kkey_type; typedef Hashkey_hash; typedef EQkey_equal; typedef pair<K,V>value_type; // or ... "const K" typedef (unsigned)size_type; //from rw_slist<T,A> typedef (int)difference_type; // from rw_slist<T,A> typedef (value_type&)reference; typedef (const value_type&)const_reference; //from rw_slist<T,A>

Iterators over ** rw_hashmap<K,T,H,EQ,A>** are forward iterators.

typedef (scoped Iterator)iterator; typedef (scoped ConstIterator)const_iterator;

rw_hashmap<K,T,H,EQ,A>(size_type sz = 1024, const Hash& h = Hash(), const EQ& eq = EQ());

Constructs an empty ** rw_hashmap<K,T,H,EQ,A>** with

rw_hashmap<K,T,H,EQ,A>(const rw_hashmap<K,T, H,EQ,A>& map);

Constructs an ** rw_hashmap<K,T,H,EQ,A>** which is a copy of

rw_hashmap<K,T,H,EQ,A>(const_iterator first, const_iterator bound size_type sz=1024, const Hash& h = Hash(), const EQ& eq = EQ());

Constructs an ** rw_hashmap<K,T,H,EQ,A>** with

rw_hashmap<K,T,H,EQ,A>(const value_type* first, const value_type* bound size_type sz=1024, const Hash& h = Hash(), const EQ& eq = EQ());

Constructs an ** rw_hashmap<K,T,H,EQ,A>** with

~rw_hashmap<K,T,H,EQ,A>();

Releases the memory used by the container's implementation.

rw_hashmap<K,T,H,EQ,A>&operator=(const rw_hashmap<K,T,H,EQ,A>& rhs);

Sets self to have the same capacity, `Hash` and `EQ` as `rhs`, removes all self's current contents, and replaces them with copies of the elements in `rhs`.

booloperator==(const rw_hashmap<K,T,H,EQ,A> & rhs) const;

Returns `true` if self and `rhs` have the same number of elements, and for each `value_type` in self, there is a `value_type` in `rhs` that has a first part for which the `EQ` object in self returns true, and a second part for which `operator==()` returns true. The need to test both parts means that this operator is slightly slower than the method `equal_by_keys()` described below.

V&operator[](const key_type& key);

Returns a reference to the `V` part of a pair held in self which has a part `EQ` to `key`, either by finding such a pair, or inserting one (in which case the reference is to an instance of `V` created by its default constructor).

iteratorbegin();

The iterator returned references the first item in self. If self is empty, the iterator is equal to `end()`. Note that because items are stored in pseudo-random order, this iterator might reference any item that has been stored in self.

const_iteratorbegin() const;

The iterator returned references the first item in self. If self is empty, the iterator is equal to `end()`. Note that because items are stored in pseudo-random order, this iterator might reference any item that has been stored in self.

iteratorend();

The iterator returned marks the location "off the end" of self. It may not be dereferenced.

const_iteratorend() const;

The iterator returned marks the location "off the end" of self. It may not be dereferenced.

pair<const_iterator, const_iterator>equal_range(const key_type key) const;

Returns `pair<const_iterator, const_iterator>(lower_bound(key), upper_bound(key))`. Upper and lower bound have special meaning for hash-based collections. See discussion elsewhere.

pair<iterator, iterator>equal_range(const key_type key);

Returns `pair<iterator, iterator>(lower_bound(key), upper_bound(key))`. Upper and lower bound have special meaning for hash-based collections. See discussion elsewhere.

const_iteratorlower_bound(const key_type& key) const;

Returns the lower bound of `key` in self. This has a special meaning for hash-based collections. See discussion elsewhere.

iteratorlower_bound(const key_type& key);

Returns the lower bound of `key` in self. This has a special meaning for hash-based collections. See discussion elsewhere.

const_iteratorupper_bound(const key_type& key) const;

Returns the upper bound of `key` in self. This has a special meaning for hash-based collections. See discussion elsewhere.

iteratorupper_bound(const key_type& key);

Returns the upper bound of `key` in self. This has a special meaning for hash-based collections. See discussion elsewhere.

size_typecapacity() const;

Returns the number of slots in the hash table that self uses.

boolempty() const;

Returns `TRUE` if self is empty.

floatfill_ratio() const;

Returns the result of calculating `size()/capacity()`.

size_typesize() const;

Returns the number of pairs currently held in self.

voidclear();

A synonym for `erase(begin(),end());`

size_typeerase(const key_type& key);

If there is a pair in self for which the first part is `EQ` to `key`, that pair is removed, and `1` is returned. Otherwise, `0` is returned.

iteratorerase(iterator iter);

Removes the element referenced by `iter` and returns an iterator referencing the "next" element. If `iter` does not reference an item in self, the result is undefined.

iteratorerase(iterator first, iterator bound);

Removes each element in the range which begins with `first` and is bound by `bound`. Returns an iterator referencing `bound`. If `first` does not reference an item in self (and if `first` and `bound` are not equal), the effect is undefined.

pair<iterator,bool>insert(const value_type& val);

If there is no pair in self with first part `EQ` to the first part of `val` then inserts `val`, returning a pair with an iterator referencing the new element and true. Otherwise, returns a pair with an iterator referencing the matching `value_type` and false.

size_typeinsert(iterator ignore, const value_type& val);

If there is no pair in self with first part `EQ` to the first part of `val` then inserts `val`, returning `1`. Otherwise, does nothing and returns `0`. Note that the first argument is provided only for conformance with the ANSI *associative container* specification, and is ignored by the method, since hash table look up can be done in constant time.

size_typeinsert(const value_type* first, const value_type* bound);

For each element in the range beginning with `first` and bounded by `bound,` if there is no pair in self with first part `EQ` to the first part of that element, the element is copied into self, or if there is such a pair, the element is skipped. Returns the number of elements inserted.

size_typeinsert(const_iterator first, const_iterator bound);

For each element in the range beginning with `first` and bounded by `bound,` if there is no pair in self with first part `EQ` to the first part of that element, the element is copied into self, or if there is such a pair, the element is skipped. Returns the number of elements inserted.

voidswap(rw_hashmap<K,T,H,EQ,A>& other);

Exchanges the contents of self with `other` including the `Hash` and `EQ` objects. This method does not copy or destroy any of the items exchanged but exchanges the underlying hash tables.

size_typecount(const key_type& key) const;

Returns `1` if self contains a pair with its first element `EQ` to `key`, else `0`.

boolequal_by_keys(const rw_hashmap<K,T,H,EQ,A>& rhs) const;

Returns true if self and `rhs` have the same size, and if for each `value_type` in self, there is a `value_type` in `rhs` such that the `EQ` object in self returns true when called for the first parts of those pairs. Note that this method does not compare the `V` (second) part of the pair of the items, so it will run slightly faster than `operator==()`.

const_iteratorfind(const key_type& key) const;

Returns a `const_iterator` referencing the pair with `key` as its first element if such a pair is contained in self, else returns `end()`.

iteratorfind(const key_type& key);

Returns an iterator referencing the pair with `key` as its first element, if such a pair is contained in self, else returns `end()`.

voidresize(size_type sz);

Resizes self's hash table to have `sz` slots; and re-hashes all self's elements into the new table. Can be very expensive if self holds many elements.

©2004 Copyright Quovadx, Inc. All Rights Reserved.

Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.

Contact Rogue Wave about documentation or support issues.