From bf5edc7c03b9f0921a0ace71390a5c357d11e5a6 Mon Sep 17 00:00:00 2001 From: Jessica James Date: Tue, 20 Dec 2016 00:27:28 -0500 Subject: [PATCH] Hash_Table: Added callback() --- Jupiter/Hash_Table.h | 18 ++++++++++++++++++ Jupiter/Hash_Table_Imp.h | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Jupiter/Hash_Table.h b/Jupiter/Hash_Table.h index 8d89bb8..38fb0f6 100644 --- a/Jupiter/Hash_Table.h +++ b/Jupiter/Hash_Table.h @@ -90,6 +90,15 @@ namespace Jupiter */ 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 void callback(CallT &in_callback) const; + /** * @brief Erases all entries from the bucket * @@ -178,6 +187,15 @@ namespace Jupiter */ 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 void callback(CallT &in_callback) const; + /** * @brief Returns the number of entries in the table * diff --git a/Jupiter/Hash_Table_Imp.h b/Jupiter/Hash_Table_Imp.h index d5c78bb..3baad04 100644 --- a/Jupiter/Hash_Table_Imp.h +++ b/Jupiter/Hash_Table_Imp.h @@ -144,6 +144,14 @@ bool Jupiter::Hash_Table::Bucket::remove( return false; } +template +template +void Jupiter::Hash_Table::Bucket::callback(CallT &in_callback) const +{ + for (Jupiter::SLList::Node *node = m_entries.getHead(); node != nullptr; node = node->next) + in_callback(*node->data); +} + template size_t Jupiter::Hash_Table::Bucket::erase() { @@ -255,6 +263,20 @@ bool Jupiter::Hash_Table::remove(const In return false; } +template +template +void Jupiter::Hash_Table::callback(CallT &in_callback) const +{ + Bucket *itr = m_buckets; + Bucket *end = m_buckets + m_buckets_size; + + while (itr != end) + { + itr->callback(in_callback); + ++itr; + } +} + template size_t Jupiter::Hash_Table::size() const {