modify the object that it points to. Using the same notation as above, (*i).second = p is a valid expression. The same point applies to multimap::reverse_iterator.

[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 multimap::const_iterator.

See also

Associative Container, Sorted Associative Container, Pair Associative Container, Multiple Sorted Associative Container, set, map, multiset, hash_set, hash_map, hash_multiset, hash_multimap

hash_set<Key, HashFcn, EqualKey, Alloc>

Category: containers

Component type: type

Description

Hash_set is a Hashed Associative Container that stores objects of type Key. Hash_set is a Simple Associative Container, meaning that its value type, as well as its key type, is Key. It is also a Unique Associative Container, meaning that no two elements compare equal using the Binary Predicate EqualKey.

Hash_set 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 set is more appropriate.

Example

struct eqstr {

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

  return strcmp(s1, s2) == 0;

 }

};

void lookup(const hash_set<const char*, hash<const char*>, eqstr>& Set, const char* word) {

 hash_set<const char*, hash<const char*>, eqstr>::const_iterator it = Set.find (word);

 cout << word << ': ' << (it != Set.end() ? 'present' : 'not present') << endl;

}

int main() {

 hash_set<const char*, hash<const char*>, eqstr> Set;

 Set.insert('kiwi');

 Set.insert('plum');

 Set.insert('apple');

 Set.insert('mango');

 Set.insert('apricot');

 Set.insert('banana');

 lookup(Set, 'mango');

 lookup(Set, 'apple');

 lookup(Set, 'durian');

}

Definition

Defined in the header hash_set, and in the backward-compatibility header hash_set.h. This class is an SGI extension; it is not part of the C++ standard.

Template parameters
Parameter Description Default
Key The hash_set's key type and value type. This is also defined as hash_set::key_type and hash_set::value_type
HashFcn The Hash Function used by the hash_set. This is also defined as hash_set::hasher. hash<Key>
EqualKey The hash_set's key equality function: a binary predicate that determines whether two keys are equal. This is also defined as hash_set::key_equal. equal_to<Key>
Alloc The hash_set 's allocator, used for all internal memory management. alloc
Model of

Unique Hashed Associative Container, Simple Associative Container

Type requirements

• Key is Assignable.

• EqualKey is a Binary Predicate whose argument type is Key.

• EqualKey is an equivalence relation.

• Alloc is an Allocator.

Public base classes

None.

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

0

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

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