diff options
author | bala <balanatarajan@users.noreply.github.com> | 2001-11-20 19:42:56 +0000 |
---|---|---|
committer | bala <balanatarajan@users.noreply.github.com> | 2001-11-20 19:42:56 +0000 |
commit | d562737ef72ab4758340a5708e73cee5cd8ab2f9 (patch) | |
tree | 5d719ca180a23d3c657db0d7ff829451d8de4440 | |
parent | 74009babc09caed362b235cf138b6649daac3f12 (diff) | |
download | ATCD-d562737ef72ab4758340a5708e73cee5cd8ab2f9.tar.gz |
ChangeLogTag: Fri Nov 16 07:22:19 2001 Balachandran Natarajan <bala@cs.wustl.edu>
-rw-r--r-- | ace/Hashable.cpp | 8 | ||||
-rw-r--r-- | ace/Hashable.h | 64 | ||||
-rw-r--r-- | ace/Hashable.inl | 27 |
3 files changed, 99 insertions, 0 deletions
diff --git a/ace/Hashable.cpp b/ace/Hashable.cpp new file mode 100644 index 00000000000..669cce3d4b7 --- /dev/null +++ b/ace/Hashable.cpp @@ -0,0 +1,8 @@ +//$Id$ +#include "ace/Hashable.h" + +#if !defined (__ACE_INLINE__) +#include "ace/Hashable.inl" +#endif /* __ACE_INLINE __ */ + +ACE_RCSID(ace, Strategies, "$Id$") diff --git a/ace/Hashable.h b/ace/Hashable.h new file mode 100644 index 00000000000..c26cb1e83b5 --- /dev/null +++ b/ace/Hashable.h @@ -0,0 +1,64 @@ +/* -*- C++ -*- */ + +//============================================================================= +/** + * @file Strategies.h + * + * $Id$ + * + * @author Doug Schmidt + */ +//============================================================================= +#ifndef ACE_HASHABLE_H +#define ACE_HASHABLE_H +#include "ace/pre.h" + +// @@todo: Hate to do this. Looks like we have less luck here as +// compilers complain for type u_long unknowns +#include "ace/OS.h" + + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + + +/** + * @class ACE_Recyclable + * + * @brief + * + * + */ + +class ACE_Export ACE_Hashable +{ +public: + + /// Destructor. + virtual ~ACE_Hashable (void); + + /// Computes and returns hash value. This "caches" the hash value to + /// improve performance. + virtual u_long hash (void) const; + +protected: + /// Protected constructor. + ACE_Hashable (void); + + /// This is the method that actually performs the non-cached hash + /// computation. + virtual u_long hash_i (void) const = 0; + + /// Pre-computed hash-value. + u_long hash_value_; +}; + + +#if defined (__ACE_INLINE__) +#include "ace/Hashable.inl" +#endif /* __ACE_INLINE __ */ + +#include "ace/post.h" +#endif /*ACE_HASHABLE_H*/ diff --git a/ace/Hashable.inl b/ace/Hashable.inl new file mode 100644 index 00000000000..554c55a5d0a --- /dev/null +++ b/ace/Hashable.inl @@ -0,0 +1,27 @@ +/* -*- C++ -*- */ + +ACE_INLINE +ACE_Hashable::ACE_Hashable (void) + : hash_value_ (0) +{ +} + +ACE_INLINE +ACE_Hashable::~ACE_Hashable (void) +{ +} + +ACE_INLINE u_long +ACE_Hashable::hash (void) const +{ + // In doing the check below, we take chance of paying a performance + // price when the hash value is zero. But, that will (hopefully) + // happen far less often than a non-zero value, so this caching + // strategy should pay off, esp. if hash computation is expensive + // relative to the simple comparison. + + if (this->hash_value_ == 0) + ((ACE_Hashable *) this)->hash_value_ = this->hash_i (); + + return this->hash_value_; +} |