diff options
Diffstat (limited to 'ace/Hash_Map_Manager_RT_T.cpp')
-rw-r--r-- | ace/Hash_Map_Manager_RT_T.cpp | 352 |
1 files changed, 187 insertions, 165 deletions
diff --git a/ace/Hash_Map_Manager_RT_T.cpp b/ace/Hash_Map_Manager_RT_T.cpp index 62000df2e33..c34bd819162 100644 --- a/ace/Hash_Map_Manager_RT_T.cpp +++ b/ace/Hash_Map_Manager_RT_T.cpp @@ -28,10 +28,10 @@ #include "Synch.h" #include "Service_Config.h" #include "Malloc.h" -#include <string.h> +#include <string.h> ACE_RCSID(ace, Hash_Map_Manager_RT_T, "$Id$") - + //***************************************************************/ ACE_Hash_Map_RT_Coord::ACE_Hash_Map_RT_Coord (int table, @@ -47,33 +47,33 @@ ACE_Hash_Map_RT_Coord::~ACE_Hash_Map_RT_Coord (void) //***************************************************************/ -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>::ACE_Hash_Map_RT_Hash_Function (int number_of_tables, +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_Hash_Function (int number_of_tables, int buckets_per_table) : max_tables_ (number_of_tables), buckets_per_table_ (buckets_per_table) { } -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>::~ACE_Hash_Map_RT_Hash_Function (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_Hash_Function (void) { } -template <class EXT_ID, class INT_ID, class HASH_KEY> int -ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>::hash (const EXT_ID& ext_id, +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int +ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::hash (const EXT_ID& ext_id, ACE_Hash_Map_RT_Coord& coord) { int hashCode = hash_key_ (ext_id); if ( hashCode < 0 ) hashCode *= -1; - + this->hash_i (hashCode, coord); - + return 0; } -template <class EXT_ID, class INT_ID, class HASH_KEY> int -ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>::hash_i (int key, +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int +ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::hash_i (int key, ACE_Hash_Map_RT_Coord& coord) { // Have you thought about precisions in all the platforms that @@ -81,95 +81,95 @@ ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>::hash_i (int key, double prod = (key * 0.618033988) - (size_t)(key * 0.618033988); size_t u = (int)(this->max_tables_ * this->buckets_per_table_ * prod); - + coord.set_table(u / this->buckets_per_table_); coord.set_bucket(u % this->buckets_per_table_); - + return 0; } //***************************************************************/ -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY>::ACE_Hash_Map_RT_POD (int num_tables, - ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>& func) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_POD (int num_tables, + ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>& func) : num_tables_ (num_tables), func_ (func) { } -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY>::~ACE_Hash_Map_RT_POD (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_POD (void) { } //***************************************************************/ -template <class EXT_ID, class INT_ID> -ACE_Hash_Map_RT_ListItem<EXT_ID, INT_ID>::ACE_Hash_Map_RT_ListItem (ENTRY* entry, +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_ListItem<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_ListItem (ENTRY* entry, LITEM* next) : entry_ (entry), next_ (next) { } -template <class EXT_ID, class INT_ID> -ACE_Hash_Map_RT_ListItem<EXT_ID, INT_ID>::ACE_Hash_Map_RT_ListItem () +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_ListItem<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_ListItem () : entry_ (0), next_ (0) { } -template <class EXT_ID, class INT_ID> -ACE_Hash_Map_RT_ListItem<EXT_ID, INT_ID>::~ACE_Hash_Map_RT_ListItem (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_ListItem<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_ListItem (void) { } //***************************************************************/ -template <class EXT_ID, class INT_ID> -ACE_Hash_Map_RT_Entry<EXT_ID, INT_ID>::ACE_Hash_Map_RT_Entry (const EXT_ID& ext_id, +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Entry<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_Entry (const EXT_ID& ext_id, const INT_ID& int_id) : ext_id_ (ext_id), int_id_ (int_id) { } -template <class EXT_ID, class INT_ID> -ACE_Hash_Map_RT_Entry<EXT_ID, INT_ID>::ACE_Hash_Map_RT_Entry () -{ +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Entry<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_Entry () +{ } # if ! defined (ACE_HAS_BROKEN_NOOP_DTORS) -template <class EXT_ID, class INT_ID> -ACE_Hash_Map_RT_Entry<EXT_ID, INT_ID>::~ACE_Hash_Map_RT_Entry (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Entry<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_Entry (void) { } # endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */ //***************************************************************/ -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY>::ACE_Hash_Map_RT_Bucket (POD* pod) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_Bucket (POD* pod) : curPOD_ (pod) { init_bucket_i(pod); } -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY>::ACE_Hash_Map_RT_Bucket (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_Bucket (void) { } -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY>::~ACE_Hash_Map_RT_Bucket (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_Bucket (void) { - // The "if" second argument results in a no-op instead of deallocation. - ACE_DES_FREE_TEMPLATE2 (this->curPOD_, + // The "if" second argument results in a no-op instead of deallocation. + ACE_DES_FREE_TEMPLATE2 (this->curPOD_, ACE_NOOP, - ACE_Hash_Map_RT_POD, - EXT_ID, + ACE_Hash_Map_RT_POD, + EXT_ID, INT_ID); this->curPOD_ = 0; @@ -179,16 +179,17 @@ ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY>::~ACE_Hash_Map_RT_Bucket (void) this->last_ = 0; } -template <class EXT_ID, class INT_ID, class HASH_KEY> int -ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY>::init_bucket_i (POD* pod) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int +ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::init_bucket_i (POD* pod) { this->head_ = new LITEM(); this->last_ = head_; + this->curPOD_ = pod; return 0; } -template <class EXT_ID, class INT_ID, class HASH_KEY> int -ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY>::prepend (ENTRY& entry) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int +ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::prepend (ENTRY& entry) { this->head_->next_ = new LITEM((new ENTRY(entry.get_ext_id(), @@ -202,57 +203,69 @@ ACE_Hash_Map_RT_Bucket<EXT_ID, INT_ID, HASH_KEY>::prepend (ENTRY& entry) //***************************************************************/ -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_Table<EXT_ID, INT_ID, HASH_KEY>::ACE_Hash_Map_RT_Table () +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Table<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_Table () { } -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_Table<EXT_ID, INT_ID, HASH_KEY>::ACE_Hash_Map_RT_Table (ACE_Allocator *allocator, +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Table<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_Table (ACE_Allocator *allocator, size_t buckets_per_table, POD* pod) { init_table_i(allocator, buckets_per_table, pod); } -template <class EXT_ID, class INT_ID, class HASH_KEY> -ACE_Hash_Map_RT_Table<EXT_ID, INT_ID, HASH_KEY>::~ACE_Hash_Map_RT_Table (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Table<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_Table (void) { // } -template <class EXT_ID, class INT_ID, class HASH_KEY> int -ACE_Hash_Map_RT_Table<EXT_ID, INT_ID, HASH_KEY>::init_table_i (ACE_Allocator *allocator, +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int +ACE_Hash_Map_RT_Table<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::init_table_i (ACE_Allocator *allocator, size_t buckets_per_table, POD* pod) { size_t bytes = buckets_per_table * sizeof (BUCKET); void *ptr; - + ACE_ALLOCATOR_RETURN (ptr, allocator->malloc (bytes), -1); - + this->buckets_ = (BUCKET *) ptr; - + for (size_t i = 0; i < buckets_per_table; i++) new (&this->buckets_[i]) BUCKET(pod); - + return 0; }; //***************************************************************/ -ACE_Hash_Map_RT_StatsManager::ACE_Hash_Map_RT_StatsManager (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_StatsManager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_StatsManager (void) : max_chain_ (0), total_elements_ (0) { } -ACE_Hash_Map_RT_StatsManager::~ACE_Hash_Map_RT_StatsManager (void) +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_StatsManager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_StatsManager (void) +{ +} + +/*ACE_Hash_Map_RT_StatsManager::ACE_Hash_Map_RT_StatsManager (void) + : max_chain_ (0), + total_elements_ (0) { } +ACE_Hash_Map_RT_StatsManager::~ACE_Hash_Map_RT_StatsManager (void) +{ +}*/ + //***************************************************************/ template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> @@ -265,35 +278,44 @@ ACE_Hash_Map_RT_Clean_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>: template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> ACE_Hash_Map_RT_Clean_Visitor<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::ACE_Hash_Map_RT_Clean_Visitor (ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>* thismanager) -{ +{ this->manager_ = thismanager; } +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> +ACE_Hash_Map_RT_Clean_Visitor<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_Clean_Visitor (void) +{ + this->dead_bucket = 0; + this->manager_ = 0; + this->found_ = 0; + this->mtfPrev_ = 0; +} + template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> ACE_Hash_Map_RT_Clean_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>* ACE_Hash_Map_RT_Clean_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::incremental_clean (void) { if (more_to_do()) { - BUCKET& bucket = manager_->get_table(cur_table_).get_bucket(cur_bucket_); + BUCKET& bucket = manager_->get_table(cur_table_).get_bucket(cur_bucket_); if (!bucket.is_clean(*manager_->curPOD_)) manager_->clean_vis_->process_bucket(bucket); - ++cur_bucket_; - if (cur_bucket_ >= manager_->buckets_per_table_) + ++cur_bucket_; + if (cur_bucket_ >= manager_->buckets_per_table_) { - ++cur_table_; - cur_bucket_ = 0; - } - } - if (cur_table_ < manager_->oldPOD_->get_num_tables()) + ++cur_table_; + cur_bucket_ = 0; + } + } + if (cur_table_ < manager_->oldPOD_->get_num_tables()) return this; - else + else { - this->manager_->oldPOD_ = 0; + this->manager_->oldPOD_ = 0; this->cur_table_ = 0; this->manager_->stats_->reset_max_chain(); - return 0; - } + return 0; + } } template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int @@ -323,31 +345,31 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::AC template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::~ACE_Hash_Map_RT_Manager_Ex (void) { - close_manager(); + close(); } template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int -ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::open_i (size_t buckets_per_table, +ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::open_i (size_t buckets_per_table, ACE_Allocator *alloc) { void *ptr, *ptr2; - + ACE_ALLOCATOR_RETURN (ptr, - allocator_->malloc (sizeof(ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY>)), + allocator_->malloc (sizeof(ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>)), -1); - + ACE_ALLOCATOR_RETURN (ptr2, - allocator_->malloc (sizeof(ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>)), + allocator_->malloc (sizeof(ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>)), -1); - - this->curPOD_ = new (ptr) ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY>(1, *(new (ptr2) ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>(1, this->buckets_per_table_))); + + this->curPOD_ = new (ptr) ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>(1, *(new (ptr2) ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>(1, this->buckets_per_table_))); this->oldPOD_ = 0; ACE_ALLOCATOR_RETURN (ptr, - allocator_->malloc (sizeof(ACE_Hash_Map_RT_StatsManager)), + allocator_->malloc (sizeof(ACE_Hash_Map_RT_StatsManager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>)), -1); - this->stats_ = new (ptr) ACE_Hash_Map_RT_StatsManager(); + this->stats_ = new (ptr) ACE_Hash_Map_RT_StatsManager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>(); ACE_ALLOCATOR_RETURN (ptr, allocator_->malloc (sizeof(ACE_Hash_Map_RT_Clean_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>)), @@ -362,28 +384,28 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::op this->clean_vis_ = new (ptr) ACE_Hash_Map_RT_Clean_Visitor<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>(this); ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); - + if (alloc == 0) alloc = ACE_Allocator::instance (); this->allocator_ = alloc; - + size_t bytes = this->max_tables_ * sizeof(TABLE); - + ACE_ALLOCATOR_RETURN (ptr, allocator_->malloc (bytes), -1); - + this->table_ = (TABLE *) ptr; - + for (size_t i = 0; i < max_tables_; i++) new (&this->get_table(i)) TABLE(allocator_, buckets_per_table, this->curPOD_); - + return 0; } template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> int -ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::close_manager (void) +ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::close (void) { ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1); @@ -399,68 +421,68 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::cl { // Remove all the entries. this->remove_all_i (); - + // Iterate through the buckets for (size_t i = 0; i < this->max_tables_; i++) { for (size_t j = 0; j < this->buckets_per_table_; j++) { BUCKET *temp_bkt = &(this->get_table(i).get_bucket(j)); - + // The "if" second argument results in a no-op instead of - // deallocation. - ACE_DES_FREE_TEMPLATE2 (temp_bkt, + // deallocation. + ACE_DES_FREE_TEMPLATE2 (temp_bkt, ACE_NOOP, - ACE_Hash_Map_RT_Bucket, - EXT_ID, + ACE_Hash_Map_RT_Bucket, + EXT_ID, INT_ID); temp_bkt = 0; } TABLE *temp_tbl = &(this->get_table(i)); // The "if" second argument results in a no-op instead of - // deallocation. - ACE_DES_FREE_TEMPLATE2 (temp_tbl, + // deallocation. + ACE_DES_FREE_TEMPLATE2 (temp_tbl, ACE_NOOP, - ACE_Hash_Map_RT_Table, - EXT_ID, + ACE_Hash_Map_RT_Table, + EXT_ID, INT_ID); temp_tbl = 0; } POD *pod = (this->get_POD()); - ACE_DES_FREE_TEMPLATE2 (pod, + ACE_DES_FREE_TEMPLATE2 (pod, ACE_NOOP, - ACE_Hash_Map_RT_POD, - EXT_ID, + ACE_Hash_Map_RT_POD, + EXT_ID, INT_ID); pod = 0; delete this->oldPOD_; this->oldPOD_ = 0; - - ACE_Hash_Map_RT_StatsManager *stats = (this->stats_); - ACE_DES_FREE_TEMPLATE2 (stats, + + ACE_Hash_Map_RT_StatsManager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> *stats = (this->stats_); + ACE_DES_FREE_TEMPLATE2 (stats, ACE_NOOP, - ACE_Hash_Map_RT_StatsManager, - EXT_ID, + ACE_Hash_Map_RT_StatsManager, + EXT_ID, INT_ID); stats = 0; CLEAN *clean = (this->clean_); - ACE_DES_FREE_TEMPLATE2 (clean, + ACE_DES_FREE_TEMPLATE2 (clean, ACE_NOOP, - ACE_Hash_Map_RT_Clean_Manager, - EXT_ID, + ACE_Hash_Map_RT_Clean_Manager, + EXT_ID, INT_ID); clean = 0; - + CLEANV *cleanv = (this->clean_vis_); - ACE_DES_FREE_TEMPLATE2 (cleanv, + ACE_DES_FREE_TEMPLATE2 (cleanv, ACE_NOOP, ACE_Hash_Map_RT_Clean_Visitor, - EXT_ID, + EXT_ID, INT_ID); cleanv = 0; @@ -470,7 +492,7 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::cl // Should be done last... this->table_ = 0; } - + return 0; } @@ -479,7 +501,7 @@ template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::remove_all_i (void) { // Iterate through the entire map calling the destuctor of each <ACE_Hash_Map_ListItem>. - + for (size_t i = 0; i < this->max_tables_; i++) { for (size_t j = 0; j < this->buckets_per_table_; j++) @@ -492,7 +514,7 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::re temp_ptr = temp_ptr->next_; delete hold_ptr; hold_ptr = 0; - + /// Explicitly call the destructor. ACE_DES_FREE_TEMPLATE2 (hold_ptr, this->allocator_->free, @@ -500,7 +522,7 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::re EXT_ID, INT_ID); } - } + } //done with the bucket this->get_table(i).get_bucket(j).set_length(0); } @@ -509,7 +531,7 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::re } //this->cur_size_ = 0; - + return 0; } @@ -520,13 +542,13 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::lo { ACE_Hash_Map_RT_Coord oldcoord = ACE_Hash_Map_RT_Coord(0,0); ACE_Hash_Map_RT_Coord newCoord = ACE_Hash_Map_RT_Coord(0,0); - + BUCKET& new_bucket = find_bucket(this->curPOD_, ext_id); - + if (is_stable() == 1) { int_id = 0; - + size_t num_cleaned = 0; if (!find_bucket(this->oldPOD_, ext_id).is_clean(*this->curPOD_)) { @@ -546,27 +568,27 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::lo if (clean_ == 0) clean_ = new ACE_Hash_Map_RT_Clean_Manager<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> (this); } - + else { visitor.process_bucket(new_bucket); } - + if (visitor.is_found() == 1) - { + { ENTRY& temp = *(visitor.get_found()).entry_; if (temp.get_int_id() != 0) - { - int_id = temp.get_int_id(); - return 0; - } + { + int_id = temp.get_int_id(); + return 0; + } } - + // we looped without finding the bucket return -1; } -template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY>* +template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>* ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::create_POD (void) { int bucketsPerTable = buckets_per_table_; @@ -575,33 +597,33 @@ ACE_Hash_Map_RT_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::cr double tuningKnob = 0.000; int new_num_of_tables = 0; - int currNumBuckets = bucketsPerTable * currNumTables; - double new_num_of_buckets = currNumBuckets + (double)(currNumBuckets+1)/(RTL_-1); - double idealLoadFactor = RTL_ - 1; - - double currNumElements = (double)(stats_->get_total_elements ()); - double currentLoadFactor = currNumElements / currNumBuckets; - double addPercentage = (idealLoadFactor - currentLoadFactor) / idealLoadFactor; - - new_num_of_tables = (int)(ceil(new_num_of_buckets / (double)bucketsPerTable)); - - double extraFraction = addPercentage * new_num_of_buckets; + int currNumBuckets = bucketsPerTable * currNumTables; + double new_num_of_buckets = currNumBuckets + (double)(currNumBuckets+1)/(RTL_-1); + double idealLoadFactor = RTL_ - 1; + + double currNumElements = (double)(stats_->get_total_elements ()); + double currentLoadFactor = currNumElements / currNumBuckets; + double addPercentage = (idealLoadFactor - currentLoadFactor) / idealLoadFactor; + + new_num_of_tables = (int)(ceil(new_num_of_buckets / (double)bucketsPerTable)); + + double extraFraction = addPercentage * new_num_of_buckets; if (extraFraction < 0) extraFraction *= -1; - - new_num_of_buckets = (int)(ceil(new_num_of_buckets + extraFraction * tuningKnob)); - new_num_of_tables = (int)(ceil(new_num_of_buckets / (double)bucketsPerTable)); - - if(new_num_of_tables > this->max_tables_) + + new_num_of_buckets = (int)(ceil(new_num_of_buckets + extraFraction * tuningKnob)); + new_num_of_tables = (int)(ceil(new_num_of_buckets / (double)bucketsPerTable)); + + if(new_num_of_tables > (int)this->max_tables_) new_num_of_tables = this->max_tables_; if(new_num_of_buckets > this->buckets_per_table_) new_num_of_buckets = this->buckets_per_table_; - this->number_of_tables_ = new_num_of_tables; - this->buckets_per_table_ = new_num_of_buckets; + this->number_of_tables_ = (size_t)new_num_of_tables; + this->buckets_per_table_ = (size_t)new_num_of_buckets; - return (new ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY> (new_num_of_tables, *(new ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY>(new_num_of_tables, bucketsPerTable)))); + return (new ACE_Hash_Map_RT_POD<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> (new_num_of_tables, *(new ACE_Hash_Map_RT_Hash_Function<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>(new_num_of_tables, bucketsPerTable)))); } template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK> size_t @@ -621,19 +643,19 @@ ACE_Hash_Map_RT_Visitor<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::proce LITEM* item = bucket.head_; // head doesnt have an entry this->mtfPrev_ = bucket.head_; // prev is head until we step forward - + while( item != (bucket.last_) ) // all ListItems have a next except last { item = item->next_; visit(item); // so let's visit that next_ ListItem - + if(is_found() == 0) // If we havent found the one we are looking for, this->mtfPrev_ = item; // then save the one we are on (the 'previous'). - // After we find the one we want, we dont want to overwrite + // After we find the one we want, we dont want to overwrite // our mtfPrev_ ptr anymore } done(bucket); - + return 0; } @@ -691,12 +713,12 @@ ACE_Hash_Map_RT_Put_Visitor<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::d if (is_found() == 0) // if we havent found what we're looking for { // then bind a new one ENTRY entry = ENTRY(this->ext_id_, - this->int_id_); - + this->int_id_); + bucket.prepend(entry); - + LITEM litem = LITEM (&entry, - bucket.head_->next_); + bucket.head_->next_); found_key(&litem); @@ -704,17 +726,17 @@ ACE_Hash_Map_RT_Put_Visitor<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::d if (manager_->is_stable() == 0) { - this->manager_->stats_->compare_max_chain(bucket.get_length()); + this->manager_->stats_->compare_max_chain(bucket.get_length()); if (bucket.get_length() >= this->manager_->RTL_) { POD* pod = this->manager_->create_POD(); if (pod != 0) this->manager_->change_POD(*pod); - } + } } return 0; } - + return -1; } @@ -748,16 +770,16 @@ ACE_Hash_Map_RT_Remove_Visitor<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> { if (this->found_ == bucket.last_) bucket.last_ = this->mtfPrev_; - + this->mtfPrev_->next_ = this->get_found().next_; - + delete this->found_; this->found_ = 0; - + bucket.decr_length(); this->manager_->stats_->decr_total_elements(); } - + return 0; } |