Browse Source

Hash_Table: Added getCast

release/0.19
Jessica James 8 years ago
parent
commit
16e822f3e7
  1. 2
      Jupiter/Hash_Table.h
  2. 18
      Jupiter/Hash_Table_Imp.h

2
Jupiter/Hash_Table.h

@ -71,6 +71,7 @@ namespace Jupiter
*/ */
ValueT *get(const InKeyT &in_key) const; ValueT *get(const InKeyT &in_key) const;
const InValueT &get(const InKeyT &in_key, const InValueT &in_value) const; const InValueT &get(const InKeyT &in_key, const InValueT &in_value) const;
template<typename CastT> CastT getCast(const InKeyT &in_key, const CastT &in_value) const;
/** /**
* @brief Sets the value for an entry in the bucket * @brief Sets the value for an entry in the bucket
@ -168,6 +169,7 @@ namespace Jupiter
*/ */
ValueT *get(const InKeyT &in_key) const; ValueT *get(const InKeyT &in_key) const;
const InValueT &get(const InKeyT &in_key, const InValueT &in_value) const; const InValueT &get(const InKeyT &in_key, const InValueT &in_value) const;
template<typename CastT> CastT getCast(const InKeyT &in_key, const CastT &in_value) const;
/** /**
* @brief Sets the value for an entry in the table * @brief Sets the value for an entry in the table

18
Jupiter/Hash_Table_Imp.h

@ -88,6 +88,17 @@ const InValueT &Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::Buck
return in_value; return in_value;
} }
template<typename KeyT, typename ValueT, typename InKeyT, typename InValueT, size_t(*HashF)(const InKeyT &)>
template<typename CastT>
CastT Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::Bucket::getCast(const InKeyT &in_key, const CastT &in_value) const
{
for (Jupiter::SLList<Entry>::Node *node = m_entries.getHead(); node != nullptr; node = node->next)
if (node->data->key == in_key)
return static_cast<CastT>(node->data->value);
return in_value;
}
template<typename KeyT, typename ValueT, typename InKeyT, typename InValueT, size_t(*HashF)(const InKeyT &)> template<typename KeyT, typename ValueT, typename InKeyT, typename InValueT, size_t(*HashF)(const InKeyT &)>
bool Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::Bucket::set(const InKeyT &in_key, const InValueT &in_value) bool Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::Bucket::set(const InKeyT &in_key, const InValueT &in_value)
{ {
@ -223,6 +234,13 @@ const InValueT &Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::get(
return m_buckets[HashF(in_key) % m_buckets_size].get(in_key, in_value); return m_buckets[HashF(in_key) % m_buckets_size].get(in_key, in_value);
} }
template<typename KeyT, typename ValueT, typename InKeyT, typename InValueT, size_t(*HashF)(const InKeyT &)>
template<typename CastT>
CastT Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::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<typename KeyT, typename ValueT, typename InKeyT, typename InValueT, size_t(*HashF)(const InKeyT &)> template<typename KeyT, typename ValueT, typename InKeyT, typename InValueT, size_t(*HashF)(const InKeyT &)>
bool Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::set(const InKeyT &in_key, const InValueT &in_value) bool Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::set(const InKeyT &in_key, const InValueT &in_value)
{ {

Loading…
Cancel
Save