Browse Source

Hash_Table: Added callback()

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

18
Jupiter/Hash_Table.h

@ -90,6 +90,15 @@ namespace Jupiter
*/ */
bool remove(const InKeyT &in_key); bool remove(const InKeyT &in_key);
/**
* @brief Calls a function for each Entry in the table, passing each Entry as a parameter
*
* @param CallT Function type to call
*
* @param in_callback Function to callback
*/
template<typename CallT> void callback(CallT &in_callback) const;
/** /**
* @brief Erases all entries from the bucket * @brief Erases all entries from the bucket
* *
@ -178,6 +187,15 @@ namespace Jupiter
*/ */
bool remove(const InKeyT &in_key); bool remove(const InKeyT &in_key);
/**
* @brief Calls a function for each Entry in the table, passing each Entry as a parameter
*
* @param CallT Function type to call
*
* @param in_callback Function to callback
*/
template<typename CallT> void callback(CallT &in_callback) const;
/** /**
* @brief Returns the number of entries in the table * @brief Returns the number of entries in the table
* *

22
Jupiter/Hash_Table_Imp.h

@ -144,6 +144,14 @@ bool Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::Bucket::remove(
return false; return false;
} }
template<typename KeyT, typename ValueT, typename InKeyT, typename InValueT, size_t(*HashF)(const InKeyT &)>
template<typename CallT>
void Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::Bucket::callback(CallT &in_callback) const
{
for (Jupiter::SLList<Entry>::Node *node = m_entries.getHead(); node != nullptr; node = node->next)
in_callback(*node->data);
}
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 &)>
size_t Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::Bucket::erase() size_t Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::Bucket::erase()
{ {
@ -255,6 +263,20 @@ bool Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::remove(const In
return false; return false;
} }
template<typename KeyT, typename ValueT, typename InKeyT, typename InValueT, size_t(*HashF)(const InKeyT &)>
template<typename CallT>
void Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::callback(CallT &in_callback) const
{
Bucket *itr = m_buckets;
Bucket *end = m_buckets + m_buckets_size;
while (itr != end)
{
itr->callback<CallT>(in_callback);
++itr;
}
}
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 &)>
size_t Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::size() const size_t Jupiter::Hash_Table<KeyT, ValueT, InKeyT, InValueT, HashF>::size() const
{ {

Loading…
Cancel
Save