| 类别:容器 | 组件类型:类型 |
Hash_multiset比较两个或多个元素是否相等。在需要快速搜索元素的应用中非常有用。但是,如果元素需要按特定顺序排列,则multiset更合适。
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;
}
int main()
{
hash_multiset<const char*, hash<const char*>, eqstr> Set;
Set.insert("mango");
Set.insert("kiwi");
Set.insert("apple");
Set.insert("kiwi");
Set.insert("mango");
Set.insert("mango");
Set.insert("apricot");
Set.insert("banana");
Set.insert("mango");
lookup(Set, "mango");
lookup(Set, "apple");
lookup(Set, "durian");
}
| 参数 | 描述 | 默认值 |
|---|---|---|
| Key | hash_multiset的键类型和值类型。这也定义为hash_multiset::key_type和hash_multiset::value_type | |
| HashFcn | hash_multiset使用的哈希函数。这也定义为hash_multiset::hasher. | hash<Key> |
| EqualKey | hash_multiset的键相等函数:一个二元谓词,用于确定两个键是否相等。这也定义为hash_multiset::key_equal. | equal_to<Key> |
| Alloc | 用于所有内部内存管理的hash_multiset的分配器。 | alloc |
| 成员 | 定义位置 | 描述 |
|---|---|---|
| value_type | 容器 | 对象类型,T,存储在hash_multiset中。 |
| key_type | 关联容器 | 与value_type. |
| hasher | 哈希关联容器 | 用于所有内部内存管理的hash_multiset的哈希函数关联的键类型。 |
| key_equal | 哈希关联容器 | 比较键是否相等的函数对象。 |
| pointer | 容器 | 指向T. |
| reference | 容器 | 引用T |
| const_reference | 容器 | 常量引用T |
| size_type | 容器 | 无符号整数类型。 |
| difference_type | 容器 | 有符号整数类型。 |
| iterator | 容器 | 用于迭代hash_multiset. |
| const_iterator | 容器 | 用于迭代hash_multiset. (迭代器和const_iterator(是相同的类型)。 |
| iterator begin() const | 容器 | 返回一个iterator指向hash_multiset. |
| iterator end() const | 容器 | 返回一个iterator指向hash_multiset. |
| size_type size() const | 容器 | 返回hash_multiset. |
| size_type max_size() const | 容器 | 返回hash_multiset. |
| bool empty() const | 容器 | true如果hash_multiset的大小为0. |
| size_type bucket_count() const | 哈希关联容器 | 返回hash_multiset. |
| void resize(size_type n) | 哈希关联容器 | 将桶的数量增加到至少n. |
| hasher hash_funct() const | 哈希关联容器 | 返回hasher对象,该对象由hash_multiset. |
| key_equal key_eq() const | 哈希关联容器 | 返回key_equal对象,该对象由hash_multiset. |
| hash_multiset() | 容器 | 创建一个空的hash_multiset. |
| hash_multiset(size_type n) | 哈希关联容器 | 创建一个空的hash_multiset至少有n个桶。 |
hash_multiset(size_type n,
const hasher& h)
|
哈希关联容器 | 创建一个空的hash_multiset至少有n个桶,使用h作为哈希函数。 |
hash_multiset(size_type n,
const hasher& h,
const key_equal& k)
|
哈希关联容器 | 创建一个空的hash_multiset至少有n个桶,使用h作为哈希函数,以及k作为键相等函数。 |
template <class InputIterator> hash_multiset(InputIterator, InputIterator) [1] |
多重哈希关联容器 | 创建一个包含范围副本的hash_multiset。 |
template <class InputIterator> hash_multiset(InputIterator, InputIterator, size_type n) [1] |
多重哈希关联容器 | 创建一个包含范围副本的hash_multiset,并至少有n. |
template <class InputIterator> hash_multiset(InputIterator, InputIterator, size_type n, const hasher& h) [1] |
多重哈希关联容器 | 创建一个包含范围副本的hash_multiset,并至少有n个桶,使用h作为哈希函数。 |
template <class InputIterator> hash_multiset(InputIterator, InputIterator, size_type n, const hasher& h, const key_equal& k) [1] |
多重哈希关联容器 | 创建一个包含范围副本的hash_multiset,并至少有n个桶,使用h作为哈希函数,以及k作为键相等函数。 |
| hash_multiset(const hash_multiset&) | 容器 | 复制构造函数。 |
| hash_multiset& operator=(const hash_multiset&) | 容器 | 赋值运算符 |
| void swap(hash_multiset&) | 容器 | 交换两个hash_multiset的内容。 |
| iterator insert(const value_type& x) | 多重关联容器 | 将x插入到hash_multiset. |
template <class InputIterator> void insert(InputIterator, InputIterator) [1] |
多重关联容器 | 将一个范围插入到hash_multiset. |
| void erase(iterator pos) | 关联容器 | 擦除pos. |
| 所指向的元素。 | 关联容器 | size_type erase(const key_type& k)k. |
| 擦除键为 | 关联容器 | void erase(iterator first, iterator last) |
| 擦除范围内的所有元素。 | 关联容器 | void clear() |
| 擦除所有元素。 | 关联容器 | iterator find(const key_type& k) constk. |
| 查找键为 | 关联容器 | size_type count(const key_type& k) constk. |
pair<iterator, iterator> equal_range(const key_type& k) const |
关联容器 | 查找键为k. |
bool operator==(const hash_multiset&,
const hash_multiset&)
|
哈希关联容器 | 测试两个hash_multiset是否相等。这是一个全局函数,而不是成员函数。 |
[1] 此成员函数依赖于成员模板函数,目前(1998年初)并非所有编译器都支持。如果您的编译器支持成员模板,则可以使用任何类型的输入迭代器调用此函数。但是,如果您的编译器尚不支持成员模板,则参数必须是类型为const value_type*或类型为hash_multiset::const_iterator.