util/IntrusiveHashSet: add const overloads

This commit is contained in:
Max Kellermann 2022-11-30 09:04:56 +01:00 committed by Max Kellermann
parent 8860962e09
commit e3ef0929f1

View File

@ -134,6 +134,7 @@ class IntrusiveHashSet {
std::array<Bucket, table_size> table;
using bucket_iterator = typename Bucket::iterator;
using const_bucket_iterator = typename Bucket::const_iterator;
public:
using value_type = T;
@ -248,10 +249,24 @@ public:
return end();
}
[[nodiscard]] [[gnu::pure]]
constexpr const_bucket_iterator find(const auto &key) const noexcept {
auto &bucket = GetBucket(key);
for (auto &i : bucket)
if (equal(key, i))
return bucket.iterator_to(i);
return end();
}
constexpr bucket_iterator end() noexcept {
return table.front().end();
}
constexpr const_bucket_iterator end() const noexcept {
return table.front().end();
}
constexpr void for_each(auto &&f) {
for (auto &bucket : table)
for (auto &i : bucket)
@ -272,4 +287,12 @@ private:
const auto h = hash(std::forward<K>(key));
return table[h % table_size];
}
template<typename K>
[[gnu::pure]]
[[nodiscard]]
constexpr const auto &GetBucket(K &&key) const noexcept {
const auto h = hash(std::forward<K>(key));
return table[h % table_size];
}
};