命名空间
变体
操作

operator==,!=(std::unordered_multiset)

来自 cppreference.cn
 
 
 
 
template< class Key, class Hash, class KeyEqual, class Alloc >

bool operator==( const std::unordered_multiset<Key, Hash, KeyEqual, Alloc>& lhs,

                 const std::unordered_multiset<Key, Hash, KeyEqual, Alloc>& rhs );
(1)
template< class Key, class Hash, class KeyEqual, class Alloc >

bool operator!=( const std::unordered_multiset<Key, Hash, KeyEqual, Alloc>& lhs,

                 const std::unordered_multiset<Key, Hash, KeyEqual, Alloc>& rhs );
(2) (C++20 前)

比较两个无序容器的内容。

当满足以下条件时,两个无序容器 lhsrhs 的内容相等:

  • lhs.size() == rhs.size().
  • 对于从 lhs.equal_range(lhs_eq1) 获得的每个等效元素组 [lhs_eq1lhs_eq2),在另一个容器中有一个对应的等效元素组 [rhs_eq1rhs_eq2),该组从 rhs.equal_range(rhs_eq1) 获得,并具有以下属性:

如果 Key 不是 EqualityComparable,则行为未定义。

如果 hash_function()key_eq()(直到 C++20)key_eq()(自 C++20 起)lhsrhs 上行为不一致,或者如果 Keyoperator== 不是由 key_eq() 引入的等效键组分区的细化(即,如果使用 operator== 比较相等的两个元素落入不同的分区),则行为也未定义。

!= 运算符由 operator== 合成

(C++20 起)

[编辑] 参数

lhs, rhs - 要比较的无序容器

[编辑] 返回值

1) 如果容器的内容相等,则为 true,否则为 false
2) 如果容器的内容不相等,则为 true,否则为 false

[编辑] 复杂度

在平均情况下,与对 value_type 调用 operator== 的次数、对 key_eq 返回的谓词的调用次数以及对 hash_function 返回的哈希函数的调用次数成比例,其中 S 是第 i 个等效键组的大小。在最坏情况下,与 N2 成比例,其中 N 是容器的大小。如果每个等效键组中的元素按相同顺序排列(当容器是彼此的副本时发生),则平均情况与 N 成比例。