Fix HashTable::operator->.

This commit is contained in:
levlam 2022-03-11 13:34:36 +03:00
parent a0a135dbda
commit acf30d3700
3 changed files with 25 additions and 2 deletions

View File

@ -156,7 +156,7 @@ class FlatHashTableChunks {
return it_->get_public();
}
pointer operator->() {
return &*it_;
return &it_->get_public();
}
bool operator==(const Iterator &other) const {
DCHECK(map_ == other.map_);

View File

@ -71,7 +71,7 @@ class FlatHashTable {
return it_->get_public();
}
pointer operator->() {
return &*it_;
return &it_->get_public();
}
NodeT *get() {
return it_;

View File

@ -77,6 +77,29 @@ TEST(FlatHashMap, probing) {
test(8192, static_cast<int>(8192 * 0.3));
}
struct A {
int a;
};
struct AHash {
std::size_t operator()(A a) const {
return std::hash<int>()(a.a);
}
};
static bool operator==(const A &lhs, const A &rhs) {
return lhs.a == rhs.a;
}
TEST(FlatHashSet, foreach) {
td::FlatHashSet<A, AHash> s;
for (auto it : s) {
LOG(ERROR) << it.a;
}
s.insert({1});
LOG(INFO) << s.begin()->a;
}
TEST(FlatHashSet, TL) {
td::FlatHashSet<int> s;
int N = 100000;