summaryrefslogtreecommitdiff
path: root/include/fud_hash_map.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/fud_hash_map.hpp')
-rw-r--r--include/fud_hash_map.hpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/include/fud_hash_map.hpp b/include/fud_hash_map.hpp
index 4333df7..7980bf4 100644
--- a/include/fud_hash_map.hpp
+++ b/include/fud_hash_map.hpp
@@ -156,8 +156,25 @@ class HashMap {
Option<KeyValuePair> extractPair(const Key& key);
Option<KeyValuePair> extractPair(Key& key);
- Option<Value> get(const Key& key) const;
- Option<Value&> getRef(const Key& key);
+ Option<Value> get(const Key& key)
+ {
+ auto hashIndexOption = lookup(key);
+ if (hashIndexOption.isNone()) {
+ return NullOpt;
+ }
+
+ return m_data[hashIndexOption.value()].value().m_value;
+ }
+
+ Option<Value&> getRef(const Key& key) const
+ {
+ auto hashIndexOption = lookup(key);
+ if (hashIndexOption.isNone()) {
+ return NullOpt;
+ }
+
+ return m_data[hashIndexOption.value()].value().m_value;
+ }
Option<const Value&> getConstRef(const Key& key) const
{
@@ -206,8 +223,7 @@ class HashMap {
return dataPtrResult.takeError();
}
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- auto* dataPtr = reinterpret_cast<Node*>(dataPtrResult.takeOkay());
+ auto* dataPtr = std::bit_cast<Node*>(dataPtrResult.takeOkay());
for (size_t index = 0; index < count; ++index) {
const auto* ptr = new (dataPtr + index) Node(NullOpt);
fudAssert(ptr != nullptr);
@@ -219,8 +235,7 @@ class HashMap {
const auto hash = m_hasher(key, m_seed);
auto newHashIndexResult = findEmptyBucket(key, count, dataPtr);
if (newHashIndexResult.isError()) {
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- m_allocator->deallocate(reinterpret_cast<std::byte*>(dataPtr), requestedSize);
+ m_allocator->deallocate(std::bit_cast<std::byte*>(dataPtr), requestedSize);
return FudStatus::Failure;
}
const auto newHashIndex{newHashIndexResult.takeOkay()};
@@ -233,8 +248,7 @@ class HashMap {
auto status = FudStatus::Success;
if (m_buckets > 0) {
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- m_allocator->deallocate(reinterpret_cast<std::byte*>(m_data), m_buckets * NodeSize);
+ m_allocator->deallocate(std::bit_cast<std::byte*>(m_data), m_buckets * NodeSize);
}
m_data = dataPtr;
@@ -295,8 +309,7 @@ class HashMap {
{
auto status = clear();
if (m_data != nullptr && m_allocator != nullptr) {
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- m_allocator->deallocate(reinterpret_cast<std::byte*>(m_data), m_buckets);
+ m_allocator->deallocate(std::bit_cast<std::byte*>(m_data), m_buckets);
}
m_allocator = nullptr;