|
ALINK="#ff0000">
hash_multimap<Key, Data, HashFcn, EqualKey, Alloc>
DescriptionHash_multimap is a Hashed Associative Container that associates objects of type Key with objects of type Data. Hash_multimap is a Pair Associative Container, meaning that its value type is pair<const Key, Data>. It is also a Multiple Associative Container, meaning that there is no limit on the number of elements whose keys may compare equal using EqualKey.Looking up an element in a hash_multimap by its key is efficient, so hash_multimap is useful for "dictionaries" where the order of elements is irrelevant. If it is important for the elements to be in a particular order, however, then multimap is more appropriate. Examplestruct eqstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; } }; typedef hash_multimap<const char*, int, hash<const char*>, eqstr> map_type; void lookup(const map_type& Map, const char* str) { cout << str << ": "; pair<map_type::const_iterator, map_type::const_iterator> p = Map.equal_range(str); for (map_type::const_iterator i = p.first; i != p.second; ++i) cout << (*i).second << " "; cout << endl; } int main() { map_type M; M.insert(map_type::value_type("H", 1)); M.insert(map_type::value_type("H", 2)); M.insert(map_type::value_type("C", 12)); M.insert(map_type::value_type("C", 13)); M.insert(map_type::value_type("O", 16)); M.insert(map_type::value_type("O", 17)); M.insert(map_type::value_type("O", 18)); M.insert(map_type::value_type("I", 127)); lookup(M, "I"); lookup(M, "O"); lookup(M, "Rn"); } DefinitionDefined in the header hash_map, and in the backward-compatibility header hash_map.h. This class is an SGI extension; it is not part of the C++ standard.Template parameters
Model ofMultiple Hashed Associative Container, Pair Associative ContainerType requirements
Public base classesNone.Members
New membersAll of hash_multimap's members are defined in the Multiple Hashed Associative Container and Pair Associative Container requirements. Hash_multimap does not introduce any new members.Notes[1] Hash_multimap::iterator is not a mutable iterator, because hash_multimap::value_type is not Assignable. That is, if i is of type hash_multimap::iterator and p is of type hash_multimap::value_type, then *i = p is not a valid expression. However, hash_multimap::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_multimap::const_iterator. See alsoAssociative Container, Hashed Associative Container, Pair Associative Container, Multiple Hashed Associative Container, set, map, multiset, multimap, hash_set, hash_map, hash_multisetCopyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|