util/IntrusiveHashSet: add const
overloads
This commit is contained in:
parent
8860962e09
commit
e3ef0929f1
@ -134,6 +134,7 @@ class IntrusiveHashSet {
|
|||||||
std::array<Bucket, table_size> table;
|
std::array<Bucket, table_size> table;
|
||||||
|
|
||||||
using bucket_iterator = typename Bucket::iterator;
|
using bucket_iterator = typename Bucket::iterator;
|
||||||
|
using const_bucket_iterator = typename Bucket::const_iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
@ -248,10 +249,24 @@ public:
|
|||||||
return end();
|
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 {
|
constexpr bucket_iterator end() noexcept {
|
||||||
return table.front().end();
|
return table.front().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr const_bucket_iterator end() const noexcept {
|
||||||
|
return table.front().end();
|
||||||
|
}
|
||||||
|
|
||||||
constexpr void for_each(auto &&f) {
|
constexpr void for_each(auto &&f) {
|
||||||
for (auto &bucket : table)
|
for (auto &bucket : table)
|
||||||
for (auto &i : bucket)
|
for (auto &i : bucket)
|
||||||
@ -272,4 +287,12 @@ private:
|
|||||||
const auto h = hash(std::forward<K>(key));
|
const auto h = hash(std::forward<K>(key));
|
||||||
return table[h % table_size];
|
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];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user