diff --git a/Jupiter/Hash_Table.h b/Jupiter/Hash_Table.h index 38fb0f6..5f58e12 100644 --- a/Jupiter/Hash_Table.h +++ b/Jupiter/Hash_Table.h @@ -71,6 +71,7 @@ namespace Jupiter */ ValueT *get(const InKeyT &in_key) const; const InValueT &get(const InKeyT &in_key, const InValueT &in_value) const; + template CastT getCast(const InKeyT &in_key, const CastT &in_value) const; /** * @brief Sets the value for an entry in the bucket @@ -168,6 +169,7 @@ namespace Jupiter */ ValueT *get(const InKeyT &in_key) const; const InValueT &get(const InKeyT &in_key, const InValueT &in_value) const; + template CastT getCast(const InKeyT &in_key, const CastT &in_value) const; /** * @brief Sets the value for an entry in the table diff --git a/Jupiter/Hash_Table_Imp.h b/Jupiter/Hash_Table_Imp.h index 3baad04..8f3eaab 100644 --- a/Jupiter/Hash_Table_Imp.h +++ b/Jupiter/Hash_Table_Imp.h @@ -88,6 +88,17 @@ const InValueT &Jupiter::Hash_Table::Buck return in_value; } +template +template +CastT Jupiter::Hash_Table::Bucket::getCast(const InKeyT &in_key, const CastT &in_value) const +{ + for (Jupiter::SLList::Node *node = m_entries.getHead(); node != nullptr; node = node->next) + if (node->data->key == in_key) + return static_cast(node->data->value); + + return in_value; +} + template bool Jupiter::Hash_Table::Bucket::set(const InKeyT &in_key, const InValueT &in_value) { @@ -223,6 +234,13 @@ const InValueT &Jupiter::Hash_Table::get( return m_buckets[HashF(in_key) % m_buckets_size].get(in_key, in_value); } +template +template +CastT Jupiter::Hash_Table::getCast(const InKeyT &in_key, const CastT &in_value) const +{ + return m_buckets[HashF(in_key) % m_buckets_size].getCast(in_key, in_value); +} + template bool Jupiter::Hash_Table::set(const InKeyT &in_key, const InValueT &in_value) {