Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Hash_Map_Manager_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Hash_Map_Manager_T.h
00006  *
00007  *  $Id: Hash_Map_Manager_T.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_HASH_MAP_MANAGER_T_H
00014 #define ACE_HASH_MAP_MANAGER_T_H
00015 #include "ace/pre.h"
00016 
00017 #include "ace/config-all.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ace/Default_Constants.h"
00024 #include "ace/Functor.h"
00025 #include "ace/Log_Msg.h"
00026 
00027 /**
00028  * @class ACE_Hash_Map_Entry
00029  *
00030  * @brief Define an entry in the hash table.
00031  */
00032 template <class EXT_ID, class INT_ID>
00033 class ACE_Hash_Map_Entry
00034 {
00035 public:
00036   // = Initialization and termination methods.
00037   /// Constructor.
00038   ACE_Hash_Map_Entry (const EXT_ID &ext_id,
00039                       const INT_ID &int_id,
00040                       ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next = 0,
00041                       ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev = 0);
00042 
00043   /// Constructor.
00044   ACE_Hash_Map_Entry (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next,
00045                       ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev);
00046 
00047   # if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
00048   /// Destructor.
00049   ~ACE_Hash_Map_Entry (void);
00050   #endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */
00051 
00052   /// Key used to look up an entry.
00053   EXT_ID ext_id_;
00054 
00055   /// The contents of the entry itself.
00056   INT_ID int_id_;
00057 
00058   /// Pointer to the next item in the bucket of overflow nodes.
00059   ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
00060 
00061   /// Pointer to the prev item in the bucket of overflow nodes.
00062   ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev_;
00063 
00064   /// Dump the state of an object.
00065   void dump (void) const;
00066 };
00067 
00068 // Forward decl.
00069 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00070 class ACE_Hash_Map_Iterator_Base_Ex;
00071 
00072 // Forward decl.
00073 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00074 class ACE_Hash_Map_Const_Iterator_Base_Ex;
00075 
00076 // Forward decl.
00077 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00078 class ACE_Hash_Map_Iterator_Ex;
00079 
00080 // Forward decl.
00081 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00082 class ACE_Hash_Map_Const_Iterator_Ex;
00083 
00084 // Forward decl.
00085 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00086 class ACE_Hash_Map_Reverse_Iterator_Ex;
00087 
00088 // Forward decl.
00089 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00090 class ACE_Hash_Map_Bucket_Iterator;
00091 
00092 // Forward decl.
00093 class ACE_Allocator;
00094 
00095 /**
00096  * @class ACE_Hash_Map_Manager_Ex
00097  *
00098  * @brief Define a map abstraction that efficiently associates
00099  * <EXT_ID>s with <INT_ID>s.
00100  *
00101  * This implementation of a map uses a hash table.  Key hashing
00102  * is achieved through the HASH_KEY object and key comparison is
00103  * achieved through the COMPARE_KEYS object.
00104  * This class uses an <ACE_Allocator> to allocate memory.  The
00105  * user can make this a persistent class by providing an
00106  * <ACE_Allocator> with a persistable memory pool.
00107  */
00108 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00109 class ACE_Hash_Map_Manager_Ex
00110 {
00111 public:
00112   friend class ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
00113   friend class ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
00114   friend class ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
00115   friend class ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
00116   friend class ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
00117   friend class ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
00118 
00119   typedef EXT_ID
00120           KEY;
00121   typedef INT_ID
00122           VALUE;
00123   typedef ACE_Hash_Map_Entry<EXT_ID, INT_ID>
00124           ENTRY;
00125 
00126   // = ACE-style iterator typedefs.
00127   typedef ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00128           ITERATOR;
00129   typedef ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00130           CONST_ITERATOR;
00131   typedef ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00132           REVERSE_ITERATOR;
00133 
00134   // = STL-style iterator typedefs.
00135   typedef ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00136           iterator;
00137   typedef ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00138           const_iterator;
00139   typedef ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00140           reverse_iterator;
00141 
00142   // = Initialization and termination methods.
00143 
00144   /// Initialize a <Hash_Map_Manager_Ex> with default size.
00145   ACE_Hash_Map_Manager_Ex (ACE_Allocator *alloc = 0);
00146 
00147   /// Initialize a <Hash_Map_Manager_Ex> with size <length>.
00148   ACE_Hash_Map_Manager_Ex (size_t size,
00149                            ACE_Allocator *alloc = 0);
00150 
00151   /// Initialize a <Hash_Map_Manager_Ex> with <size> elements.
00152   int open (size_t size = ACE_DEFAULT_MAP_SIZE,
00153             ACE_Allocator *alloc = 0);
00154 
00155   /// Close down a <Hash_Map_Manager_Ex> and release dynamically allocated
00156   /// resources.
00157   int close (void);
00158 
00159   /// Removes all the entries in <Map_Manager_Ex>.
00160   int unbind_all (void);
00161 
00162   /// Cleanup the <Hash_Map_Manager_Ex>.
00163   ~ACE_Hash_Map_Manager_Ex (void);
00164 
00165   /**
00166    * Associate <ext_id> with <int_id>.  If <ext_id> is already in the
00167    * map then the <ACE_Hash_Map_Entry> is not changed.  Returns 0 if a
00168    * new entry is bound successfully, returns 1 if an attempt is made
00169    * to bind an existing entry, and returns -1 if failures occur.
00170    */
00171   int bind (const EXT_ID &item,
00172             const INT_ID &int_id);
00173 
00174   /**
00175    * Same as a normal bind, except the map entry is also passed back
00176    * to the caller.  The entry in this case will either be the newly
00177    * created entry, or the existing one.
00178    */
00179   int bind (const EXT_ID &ext_id,
00180             const INT_ID &int_id,
00181             ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00182 
00183   /**
00184    * Associate <ext_id> with <int_id> if and only if <ext_id> is not
00185    * in the map.  If <ext_id> is already in the map then the <int_id>
00186    * parameter is assigned the existing value in the map.  Returns 0
00187    * if a new entry is bound successfully, returns 1 if an attempt is
00188    * made to bind an existing entry, and returns -1 if failures occur.
00189    */
00190   int trybind (const EXT_ID &ext_id,
00191                INT_ID &int_id);
00192 
00193   /**
00194    * Same as a normal trybind, except the map entry is also passed
00195    * back to the caller.  The entry in this case will either be the
00196    * newly created entry, or the existing one.
00197    */
00198   int trybind (const EXT_ID &ext_id,
00199                INT_ID &int_id,
00200                ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00201 
00202   /**
00203    * Reassociate <ext_id> with <int_id>.  If <ext_id> is not in the
00204    * map then behaves just like <bind>.  Returns 0 if a new entry is
00205    * bound successfully, returns 1 if an existing entry was rebound,
00206    * and returns -1 if failures occur.
00207    */
00208   int rebind (const EXT_ID &ext_id,
00209               const INT_ID &int_id);
00210 
00211   /**
00212    * Same as a normal rebind, except the map entry is also passed back
00213    * to the caller.  The entry in this case will either be the newly
00214    * created entry, or the existing one.
00215    */
00216   int rebind (const EXT_ID &ext_id,
00217               const INT_ID &int_id,
00218               ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00219 
00220   /**
00221    * Associate <ext_id> with <int_id>.  If <ext_id> is not in the map
00222    * then behaves just like <bind>.  Otherwise, store the old value of
00223    * <int_id> into the "out" parameter and rebind the new parameters.
00224    * Returns 0 if a new entry is bound successfully, returns 1 if an
00225    * existing entry was rebound, and returns -1 if failures occur.
00226    */
00227   int rebind (const EXT_ID &ext_id,
00228               const INT_ID &int_id,
00229               INT_ID &old_int_id);
00230 
00231   /**
00232    * Same as a normal rebind, except the map entry is also passed back
00233    * to the caller.  The entry in this case will either be the newly
00234    * created entry, or the existing one.
00235    */
00236   int rebind (const EXT_ID &ext_id,
00237               const INT_ID &int_id,
00238               INT_ID &old_int_id,
00239               ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00240 
00241   /**
00242    * Associate <ext_id> with <int_id>.  If <ext_id> is not in the map
00243    * then behaves just like <bind>.  Otherwise, store the old values
00244    * of <ext_id> and <int_id> into the "out" parameters and rebind the
00245    * new parameters.  This is very useful if you need to have an
00246    * atomic way of updating <ACE_Hash_Map_Entrys> and you also need
00247    * full control over memory allocation.  Returns 0 if a new entry is
00248    * bound successfully, returns 1 if an existing entry was rebound,
00249    * and returns -1 if failures occur.
00250    */
00251   int rebind (const EXT_ID &ext_id,
00252               const INT_ID &int_id,
00253               EXT_ID &old_ext_id,
00254               INT_ID &old_int_id);
00255 
00256   /**
00257    * Same as a normal rebind, except the map entry is also passed back
00258    * to the caller.  The entry in this case will either be the newly
00259    * created entry, or the existing one.
00260    */
00261   int rebind (const EXT_ID &ext_id,
00262               const INT_ID &int_id,
00263               EXT_ID &old_ext_id,
00264               INT_ID &old_int_id,
00265               ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00266 
00267   /// Locate <ext_id> and pass out parameter via <int_id>.
00268   /// Return 0 if found, returns -1 if not found.
00269   int find (const EXT_ID &ext_id,
00270             INT_ID &int_id) const;
00271 
00272   /// Returns 0 if the <ext_id> is in the mapping, otherwise -1.
00273   int find (const EXT_ID &ext_id) const;
00274 
00275   /// Locate <ext_id> and pass out parameter via <entry>.  If found,
00276   /// return 0, returns -1 if not found.
00277   int find (const EXT_ID &ext_id,
00278             ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry) const;
00279 
00280   /**
00281    * Unbind (remove) the <ext_id> from the map.  Don't return the
00282    * <int_id> to the caller (this is useful for collections where the
00283    * <int_id>s are *not* dynamically allocated...)
00284    */
00285   int unbind (const EXT_ID &ext_id);
00286 
00287   /// Break any association of <ext_id>.  Returns the value of <int_id>
00288   /// in case the caller needs to deallocate memory. Return 0 if the
00289   /// unbind was successfully, and returns -1 if failures occur.
00290   int unbind (const EXT_ID &ext_id,
00291               INT_ID &int_id);
00292 
00293   /// Remove entry from map. Return 0 if the unbind was successfully,
00294   /// and returns -1 if failures occur.
00295   int unbind (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *entry);
00296 
00297   /// Return the current size of the map.
00298   size_t current_size (void) const;
00299 
00300   /// Return the total size of the map.
00301   size_t total_size (void) const;
00302 
00303   /**
00304    * Returns a reference to the underlying <ACE_LOCK>.  This makes it
00305    * possible to acquire the lock explicitly, which can be useful in
00306    * some cases if you instantiate the <ACE_Atomic_Op> with an
00307    * <ACE_Recursive_Mutex> or <ACE_Process_Mutex>, or if you need to
00308    * guard the state of an iterator.  NOTE: the right name would be
00309    * <lock>, but HP/C++ will choke on that!
00310    */
00311   ACE_LOCK &mutex (void);
00312 
00313   /// Dump the state of an object.
00314   void dump (void) const;
00315 
00316   // = STL styled iterator factory functions.
00317 
00318   /// Return forward iterator.
00319   ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> begin (void);
00320   ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> end (void);
00321 
00322   /// Return reverse iterator.
00323   ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> rbegin (void);
00324   ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> rend (void);
00325 
00326 protected:
00327   // = The following methods do the actual work.
00328 
00329   /// Returns 1 if <id1> == <id2>, else 0.  This is defined as a
00330   /// separate method to facilitate template specialization.
00331   int equal (const EXT_ID &id1, const EXT_ID &id2);
00332 
00333   /// Compute the hash value of the <ext_id>.  This is defined as a
00334   /// separate method to facilitate template specialization.
00335   u_long hash (const EXT_ID &ext_id);
00336 
00337   // = These methods assume locks are held by private methods.
00338 
00339   /// Performs bind.  Must be called with locks held.
00340   int bind_i (const EXT_ID &ext_id,
00341               const INT_ID &int_id);
00342 
00343   /// Performs bind.  Must be called with locks held.
00344   int bind_i (const EXT_ID &ext_id,
00345               const INT_ID &int_id,
00346               ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00347 
00348   /// Performs trybind.  Must be called with locks held.
00349   int trybind_i (const EXT_ID &ext_id,
00350                  INT_ID &int_id);
00351 
00352   /// Performs trybind.  Must be called with locks held.
00353   int trybind_i (const EXT_ID &ext_id,
00354                  INT_ID &int_id,
00355                  ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00356 
00357   /// Performs rebind.  Must be called with locks held.
00358   int rebind_i (const EXT_ID &ext_id,
00359                 const INT_ID &int_id);
00360 
00361   /// Performs rebind.  Must be called with locks held.
00362   int rebind_i (const EXT_ID &ext_id,
00363                 const INT_ID &int_id,
00364                 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00365 
00366   /// Performs rebind.  Must be called with locks held.
00367   int rebind_i (const EXT_ID &ext_id,
00368                 const INT_ID &int_id,
00369                 INT_ID &old_int_id);
00370 
00371   /// Performs rebind.  Must be called with locks held.
00372   int rebind_i (const EXT_ID &ext_id,
00373                 const INT_ID &int_id,
00374                 INT_ID &old_int_id,
00375                 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00376 
00377   /// Performs rebind.  Must be called with locks held.
00378   int rebind_i (const EXT_ID &ext_id,
00379                 const INT_ID &int_id,
00380                 EXT_ID &old_ext_id,
00381                 INT_ID &old_int_id);
00382 
00383   /// Performs rebind.  Must be called with locks held.
00384   int rebind_i (const EXT_ID &ext_id,
00385                 const INT_ID &int_id,
00386                 EXT_ID &old_ext_id,
00387                 INT_ID &old_int_id,
00388                 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00389 
00390   /// Performs a find of <int_id> using <ext_id> as the key.  Must be
00391   /// called with locks held.
00392   int find_i (const EXT_ID &ext_id,
00393               INT_ID &int_id);
00394 
00395   /// Performs a find using <ext_id> as the key.  Must be called with
00396   /// locks held.
00397   int find_i (const EXT_ID &ext_id);
00398 
00399   /// Performs a find using <ext_id> as the key.  Must be called with
00400   /// locks held.
00401   int find_i (const EXT_ID &ext_id,
00402               ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
00403 
00404   /// Performs unbind.  Must be called with locks held.
00405   int unbind_i (const EXT_ID &ext_id,
00406                 INT_ID &int_id);
00407 
00408   /// Performs unbind.  Must be called with locks held.
00409   int unbind_i (const EXT_ID &ext_id);
00410 
00411   /// Performs unbind.  Must be called with locks held.
00412   int unbind_i (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *entry);
00413 
00414   /**
00415    * Resize the map.  Must be called with locks held.  Note, that this
00416    * method should never be called more than once or else all the
00417    * hashing will get screwed up as the size will change.
00418    */
00419   int create_buckets (size_t size);
00420 
00421   /// Close down a <Map_Manager_Ex>.  Must be called with
00422   /// locks held.
00423   int close_i (void);
00424 
00425   /// Removes all the entries in <Map_Manager_Ex>.  Must be called with
00426   /// locks held.
00427   int unbind_all_i (void);
00428 
00429   /// Pointer to a memory allocator.
00430   ACE_Allocator *allocator_;
00431 
00432   /// Synchronization variable for the MT_SAFE <ACE_Hash_Map_Manager_Ex>.
00433   ACE_LOCK lock_;
00434 
00435   /// Function object used for hashing keys.
00436   HASH_KEY hash_key_;
00437 
00438   /// Function object used for comparing keys.
00439   COMPARE_KEYS compare_keys_;
00440 
00441 protected:
00442   /// Returns the <ACE_Hash_Map_Entry> that corresponds to <ext_id>.
00443   int shared_find (const EXT_ID &ext_id,
00444                    ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry,
00445                    size_t &loc);
00446 
00447 private:
00448   /**
00449    * Array of <ACE_Hash_Map_Entry> *s, each of which points to an
00450    * <ACE_Hash_Map_Entry> that serves as the beginning of a linked
00451    * list of <EXT_ID>s that hash to that bucket.
00452    */
00453   ACE_Hash_Map_Entry<EXT_ID, INT_ID> *table_;
00454 
00455   /// Total size of the hash table.
00456   size_t total_size_;
00457 
00458   /// Current number of entries in the table (note that this can be
00459   /// larger than <total_size_> due to the bucket chaining).
00460   size_t cur_size_;
00461 
00462   // = Disallow these operations.
00463   ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID,  HASH_KEY, COMPARE_KEYS, ACE_LOCK> &))
00464   ACE_UNIMPLEMENTED_FUNC (ACE_Hash_Map_Manager_Ex (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID,  HASH_KEY, COMPARE_KEYS, ACE_LOCK> &))
00465 };
00466 
00467 /**
00468  * @class ACE_Hash_Map_Iterator_Base_Ex
00469  *
00470  * @brief Base iterator for the <ACE_Hash_Map_Manager_Ex>
00471  *
00472  * This class factors out common code from its templatized
00473  * subclasses.
00474  */
00475 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00476 class ACE_Hash_Map_Iterator_Base_Ex
00477 {
00478 public:
00479   // = Initialization method.
00480   /// Contructor.  If head != 0, the iterator constructed is positioned
00481   /// at the head of the map, it is positioned at the end otherwise.
00482   ACE_Hash_Map_Iterator_Base_Ex (ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
00483                                  int head);
00484 
00485   // = ITERATION methods.
00486 
00487   /// Pass back the next <entry> that hasn't been seen in the Set.
00488   /// Returns 0 when all items have been seen, else 1.
00489   int next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&next_entry) const;
00490 
00491   /// Returns 1 when all items have been seen, else 0.
00492   int done (void) const;
00493 
00494   /// Returns a reference to the interal element <this> is pointing to.
00495   ACE_Hash_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
00496 
00497   /// Returns reference the Hash_Map_Manager_Ex that is being iterated
00498   /// over.
00499   ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>& map (void);
00500 
00501   /// Check if two iterators point to the same position
00502   int operator== (const ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
00503   int operator!= (const ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
00504 
00505   /// Declare the dynamic allocation hooks.
00506   ACE_ALLOC_HOOK_DECLARE;
00507 
00508 protected:
00509   /// Move forward by one element in the set.  Returns 0 when there's
00510   /// no more item in the set after the current items, else 1.
00511   int forward_i (void);
00512 
00513   /// Move backward by one element in the set.  Returns 0 when there's
00514   /// no more item in the set before the current item, else 1.
00515   int reverse_i (void);
00516 
00517   /// Dump the state of an object.
00518   void dump_i (void) const;
00519 
00520   /// Map we are iterating over.
00521   ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> *map_man_;
00522 
00523   /// Keeps track of how far we've advanced in the table.
00524   ssize_t index_;
00525 
00526   /// Keeps track of how far we've advanced in a linked list in each
00527   /// table slot.
00528   ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
00529 };
00530 
00531 /**
00532  * @class ACE_Hash_Map_Const_Iterator_Base_Ex
00533  *
00534  * @brief Base const iterator for the <ACE_Hash_Map_Manager_Ex>
00535  *
00536  * This class factors out common code from its templatized
00537  * subclasses.
00538  */
00539 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00540 class ACE_Hash_Map_Const_Iterator_Base_Ex
00541 {
00542 public:
00543   // = Initialization method.
00544   /// Contructor.  If head != 0, the iterator constructed is positioned
00545   /// at the head of the map, it is positioned at the end otherwise.
00546   ACE_Hash_Map_Const_Iterator_Base_Ex (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
00547                                        int head);
00548 
00549   // = ITERATION methods.
00550 
00551   /// Pass back the next <entry> that hasn't been seen in the Set.
00552   /// Returns 0 when all items have been seen, else 1.
00553   int next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&next_entry) const;
00554 
00555   /// Returns 1 when all items have been seen, else 0.
00556   int done (void) const;
00557 
00558   /// Returns a reference to the interal element <this> is pointing to.
00559   ACE_Hash_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
00560 
00561   /// Returns reference the Hash_Map_Manager_Ex that is being iterated
00562   /// over.
00563   const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>& map (void);
00564 
00565   /// Check if two iterators point to the same position
00566   int operator== (const ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
00567   int operator!= (const ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
00568 
00569   /// Declare the dynamic allocation hooks.
00570   ACE_ALLOC_HOOK_DECLARE;
00571 
00572 protected:
00573   /// Move forward by one element in the set.  Returns 0 when there's
00574   /// no more item in the set after the current items, else 1.
00575   int forward_i (void);
00576 
00577   /// Move backward by one element in the set.  Returns 0 when there's
00578   /// no more item in the set before the current item, else 1.
00579   int reverse_i (void);
00580 
00581   /// Dump the state of an object.
00582   void dump_i (void) const;
00583 
00584   /// Map we are iterating over.
00585   const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> *map_man_;
00586 
00587   /// Keeps track of how far we've advanced in the table.
00588   ssize_t index_;
00589 
00590   /// Keeps track of how far we've advanced in a linked list in each
00591   /// table slot.
00592   ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
00593 };
00594 
00595 /**
00596  * @class ACE_Hash_Map_Iterator_Ex
00597  *
00598  * @brief Forward iterator for the <ACE_Hash_Map_Manager_Ex>.
00599  *
00600  * This class does not perform any internal locking of the
00601  * <ACE_Hash_Map_Manager_Ex> it is iterating upon since locking is
00602  * inherently inefficient and/or error-prone within an STL-style
00603  * iterator.  If you require locking, you can explicitly use an
00604  * <ACE_Guard> or <ACE_Read_Guard> on the <ACE_Hash_Map_Manager_Ex>'s
00605  * internal lock, which is accessible via its <mutex> method.
00606  */
00607 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00608 class ACE_Hash_Map_Iterator_Ex : public ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00609 {
00610 public:
00611   // = Initialization method.
00612   ACE_Hash_Map_Iterator_Ex (ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
00613                             int tail = 0);
00614 
00615   // = Iteration methods.
00616   /// Move forward by one element in the set.  Returns 0 when all the
00617   /// items in the set have been seen, else 1.
00618   int advance (void);
00619 
00620   /// Dump the state of an object.
00621   void dump (void) const;
00622 
00623   // = STL styled iteration, compare, and reference functions.
00624 
00625   /// Prefix advance.
00626   ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
00627 
00628   /// Postfix advance.
00629   ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
00630 
00631   /// Prefix reverse.
00632   ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
00633 
00634   /// Postfix reverse.
00635   ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
00636 
00637   /// Declare the dynamic allocation hooks.
00638   ACE_ALLOC_HOOK_DECLARE;
00639 };
00640 
00641 /**
00642  * @class ACE_Hash_Map_Const_Iterator_Ex
00643  *
00644  * @brief Const forward iterator for the <ACE_Hash_Map_Manager_Ex>.
00645  *
00646  * This class does not perform any internal locking of the
00647  * <ACE_Hash_Map_Manager_Ex> it is iterating upon since locking is
00648  * inherently inefficient and/or error-prone within an STL-style
00649  * iterator.  If you require locking, you can explicitly use an
00650  * <ACE_Guard> or <ACE_Read_Guard> on the <ACE_Hash_Map_Manager_Ex>'s
00651  * internal lock, which is accessible via its <mutex> method.
00652  */
00653 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00654 class ACE_Hash_Map_Const_Iterator_Ex : public ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00655 {
00656 public:
00657   // = Initialization method.
00658   ACE_Hash_Map_Const_Iterator_Ex (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
00659                                   int tail = 0);
00660 
00661   // = Iteration methods.
00662   /// Move forward by one element in the set.  Returns 0 when all the
00663   /// items in the set have been seen, else 1.
00664   int advance (void);
00665 
00666   /// Dump the state of an object.
00667   void dump (void) const;
00668 
00669   // = STL styled iteration, compare, and reference functions.
00670 
00671   /// Prefix advance.
00672   ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
00673 
00674   /// Postfix advance.
00675   ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
00676 
00677   /// Prefix reverse.
00678   ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
00679 
00680   /// Postfix reverse.
00681   ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
00682 
00683   /// Declare the dynamic allocation hooks.
00684   ACE_ALLOC_HOOK_DECLARE;
00685 };
00686 
00687 /**
00688  * @class ACE_Hash_Map_Bucket_Iterator
00689  *
00690  * @brief Forward iterator for the <ACE_Hash_Map_Manager_Ex> which only
00691  * traverses a particular bucket.  The particular bucket is
00692  * specified by the <EXT_ID> parameter specified in the
00693  * constructor.
00694  *
00695  * This class does not perform any internal locking of the
00696  * <ACE_Hash_Map_Manager_Ex> it is iterating upon since locking
00697  * is inherently inefficient and/or error-prone within an
00698  * STL-style iterator.  If you require locking, you can
00699  * explicitly use an <ACE_Guard> or <ACE_Read_Guard> on the
00700  * <ACE_Hash_Map_Manager_Ex>'s internal lock, which is
00701  * accessible via its <mutex> method.
00702  * Note that this iterator cannot be created by calling a method
00703  * on the map, since this would require adding explicit template
00704  * instantiations for bucket iterators on platforms with broken
00705  * templates.
00706  */
00707 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00708 class ACE_Hash_Map_Bucket_Iterator
00709 {
00710 public:
00711   // = Initialization method.
00712   ACE_Hash_Map_Bucket_Iterator (ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
00713                                 const EXT_ID &ext_id,
00714                                 int tail = 0);
00715 
00716   // = STL styled iteration, compare, and reference functions.
00717 
00718   /// Prefix advance.
00719   ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
00720 
00721   /// Postfix advance.
00722   ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
00723 
00724   /// Prefix reverse.
00725   ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
00726 
00727   /// Postfix reverse.
00728   ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
00729 
00730   /// Returns a reference to the interal element <this> is pointing to.
00731   ACE_Hash_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
00732 
00733   /// Returns reference the Hash_Map_Manager_Ex that is being iterated
00734   /// over.
00735   ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>& map (void);
00736 
00737   /// Check if two iterators point to the same position
00738   int operator== (const ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
00739   int operator!= (const ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
00740 
00741 protected:
00742   /// Move forward by one element in the set.  Returns 0 when there's
00743   /// no more item in the set after the current items, else 1.
00744   int forward_i (void);
00745 
00746   /// Move backward by one element in the set.  Returns 0 when there's
00747   /// no more item in the set before the current item, else 1.
00748   int reverse_i (void);
00749 
00750   /// Map we are iterating over.
00751   ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> *map_man_;
00752 
00753   /// Keeps track of how far we've advanced in the table.
00754   ssize_t index_;
00755 
00756   /// Keeps track of how far we've advanced in a linked list in each
00757   /// table slot.
00758   ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
00759 };
00760 
00761 /**
00762  * @class ACE_Hash_Map_Reverse_Iterator_Ex
00763  *
00764  * @brief Reverse iterator for the <ACE_Hash_Map_Manager_Ex>.
00765  *
00766  * This class does not perform any internal locking of the
00767  * <ACE_Hash_Map_Manager_Ex> it is iterating upon since locking is
00768  * inherently inefficient and/or error-prone within an STL-style
00769  * iterator.  If you require locking, you can explicitly use an
00770  * <ACE_Guard> or <ACE_Read_Guard> on the <ACE_Hash_Map_Manager_Ex>'s
00771  * internal lock, which is accessible via its <mutex> method.
00772  */
00773 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
00774 class ACE_Hash_Map_Reverse_Iterator_Ex : public ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
00775 {
00776 public:
00777   // = Initialization method.
00778   ACE_Hash_Map_Reverse_Iterator_Ex (ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
00779                                     int head = 0);
00780 
00781   // = Iteration methods.
00782   /// Move forward by one element in the set.  Returns 0 when all the
00783   /// items in the set have been seen, else 1.
00784   int advance (void);
00785 
00786   /// Dump the state of an object.
00787   void dump (void) const;
00788 
00789   // = STL styled iteration, compare, and reference functions.
00790 
00791   /// Prefix reverse.
00792   ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
00793 
00794   /// Postfix reverse.
00795   ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
00796 
00797   /// Prefix advance.
00798   ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
00799 
00800   /// Postfix advance.
00801   ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
00802 
00803   /// Declare the dynamic allocation hooks.
00804   ACE_ALLOC_HOOK_DECLARE;
00805 };
00806 
00807 /**
00808  * @class ACE_Hash_Map_Manager
00809  *
00810  * @brief Wrapper for backward compatibility.
00811  *
00812  * This implementation of a map uses a hash table.  This class
00813  * expects that the <EXT_ID> contains a method called <hash>.
00814  * In addition, the <EXT_ID> must support <operator==>.  Both of
00815  * these constraints can be alleviated via template
00816  * specialization, as shown in the $ACE_ROOT/tests/Conn_Test.cpp
00817  * test.
00818  *
00819  * <b> Requirements and Performance Characteristics</b>
00820  *   - Internal Structure
00821  *       Hash Table
00822  *   - Duplicates allowed?
00823  *       No
00824  *   - Random access allowed?
00825  *       Yes
00826  *   - Search speed
00827  *       O(1)
00828  *   - Insert/replace speed
00829  *       O(1), can be longer if the hash map has to resize
00830  *   - Iterator still valid after change to container?
00831  *       Yes
00832  *   - Frees memory for removed elements?
00833  *       Yes
00834  *   - Items inserted by
00835  *       Value
00836  *   - Requirements for key type
00837  *       -# Default constructor
00838  *       -# Copy constructor
00839  *       -# operator=
00840  *       -# operator==
00841  *   - Requirements for object type
00842  *       -# Default constructor
00843  *       -# Copy constructor
00844  *       -# operator=
00845  *       -# operator<
00846  */
00847 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00848 class ACE_Hash_Map_Manager : public ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>
00849 {
00850 public:
00851   /// Initialize a <Hash_Map_Manager> with default size.
00852   ACE_Hash_Map_Manager (ACE_Allocator *alloc = 0);
00853 
00854   /// Initialize a <Hash_Map_Manager> with size <length>.
00855   ACE_Hash_Map_Manager (size_t size,
00856                         ACE_Allocator *alloc = 0);
00857 
00858   // = The following two are necessary for template specialization of
00859   // ACE_Hash_Map_Manager to work.
00860   int equal (const EXT_ID &id1, const EXT_ID &id2);
00861   u_long hash (const EXT_ID &ext_id);
00862 };
00863 
00864 /**
00865  * @class ACE_Hash_Map_Iterator
00866  *
00867  * @brief Wrapper for backward compatibility.
00868  */
00869 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00870 class ACE_Hash_Map_Iterator : public ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>
00871 {
00872 public:
00873   // = Initialization method.
00874   /// Construct from map
00875   ACE_Hash_Map_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
00876                          int tail = 0);
00877 
00878   /// Construct from base
00879   ACE_Hash_Map_Iterator (const ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
00880 
00881   /// Assignment from base
00882   ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
00883   operator= (const ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
00884 };
00885 
00886 /**
00887  * @class ACE_Hash_Map_Const_Iterator
00888  *
00889  * @brief Wrapper for backward compatibility.
00890  */
00891 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00892 class ACE_Hash_Map_Const_Iterator : public ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>
00893 {
00894 public:
00895   // = Initialization method.
00896   /// Construct from map
00897   ACE_Hash_Map_Const_Iterator (const ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
00898                                int tail = 0);
00899 
00900   /// Construct from base
00901   ACE_Hash_Map_Const_Iterator (const ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
00902 
00903   /// Assignment from base
00904   ACE_Hash_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
00905   operator= (const ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
00906 };
00907 
00908 /**
00909  * @class ACE_Hash_Map_Reverse_Iterator
00910  *
00911  * @brief Wrapper for backward compatibility.
00912  */
00913 template <class EXT_ID, class INT_ID, class ACE_LOCK>
00914 class ACE_Hash_Map_Reverse_Iterator : public ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>
00915 {
00916 public:
00917   // = Initialization method.
00918   ACE_Hash_Map_Reverse_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
00919                                  int head = 0);
00920 
00921   /// Construct from base
00922   ACE_Hash_Map_Reverse_Iterator (const ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
00923 
00924   /// Assignment from base
00925   ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
00926   operator= (const ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
00927 };
00928 
00929 #if defined (__ACE_INLINE__)
00930 // Include ace/Hash_Map_Manager_T.i on all platforms excluding SunCC.
00931 // This nonsense is necessary since SunCC (version 4.2) cannot inline
00932 // the code in ace/Hash_Map_Manager_T.i (with the fast option).
00933 # if !(defined (__SUNPRO_CC) && (__SUNPRO_CC == 0x420))
00934 #  include "ace/Hash_Map_Manager_T.i"
00935 # endif /* ! __SUNPRO_CC */
00936 #endif /* __ACE_INLINE__ */
00937 
00938 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00939 #include "ace/Hash_Map_Manager_T.cpp"
00940 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00941 
00942 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00943 #pragma implementation ("Hash_Map_Manager_T.cpp")
00944 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00945 
00946 #include "ace/post.h"
00947 #endif /* ACE_HASH_MAP_MANAGER_T_H */

Generated on Mon Jun 16 11:19:49 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002