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的比较相等函数 #166

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

hashtable的比较相等函数 #166

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

Comments

@Peas-Li
Copy link

Peas-Li commented Nov 2, 2024

// comparision 应该声明为公有,且const,不然hashmap和hashset的友元重载==函数无法调用私有函数,而且因为他们的参数都是const,因此声明为const
bool equal_to_multi(const hashtable& other) const;
bool equal_to_unique(const hashtable& other) const;

此外hashmap和hashset的重载函数都调用错了函数,应该调用的是equal_to_multi或者equal_to_unique,而不是equal_range_unique
public:
friend bool operator==(const unordered_set& lhs, const unordered_set& rhs)
{
return lhs.ht_.equal_range_unique(rhs.ht_);
}
friend bool operator!=(const unordered_set& lhs, const unordered_set& rhs)
{
return !lhs.ht_.equal_range_unique(rhs.ht_);
}
};

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