Erases the element pointed to by pos.
size_type erase(const key_type& k) Associative Container Erases the element whose key is k.
void erase(iterator first, iterator last) Associative Container Erases all elements in a range.
void clear() Associative Container Erases all of the elements.
iterator find(const key_type& k) const Associative Container Finds an element whose key is k.
size_type count(const key_type& k) const Unique Associative Container Counts the number of elements whose key is k.
pair<iterator, iterator> equal_range(const key_type& k) const Associative Container Finds a range containing all elements whose key is k.
bool operator==(const hash_set&, const hash_set&) Hashed Associative Container Tests two hash_sets for equality. This is a global function, not a member function.
New members

All of hash_set's members are defined in the Unique Hashed Associative Container and Simple Associative Container requirements. Hash_set does not introduce any new members.

Notes

[1] 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_set::const_iterator.

See also

Associative Container, Hashed Associative Container, Simple Associative Container, Unique Hashed Associative Container, set, map, multiset, multimap, hash_map, hash_multiset, hash_multimap

hash_map<Key, Data, HashFcn, EqualKey, Alloc>

Category: containers

Component type: type

Description

Hash_map is a Hashed Associative Container that associates objects of type Key with objects of type Data. Hash_map is a Pair Associative Container, meaning that its value type is pair<const Key, Data>. It is also a Unique Associative Container, meaning that no two elements have keys that compare equal using EqualKey.

Looking up an element in a hash_map by its key is efficient, so hash_map 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 map is more appropriate.

Example

struct eqstr {

 bool operator()(const char* s1, const char* s2) const {

  return strcmp(s1, s2) == 0;

 }

};

int main() {

 hash_map<const char*, int, hash<const char*>, eqstr> months;

 months['january'] = 31;

 months['february'] = 28;

 months['march'] = 31;

 months['april'] = 30;

 months['may'] = 31;

 months['june'] = 30;

 months['july'] = 31;

 months['august'] = 31;

 months['september'] = 30;

 months['october'] = 31;

 months['november'] = 30;

 months['december'] = 31;

 cout << 'september –> ' << months['september'] << endl;

 cout << 'april –> ' << months['april'] << endl;

 cout << 'june –> ' << months['june'] << endl;

 cout << 'november –> ' << months['november'] << endl;

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату