size_type count(const key_type& k) const | Unique Associative Container | Counts the number of elements whose key is k. |
pair<const_iterator, const_iterator> equal_range(const key_type& k) const | Associative Container | Finds a range containing all elements whose key is k. |
pair<iterator, iterator> equal_range(const key_type& k) | Associative Container | Finds a range containing all elements whose key is k. |
data_type& operator[](const key_type& k) [3] | hash_map | See below. |
bool operator==(const hash_map&, const hash_map&) | Hashed Associative Container | Tests two hash_maps for equality. This is a global function, not a member function. |
New members These members are not defined in the Unique Hashed Associative Container and Pair Associative Container requirements, but are specific to hash_map.
| Member | Description |
data_type& operator[](const key_type& k) [3] | Returns a reference to the object that is associated with a particular key. If the hash_map does not already contain such an object, operator[] inserts the default object data_type(). [3] |
Notes [1] Hash_map::iterator is not a mutable iterator, because hash_map::value_type is not Assignable. That is, if i is of type hash_map::iterator and p is of type hash_map::value_type, then *i = p is not a valid expression. However, hash_map::iterator isn't a constant iterator either, because it can be used to modify the object that it points to. Using the same notation as above, (*i).second = p is a valid expression.
[2] This member function relies on member template functions, which at present (early 1998) are not supported by all compilers. If your compiler supports member templates, you can call this function with any type of input iterator. If your compiler does not yet support member templates, though, then the arguments must either be of type const value_type* or of type hash_map::const_iterator.
[3] Since operator[] might insert a new element into the hash_map, it can't possibly be a const member function. Note that the definition of operator[] is extremely simple: m[k] is equivalent to (*((m.insert(value_type(k, data_type()))).first)).second. Strictly speaking, this member function is unnecessary: it exists only for convenience.
See also Associative Container, Hashed Associative Container, Pair Associative Container, Unique Hashed Associative Container, set, map, multiset, multimap, hash_set, hash_multiset, hash_multimap
hash_multiset<Key, HashFcn, EqualKey, Alloc>
Category: containers
Component type: type
Description Hash_multiset is a Hashed Associative Container that stores objects of type Key. Hash_multiset is a simple associative container, meaning that its value type, as well as its key type, is Key. It is also a Multiple Associative Container, meaning that two or more elements may compare equal using the Binary Predicate EqualKey.
Hash_multiset is useful in applications where it is important to be able to search for an element quickly. If it is important for the elements to be in a particular order, however, then multiset is more appropriate.
Example struct eqstr {
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1, s2) == 0;
}
};
void lookup(const hash_multiset<const char*, hash<const char*>, eqstr>& Set, const char* word) {
int n_found = Set.count(word);
cout << word << ': ' << n_found << ' ' << (n_found == 1 ? 'instance' : 'instances') << endl;
}