diff options
author | bala <balanatarajan@users.noreply.github.com> | 2003-05-22 15:46:49 +0000 |
---|---|---|
committer | bala <balanatarajan@users.noreply.github.com> | 2003-05-22 15:46:49 +0000 |
commit | a315d7af60b07cc3144e0996763909043b4ca46a (patch) | |
tree | fd6c10ba1da07641faff17827608811178c2e87e | |
parent | 4c26f7e14a64db4072e195cfcf58d4b8a42d085a (diff) | |
download | ATCD-a315d7af60b07cc3144e0996763909043b4ca46a.tar.gz |
ChangeLogTag:Thu May 22 10:38:53 2003 Balachandran Natarajan <bala@dre.vanderbilt.edu>
-rw-r--r-- | TAO/ChangeLog | 16 | ||||
-rw-r--r-- | TAO/tao/ObjectKey_Table.cpp | 75 | ||||
-rw-r--r-- | TAO/tao/ObjectKey_Table.h | 29 |
3 files changed, 71 insertions, 49 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 4004ebdeb76..2cfeb410c8e 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,19 @@ +Thu May 22 10:38:53 2003 Balachandran Natarajan <bala@dre.vanderbilt.edu> + + * tao/ObjectKey_Table.cpp (ObjectKey_Table): + * tao/ObjectKey_Table.h: The hash value that was used as an key + did not scale. We got collissions which broke down the whole + model. Instead of using the hash value as the key, we now use + the ObjectKey itself as the key. This turns out to be more + efficient than the previous scheme and avoid collisions. + + The other problem that came up because of the above change, is + the requirement of a operator < for the ObjectKey. This was + solved by the addition of a class TAO::Less_Than_ObjectKey which + acts as a comparative operator. Ideally this should have been a + template specialization of the parametric class ACE_Less_Than<>, + but this wouldnt work so easily without breaking builds. + Wed May 21 19:57:31 2003 Nanbor Wang <nanbor@cs.wustl.edu> * tao/Strategies/SHMIOP_Acceptor.cpp (open_i): Changed to use the diff --git a/TAO/tao/ObjectKey_Table.cpp b/TAO/tao/ObjectKey_Table.cpp index c0b0c5a66d0..68fa7488fbe 100644 --- a/TAO/tao/ObjectKey_Table.cpp +++ b/TAO/tao/ObjectKey_Table.cpp @@ -2,12 +2,32 @@ #include "ObjectKey_Table.h" #include "ORB_Core.h" #include "Refcounted_ObjectKey.h" +#include "Object_KeyC.h" ACE_RCSID(tao, ObjectKey_Table, "$Id$") +int +TAO::Less_Than_ObjectKey::operator () (const TAO::ObjectKey &lhs, + const TAO::ObjectKey &rhs) const +{ + if (lhs.length () < rhs.length ()) + return 1; + else if (lhs.length () > rhs.length ()) + return 0; + + for (CORBA::ULong i = 0; i < rhs.length (); ++i) + { + if (lhs[i] < rhs[i]) + return 1; + } + + return 0; +} + +/********************************************************/ TAO::ObjectKey_Table::ObjectKey_Table (void) : lock_ (0) , table_ () @@ -38,16 +58,6 @@ TAO::ObjectKey_Table::bind (const TAO::ObjectKey &key, { key_new = 0; - // NOTE:Place for optimization. This is real expensive.. - CORBA::String_var str; - TAO::ObjectKey::encode_sequence_to_string (str.inout (), - key); - - // Hash values can be tricky, but even then thy are useful at - // times. - u_long hash_val = - ACE::hash_pjw (str.in ()); - int retval = 0; { ACE_GUARD_RETURN (ACE_Lock, @@ -60,26 +70,16 @@ TAO::ObjectKey_Table::bind (const TAO::ObjectKey &key, // efficient. BUT we may have to do allocation upfront and delete if // bind () returns with an entry. We take one of the routes that // avoids allocation. - retval = this->table_.find (hash_val, + retval = this->table_.find (key, key_new); if (retval == -1) - return this->bind_i (hash_val, - key, + return this->bind_i (key, key_new); - // Do a sanity comparison check and increment the refcount. // Place for optimization by removing the comparison. - if (key_new->object_key () == key) - { - (void) key_new->incr_refcount (); - } - else - { - // Do we bind it again. And if so, how? - // Need to thinkk.... - } + (void) key_new->incr_refcount (); } return 0; @@ -127,15 +127,14 @@ TAO::ObjectKey_Table::destroy (void) } int -TAO::ObjectKey_Table::bind_i (u_long hash_val, - const TAO::ObjectKey &key, +TAO::ObjectKey_Table::bind_i (const TAO::ObjectKey &key, TAO::Refcounted_ObjectKey *&key_new) { ACE_NEW_RETURN (key_new, TAO::Refcounted_ObjectKey (key), -1); - int retval = this->table_.bind (hash_val, + int retval = this->table_.bind (key, key_new); if (retval != -1) @@ -149,15 +148,7 @@ TAO::ObjectKey_Table::bind_i (u_long hash_val, int TAO::ObjectKey_Table::unbind_i (TAO::Refcounted_ObjectKey *&key_new) { - // NOTE:Place for optimization. This is real expensive.. - CORBA::String_var str; - TAO::ObjectKey::encode_sequence_to_string (str.inout (), - key_new->object_key ()); - - u_long hash_val = - ACE::hash_pjw (str.in ()); - - (void) this->table_.unbind (hash_val, + (void) this->table_.unbind (key_new->object_key (), key_new); // Remove our refcount on the ObjectKey @@ -166,20 +157,18 @@ TAO::ObjectKey_Table::unbind_i (TAO::Refcounted_ObjectKey *&key_new) return 0; } - #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) // Instantiations for the Hash Map -template class ACE_Less_Than<long>; -template class ACE_RB_Tree <long, +template class ACE_RB_Tree <TAO::ObjectKey, TAO::Refcounted_ObjectKey, - ACE_Less_Than<long>, + TAO::Less_Than_ObjectKey, ACE_Null_Mutex>; + #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Less_Than<long>; -#pragma instantiate ACE_RB_Tree <long, +#pragma instantiate ACE_RB_Tree <TAO::ObjectKey, TAO::Refcounted_ObjectKey, - ACE_Less_Than<long>, - ACE_Null_Mutex>; + TAO::Less_Than_ObjectKey, + ACE_Null_Mutex> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/ObjectKey_Table.h b/TAO/tao/ObjectKey_Table.h index 52ded9b5294..3303d9113f6 100644 --- a/TAO/tao/ObjectKey_Table.h +++ b/TAO/tao/ObjectKey_Table.h @@ -1,3 +1,4 @@ + // -*- C++ -*- //============================================================================= @@ -19,6 +20,7 @@ #endif /* ACE_LACKS_PRAGMA_ONCE */ #include "tao/TAO_Export.h" +#include "ace/Functor.h" // Forward declarations @@ -36,6 +38,23 @@ namespace TAO /** * @class ObjectKey_Table * + * @brief: Compares the length and then the contents of ObjectKeys. + * + * Should have been a specialization of the functor + * ACE_Less_Than<sequence<CORBA::Octet>>. But that will not work + * so easily across bunch of stuff. Hence let us put up with this + * for the time being. + */ + class TAO_Export Less_Than_ObjectKey + { + public: + int operator () (const TAO::ObjectKey &lhs, + const TAO::ObjectKey &rhs) const; + }; + + /** + * @class ObjectKey_Table + * * @brief Table that maintains the set of ObjectKey's seen by the * ORB. * @@ -96,8 +115,7 @@ namespace TAO protected: /// Implementation for bind (). - int bind_i (u_long hash_val, - const ObjectKey &key, + int bind_i (const ObjectKey &key, Refcounted_ObjectKey *&key_new); /// Implementation for unbind (). @@ -106,11 +124,9 @@ namespace TAO private: // Some useful typedefs. - typedef unsigned long ExtId; - - typedef ACE_RB_Tree<ExtId, + typedef ACE_RB_Tree<TAO::ObjectKey, TAO::Refcounted_ObjectKey *, - ACE_Less_Than <ExtId>, + TAO::Less_Than_ObjectKey, ACE_Null_Mutex> TABLE; /// Lock for the table. @@ -121,5 +137,6 @@ namespace TAO }; } + #include "ace/post.h" #endif /*TAO_OBJECT_KEY_TABLE_H*/ |