Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashtable的判断相等 #165

Open
Peas-Li opened this issue Nov 1, 2024 · 0 comments
Open

hashtable的判断相等 #165

Peas-Li opened this issue Nov 1, 2024 · 0 comments

Comments

@Peas-Li
Copy link

Peas-Li commented Nov 1, 2024

template <class T, class Hash, class KeyEqual>
bool hashtable<T, Hash, KeyEqual>::equal_to_multi(const hashtable& other)
{
if (size_ != other.size_)
return false;
for (auto f = begin(), l = end(); f != l;)
{
auto p1 = equal_range_multi(value_traits::get_key(*f));
auto p2 = other.equal_range_multi(value_traits::get_key(*f));
if (mystl::distance(p1.first, p1.last) != mystl::distance(p2.first, p2.last) ||
!mystl::is_permutation(p1.first, p2.last, p2.first, p2.last))
return false;
f = p1.last;
}
return true;
}

只判断了other包含了该hashtable中所有的元素,应该继续判断该hashtable是否包含了other中所有的元素,互相包含才相等。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant