[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Hash_Map_Manager_T.h
blob7585b1961bb7b11ddfa7abddd916c59353cb7ccf
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Hash_Map_Manager_T.h
7 * $Id: Hash_Map_Manager_T.h 81735 2008-05-19 19:14:10Z johnnyw $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
11 //=============================================================================
13 #ifndef ACE_HASH_MAP_MANAGER_T_H
14 #define ACE_HASH_MAP_MANAGER_T_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/config-all.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/Default_Constants.h"
24 #include "ace/Functor_T.h"
25 #include "ace/Log_Msg.h"
26 #include <iterator>
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 /**
31 * @class ACE_Hash_Map_Entry
33 * @brief Define an entry in the hash table.
35 template <class EXT_ID, class INT_ID>
36 class ACE_Hash_Map_Entry
38 public:
39 // = Initialization and termination methods.
40 /// Constructor.
41 ACE_Hash_Map_Entry (const EXT_ID &ext_id,
42 const INT_ID &int_id,
43 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next = 0,
44 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev = 0);
46 /// Constructor.
47 ACE_Hash_Map_Entry (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next,
48 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev);
50 /// Destructor.
51 ~ACE_Hash_Map_Entry (void);
53 /// Key accessor.
54 EXT_ID& key (void);
56 /// Item accessor.
57 INT_ID& item (void);
59 /// Key used to look up an entry.
60 /// @deprecated Use key()
61 EXT_ID ext_id_;
63 /// The contents of the entry itself.
64 /// @deprecated Use item()
65 INT_ID int_id_;
67 /// Pointer to the next item in the bucket of overflow nodes.
68 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
70 /// Pointer to the prev item in the bucket of overflow nodes.
71 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *prev_;
73 /// Dump the state of an object.
74 void dump (void) const;
77 // Forward decl.
78 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
79 class ACE_Hash_Map_Iterator_Base_Ex;
81 // Forward decl.
82 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
83 class ACE_Hash_Map_Const_Iterator_Base_Ex;
85 // Forward decl.
86 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
87 class ACE_Hash_Map_Iterator_Ex;
89 // Forward decl.
90 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
91 class ACE_Hash_Map_Const_Iterator_Ex;
93 // Forward decl.
94 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
95 class ACE_Hash_Map_Reverse_Iterator_Ex;
97 // Forward decl.
98 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
99 class ACE_Hash_Map_Const_Reverse_Iterator_Ex;
101 // Forward decl.
102 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
103 class ACE_Hash_Map_Bucket_Iterator;
105 // Forward decl.
106 class ACE_Allocator;
109 * @class ACE_Hash_Map_Manager_Ex
111 * @brief Define a map abstraction that efficiently associates
112 * @c EXT_ID type objects with @c INT_ID type objects.
114 * This implementation of a map uses a hash table. Key hashing
115 * is achieved through the @c HASH_KEY object and key comparison is
116 * achieved through the @c COMPARE_KEYS object.
117 * This class uses an ACE_Allocator to allocate memory. The
118 * user can make this a persistent class by providing an
119 * ACE_Allocator with a persistable memory pool.
122 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
123 class ACE_Hash_Map_Manager_Ex
125 public:
126 friend class ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
127 friend class ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
128 friend class ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
129 friend class ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
130 friend class ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
131 friend class ACE_Hash_Map_Const_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
132 friend class ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>;
134 typedef EXT_ID
135 KEY;
136 typedef INT_ID
137 VALUE;
138 typedef ACE_LOCK lock_type;
139 typedef ACE_Hash_Map_Entry<EXT_ID, INT_ID>
140 ENTRY;
142 // = ACE-style iterator typedefs.
143 typedef ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
144 ITERATOR;
145 typedef ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
146 CONST_ITERATOR;
147 typedef ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
148 REVERSE_ITERATOR;
149 typedef ACE_Hash_Map_Const_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
150 CONST_REVERSE_ITERATOR;
152 // = STL-style iterator typedefs.
153 typedef ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
154 iterator;
155 typedef ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
156 const_iterator;
157 typedef ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
158 reverse_iterator;
159 typedef ACE_Hash_Map_Const_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
160 const_reverse_iterator;
162 // = STL-style typedefs/traits.
163 typedef EXT_ID key_type;
164 typedef INT_ID data_type;
165 typedef ACE_Hash_Map_Entry<EXT_ID, INT_ID> value_type;
166 typedef value_type & reference;
167 typedef value_type const & const_reference;
168 typedef value_type * pointer;
169 typedef value_type const * const_pointer;
170 typedef ptrdiff_t difference_type;
171 typedef size_t size_type;
173 // = Initialization and termination methods.
176 * Initialize an ACE_Hash_Map_Manager_Ex with a default number of elements.
178 * @param table_alloc is a pointer to a memory allocator used for
179 * table_, so it should supply size*sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>).
180 * If @a table_alloc is 0 it defaults to ACE_Allocator::instance().
181 * @param entry_alloc is a pointer to an additional allocator for
182 * entries, so it should be able to allocate 'size' / chunks
183 * of sizeof(ACE_Hash_Map_Entry<EXT_ID, INT_ID>) bytes each.
184 * If @a entry_alloc is 0 it defaults to the same allocator as
185 * @a table_alloc.
187 ACE_Hash_Map_Manager_Ex (ACE_Allocator *table_alloc = 0,
188 ACE_Allocator *entry_alloc = 0);
191 * Initialize an ACE_Hash_Map_Manager_Ex with @a size elements.
193 * @param table_alloc is a pointer to a memory allocator used for
194 * table_, so it should supply size*sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>).
195 * If @a table_alloc is 0 it defaults to ACE_Allocator::instance().
196 * @param entry_alloc is a pointer to an additional allocator for
197 * entries, so it should be able to allocate 'size' / chunks
198 * of sizeof(ACE_Hash_Map_Entry<EXT_ID, INT_ID>) bytes each.
199 * If @a entry_alloc is 0 it defaults to the same allocator as
200 * @a table_alloc.
202 ACE_Hash_Map_Manager_Ex (size_t size,
203 ACE_Allocator *table_alloc = 0,
204 ACE_Allocator *entry_alloc = 0);
207 * Initialize an ACE_Hash_Map_Manager_Ex with @a size elements.
208 * @param table_alloc is a pointer to a memory allocator used for
209 * table_, so it should supply size*sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>).
210 * If @a table_alloc is 0 it defaults to ACE_Allocator::instance().
211 * @param entry_alloc is a pointer to an additional allocator for
212 * entries, so it should be able to allocate 'size' / chunks
213 * of sizeof(ACE_Hash_Map_Entry<EXT_ID, INT_ID>) bytes each.
214 * If @a entry_alloc is 0 then it defaults to the same allocator as
215 * @a table_alloc.
216 * @return -1 on failure, 0 on success
219 int open (size_t size = ACE_DEFAULT_MAP_SIZE,
220 ACE_Allocator *table_alloc = 0,
221 ACE_Allocator *entry_alloc = 0);
223 /// Close down the ACE_Hash_Map_Manager_Ex and release dynamically allocated
224 /// resources.
225 int close (void);
227 /// Removes all the entries in the ACE_Hash_Map_Manager_Ex.
228 int unbind_all (void);
230 /// Cleanup the ACE_Hash_Map_Manager_Ex.
231 ~ACE_Hash_Map_Manager_Ex (void);
234 * Associate @a item with @a int_id. If @a item is already in the
235 * map then the map is not changed.
237 * @retval 0 if a new entry is bound successfully.
238 * @retval 1 if an attempt is made to bind an existing entry.
239 * @retval -1 if a failure occurs; check @c errno for more information.
241 int bind (const EXT_ID &item,
242 const INT_ID &int_id);
245 * Same as a normal bind, except the map entry is also passed back
246 * to the caller. The entry in this case will either be the newly
247 * created entry, or the existing one.
249 int bind (const EXT_ID &ext_id,
250 const INT_ID &int_id,
251 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
254 * Associate @a ext_id with @a int_id if and only if @a ext_id is not
255 * in the map. If @a ext_id is already in the map then the @a int_id
256 * parameter is assigned the existing value in the map. Returns 0
257 * if a new entry is bound successfully, returns 1 if an attempt is
258 * made to bind an existing entry, and returns -1 if failures occur.
260 int trybind (const EXT_ID &ext_id,
261 INT_ID &int_id);
264 * Same as a normal trybind, except the map entry is also passed
265 * back to the caller. The entry in this case will either be the
266 * newly created entry, or the existing one.
268 int trybind (const EXT_ID &ext_id,
269 INT_ID &int_id,
270 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
273 * Reassociate @a ext_id with @a int_id. If @a ext_id is not in the
274 * map then behaves just like <bind>. Returns 0 if a new entry is
275 * bound successfully, returns 1 if an existing entry was rebound,
276 * and returns -1 if failures occur.
278 int rebind (const EXT_ID &ext_id,
279 const INT_ID &int_id);
282 * Same as a normal rebind, except the map entry is also passed back
283 * to the caller. The entry in this case will either be the newly
284 * created entry, or the existing one.
286 int rebind (const EXT_ID &ext_id,
287 const INT_ID &int_id,
288 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
291 * Associate @a ext_id with @a int_id. If @a ext_id is not in the map
292 * then behaves just like <bind>. Otherwise, store the old value of
293 * @a int_id into the "out" parameter and rebind the new parameters.
294 * Returns 0 if a new entry is bound successfully, returns 1 if an
295 * existing entry was rebound, and returns -1 if failures occur.
297 int rebind (const EXT_ID &ext_id,
298 const INT_ID &int_id,
299 INT_ID &old_int_id);
302 * Same as a normal rebind, except the map entry is also passed back
303 * to the caller. The entry in this case will either be the newly
304 * created entry, or the existing one.
306 int rebind (const EXT_ID &ext_id,
307 const INT_ID &int_id,
308 INT_ID &old_int_id,
309 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
312 * Associate @a ext_id with @a int_id. If @a ext_id is not in the map
313 * then behaves just like <bind>. Otherwise, store the old values
314 * of @a ext_id and @a int_id into the "out" parameters and rebind the
315 * new parameters. This is very useful if you need to have an
316 * atomic way of updating ACE_Hash_Map_Entrys and you also need
317 * full control over memory allocation. Returns 0 if a new entry is
318 * bound successfully, returns 1 if an existing entry was rebound,
319 * and returns -1 if failures occur.
321 int rebind (const EXT_ID &ext_id,
322 const INT_ID &int_id,
323 EXT_ID &old_ext_id,
324 INT_ID &old_int_id);
327 * Same as a normal rebind, except the map entry is also passed back
328 * to the caller. The entry in this case will either be the newly
329 * created entry, or the existing one.
331 int rebind (const EXT_ID &ext_id,
332 const INT_ID &int_id,
333 EXT_ID &old_ext_id,
334 INT_ID &old_int_id,
335 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
337 /// Locate @a ext_id and pass out parameter via @a int_id.
338 /// Return 0 if found, returns -1 if not found.
339 int find (const EXT_ID &ext_id,
340 INT_ID &int_id) const;
342 /// Returns 0 if the @a ext_id is in the mapping, otherwise -1.
343 int find (const EXT_ID &ext_id) const;
345 /// Locate @a ext_id and pass out parameter via @a entry. If found,
346 /// return 0, returns -1 if not found.
347 int find (const EXT_ID &ext_id,
348 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry) const;
350 /// Locate @a ext_id and pass out an iterator that points to its
351 /// corresponding value.
353 * @param pos @a pos will be set to @c end() if not found.
355 void find (EXT_ID const & ext_id, iterator & pos) const;
358 * Unbind (remove) the @a ext_id from the map. Don't return the
359 * @a int_id to the caller (this is useful for collections where the
360 * @a int_ids are *not* dynamically allocated...)
362 int unbind (const EXT_ID &ext_id);
364 /// Break any association of @a ext_id. Returns the value of @a int_id
365 /// in case the caller needs to deallocate memory. Return 0 if the
366 /// unbind was successful, and returns -1 if failures occur.
367 int unbind (const EXT_ID &ext_id,
368 INT_ID &int_id);
370 /// Remove entry from map.
372 * This unbind operation is fast relative to those that accept an
373 * external ID parameter since no map lookup is performed.
375 * @return 0 if the unbind was successful, and -1 if failures
376 * occur.
378 int unbind (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *entry);
380 /// Remove entry from map pointed to by @c iterator @a pos.
382 * This unbind operation is fast relative to those that accept an
383 * external ID parameter since no map lookup is performed.
385 * @return 0 if the unbind was successful, and -1 if failures
386 * occur.
388 int unbind (iterator pos);
390 /// Returns the current number of ACE_Hash_Map_Entry objects in the
391 /// hash table.
392 size_t current_size (void) const;
394 /// Return the size of the array that's used to point to the
395 /// linked lists of ACE_Hash_Map_Entry objects in the hash table.
396 size_t total_size (void) const;
399 * Returns a reference to the underlying <ACE_LOCK>. This makes it
400 * possible to acquire the lock explicitly, which can be useful in
401 * some cases if you instantiate the ACE_Atomic_Op with an
402 * ACE_Recursive_Mutex or ACE_Process_Mutex, or if you need to
403 * guard the state of an iterator.
404 * @note The right name would be <lock>, but HP/C++ will choke on that!
406 ACE_LOCK &mutex (void);
408 /// Dump the state of an object.
409 void dump (void) const;
411 // = STL styled iterator factory functions.
413 /// Return forward iterator.
414 iterator begin (void);
415 iterator end (void);
416 const_iterator begin (void) const;
417 const_iterator end (void) const;
419 /// Return reverse iterator.
420 reverse_iterator rbegin (void);
421 reverse_iterator rend (void);
422 const_reverse_iterator rbegin (void) const;
423 const_reverse_iterator rend (void) const;
425 protected:
426 // = The following methods do the actual work.
428 /// Returns 1 if <id1> == <id2>, else 0. This is defined as a
429 /// separate method to facilitate template specialization.
430 int equal (const EXT_ID &id1, const EXT_ID &id2);
432 /// Compute the hash value of the @a ext_id. This is defined as a
433 /// separate method to facilitate template specialization.
434 u_long hash (const EXT_ID &ext_id);
436 // = These methods assume locks are held by private methods.
438 /// Performs bind. Must be called with locks held.
439 int bind_i (const EXT_ID &ext_id,
440 const INT_ID &int_id);
442 /// Performs bind. Must be called with locks held.
443 int bind_i (const EXT_ID &ext_id,
444 const INT_ID &int_id,
445 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
447 /// Performs trybind. Must be called with locks held.
448 int trybind_i (const EXT_ID &ext_id,
449 INT_ID &int_id);
451 /// Performs trybind. Must be called with locks held.
452 int trybind_i (const EXT_ID &ext_id,
453 INT_ID &int_id,
454 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
456 /// Performs rebind. Must be called with locks held.
457 int rebind_i (const EXT_ID &ext_id,
458 const INT_ID &int_id);
460 /// Performs rebind. Must be called with locks held.
461 int rebind_i (const EXT_ID &ext_id,
462 const INT_ID &int_id,
463 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
465 /// Performs rebind. Must be called with locks held.
466 int rebind_i (const EXT_ID &ext_id,
467 const INT_ID &int_id,
468 INT_ID &old_int_id);
470 /// Performs rebind. Must be called with locks held.
471 int rebind_i (const EXT_ID &ext_id,
472 const INT_ID &int_id,
473 INT_ID &old_int_id,
474 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
476 /// Performs rebind. Must be called with locks held.
477 int rebind_i (const EXT_ID &ext_id,
478 const INT_ID &int_id,
479 EXT_ID &old_ext_id,
480 INT_ID &old_int_id);
482 /// Performs rebind. Must be called with locks held.
483 int rebind_i (const EXT_ID &ext_id,
484 const INT_ID &int_id,
485 EXT_ID &old_ext_id,
486 INT_ID &old_int_id,
487 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
489 /// Performs a find of @a int_id using @a ext_id as the key. Must be
490 /// called with locks held.
491 int find_i (const EXT_ID &ext_id,
492 INT_ID &int_id);
494 /// Performs a find using @a ext_id as the key. Must be called with
495 /// locks held.
496 int find_i (const EXT_ID &ext_id);
498 /// Performs a find using @a ext_id as the key. Must be called with
499 /// locks held.
500 int find_i (const EXT_ID &ext_id,
501 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry);
503 /// Performs unbind. Must be called with locks held.
504 int unbind_i (const EXT_ID &ext_id,
505 INT_ID &int_id);
507 /// Performs unbind. Must be called with locks held.
508 int unbind_i (const EXT_ID &ext_id);
510 /// Performs unbind. Must be called with locks held.
511 int unbind_i (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *entry);
514 * Resize the map. Must be called with locks held.
515 * @note This method should never be called more than once or else all the
516 * hashing will get screwed up as the size will change.
518 int create_buckets (size_t size);
520 /// Close down a <Map_Manager_Ex>. Must be called with
521 /// locks held.
522 int close_i (void);
524 /// Removes all the entries in <Map_Manager_Ex>. Must be called with
525 /// locks held.
526 int unbind_all_i (void);
528 /// Pointer to a memory allocator used for table_, so it should
529 /// supply size*sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>),
530 ACE_Allocator *table_allocator_;
532 /// Addidtional allocator for entries, so it should be able to
533 /// allocate 'size' / chunks of sizeof(ACE_Hash_Map_Entry<EXT_ID,
534 /// INT_ID>) bytes each.
535 ACE_Allocator *entry_allocator_;
537 /// Synchronization variable for the MT_SAFE
538 /// @c ACE_Hash_Map_Manager_Ex.
539 mutable ACE_LOCK lock_;
541 /// Function object used for hashing keys.
542 HASH_KEY hash_key_;
544 /// Function object used for comparing keys.
545 COMPARE_KEYS compare_keys_;
547 protected:
548 /// Returns the ACE_Hash_Map_Entry that corresponds to @a ext_id.
549 int shared_find (const EXT_ID &ext_id,
550 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&entry,
551 size_t &loc);
553 /// Accessor of the underlying table
554 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *table (void);
556 /// Accessor of the current size attribute
557 size_t cur_size (void) const;
559 private:
561 * Array of ACE_Hash_Map_Entry *s, each of which points to an
562 * ACE_Hash_Map_Entry that serves as the beginning of a linked
563 * list of <EXT_ID>s that hash to that bucket.
565 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *table_;
567 /// Total size of the hash table.
568 size_t total_size_;
570 /// Current number of entries in the table
571 /// @note That this can be larger than <total_size_> due to the
572 /// bucket chaining).
573 size_t cur_size_;
575 // = Disallow these operations.
576 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &))
577 ACE_UNIMPLEMENTED_FUNC (ACE_Hash_Map_Manager_Ex (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &))
581 * @class ACE_Hash_Map_Iterator_Base_Ex
583 * @brief Base iterator for the ACE_Hash_Map_Manager_Ex
585 * This class factors out common code from its templatized
586 * subclasses.
588 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
589 class ACE_Hash_Map_Iterator_Base_Ex
591 public:
592 // = STL-style typedefs/traits.
593 typedef ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
594 container_type;
596 // = std::iterator_traits typedefs/traits.
597 typedef typename container_type::value_type value_type;
598 typedef typename container_type::reference reference;
599 typedef typename container_type::pointer pointer;
600 typedef typename container_type::difference_type difference_type;
602 // = Initialization method.
603 /// Contructor.
605 * If @a head != @c false, the iterator constructed is positioned
606 * at the head of the map. It is positioned at the end otherwise.
607 * @par
609 ACE_Hash_Map_Iterator_Base_Ex (
610 ACE_Hash_Map_Manager_Ex<EXT_ID,
611 INT_ID,
612 HASH_KEY,
613 COMPARE_KEYS,
614 ACE_LOCK> &mm,
615 bool head);
617 /// Contructor.
619 * This constructor positions the iterator to the given @a entry.
621 ACE_Hash_Map_Iterator_Base_Ex (
622 ACE_Hash_Map_Manager_Ex<EXT_ID,
623 INT_ID,
624 HASH_KEY,
625 COMPARE_KEYS,
626 ACE_LOCK> & mm,
627 ACE_Hash_Map_Entry<EXT_ID, INT_ID> * entry,
628 size_t index);
630 // = ITERATION methods.
632 /// Pass back the next <entry> that hasn't been seen in the Set.
633 /// Returns 0 when all items have been seen, else 1.
634 int next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&next_entry) const;
636 /// Returns 1 when all items have been seen, else 0.
637 int done (void) const;
639 /// Returns a reference to the interal element @c this is pointing to.
640 ACE_Hash_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
642 /// Returns a pointer to the interal element @c this is pointing to.
643 ACE_Hash_Map_Entry<EXT_ID, INT_ID>* operator-> (void) const;
645 /// Returns reference the Hash_Map_Manager_Ex that is being iterated
646 /// over.
647 ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>& map (void);
649 /// Check if two iterators point to the same position
650 bool operator== (const ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
651 bool operator!= (const ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
653 /// Declare the dynamic allocation hooks.
654 ACE_ALLOC_HOOK_DECLARE;
656 protected:
657 /// Move forward by one element in the set. Returns 0 when there's
658 /// no more item in the set after the current items, else 1.
659 int forward_i (void);
661 /// Move backward by one element in the set. Returns 0 when there's
662 /// no more item in the set before the current item, else 1.
663 int reverse_i (void);
665 /// Dump the state of an object.
666 void dump_i (void) const;
668 /// Map we are iterating over.
669 ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> *map_man_;
671 /// Keeps track of how far we've advanced in the table.
672 ssize_t index_;
674 /// Keeps track of how far we've advanced in a linked list in each
675 /// table slot.
676 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
680 * @class ACE_Hash_Map_Const_Iterator_Base_Ex
682 * @brief Base const iterator for the ACE_Hash_Map_Manager_Ex
684 * This class factors out common code from its templatized
685 * subclasses.
687 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
688 class ACE_Hash_Map_Const_Iterator_Base_Ex
690 public:
691 // = STL-style typedefs/traits.
692 typedef ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
693 container_type;
695 // = std::iterator_traits typedefs/traits.
696 typedef typename container_type::value_type value_type;
697 typedef typename container_type::const_reference reference;
698 typedef typename container_type::const_pointer pointer;
699 typedef typename container_type::difference_type difference_type;
701 // = Initialization method.
702 /// Contructor. If head the iterator constructed is positioned
703 /// at the head of the map, it is positioned at the end otherwise.
704 ACE_Hash_Map_Const_Iterator_Base_Ex (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
705 bool head);
707 // = ITERATION methods.
709 /// Pass back the next <entry> that hasn't been seen in the Set.
710 /// Returns 0 when all items have been seen, else 1.
711 int next (ACE_Hash_Map_Entry<EXT_ID, INT_ID> *&next_entry) const;
713 /// Returns 1 when all items have been seen, else 0.
714 int done (void) const;
716 /// Returns a reference to the interal element @c this is pointing to.
717 ACE_Hash_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
719 /// Returns a pointer to the interal element @c this is pointing to.
720 ACE_Hash_Map_Entry<EXT_ID, INT_ID>* operator-> (void) const;
722 /// Returns reference the Hash_Map_Manager_Ex that is being iterated
723 /// over.
724 const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>& map (void);
726 /// Check if two iterators point to the same position
727 bool operator== (const ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
728 bool operator!= (const ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
730 /// Declare the dynamic allocation hooks.
731 ACE_ALLOC_HOOK_DECLARE;
733 protected:
734 /// Move forward by one element in the set. Returns 0 when there's
735 /// no more item in the set after the current items, else 1.
736 int forward_i (void);
738 /// Move backward by one element in the set. Returns 0 when there's
739 /// no more item in the set before the current item, else 1.
740 int reverse_i (void);
742 /// Dump the state of an object.
743 void dump_i (void) const;
745 /// Map we are iterating over.
746 const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> *map_man_;
748 /// Keeps track of how far we've advanced in the table.
749 ssize_t index_;
751 /// Keeps track of how far we've advanced in a linked list in each
752 /// table slot.
753 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
757 * @class ACE_Hash_Map_Iterator_Ex
759 * @brief Forward iterator for the ACE_Hash_Map_Manager_Ex.
761 * This class does not perform any internal locking of the
762 * ACE_Hash_Map_Manager_Ex it is iterating upon since locking is
763 * inherently inefficient and/or error-prone within an STL-style
764 * iterator. If you require locking, you can explicitly use an
765 * ACE_Guard or ACE_Read_Guard on the ACE_Hash_Map_Manager_Ex's
766 * internal lock, which is accessible via its <mutex> method.
768 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
769 class ACE_Hash_Map_Iterator_Ex : public ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
771 public:
772 // = STL-style traits/typedefs
773 typedef typename ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::container_type
774 container_type;
776 // = STL-style traits/typedefs
777 typedef std::bidirectional_iterator_tag iterator_category;
778 typedef typename container_type::value_type value_type;
779 typedef typename container_type::reference reference;
780 typedef typename container_type::pointer pointer;
781 typedef typename container_type::difference_type difference_type;
783 // = Initialization method.
784 ACE_Hash_Map_Iterator_Ex (ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
785 int tail = 0);
787 /// Contructor.
789 * This constructor positions the iterator to the given @a entry.
791 ACE_Hash_Map_Iterator_Ex (
792 ACE_Hash_Map_Manager_Ex<EXT_ID,
793 INT_ID,
794 HASH_KEY,
795 COMPARE_KEYS,
796 ACE_LOCK> & mm,
797 ACE_Hash_Map_Entry<EXT_ID, INT_ID> * entry,
798 size_t index);
800 // = Iteration methods.
801 /// Move forward by one element in the set. Returns 0 when all the
802 /// items in the set have been seen, else 1.
803 int advance (void);
805 /// Dump the state of an object.
806 void dump (void) const;
808 // = STL styled iteration, compare, and reference functions.
810 /// Prefix advance.
811 ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
813 /// Postfix advance.
814 ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
816 /// Prefix reverse.
817 ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
819 /// Postfix reverse.
820 ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
822 /// Declare the dynamic allocation hooks.
823 ACE_ALLOC_HOOK_DECLARE;
827 * @class ACE_Hash_Map_Const_Iterator_Ex
829 * @brief Const forward iterator for the ACE_Hash_Map_Manager_Ex.
831 * This class does not perform any internal locking of the
832 * ACE_Hash_Map_Manager_Ex it is iterating upon since locking is
833 * inherently inefficient and/or error-prone within an STL-style
834 * iterator. If you require locking, you can explicitly use an
835 * ACE_Guard or ACE_Read_Guard on the ACE_Hash_Map_Manager_Ex's
836 * internal lock, which is accessible via its <mutex> method.
838 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
839 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>
841 public:
842 // = STL-style traits/typedefs
843 typedef typename ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::container_type
844 container_type;
846 // = std::iterator_trait traits/typedefs
847 typedef std::bidirectional_iterator_tag iterator_category;
848 typedef typename container_type::value_type value_type;
849 typedef typename container_type::reference reference;
850 typedef typename container_type::pointer pointer;
851 typedef typename container_type::difference_type difference_type;
853 // = Initialization method.
854 ACE_Hash_Map_Const_Iterator_Ex (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
855 int tail = 0);
857 // = Iteration methods.
858 /// Move forward by one element in the set. Returns 0 when all the
859 /// items in the set have been seen, else 1.
860 int advance (void);
862 /// Dump the state of an object.
863 void dump (void) const;
865 // = STL styled iteration, compare, and reference functions.
867 /// Prefix advance.
868 ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
870 /// Postfix advance.
871 ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
873 /// Prefix reverse.
874 ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
876 /// Postfix reverse.
877 ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
879 /// Declare the dynamic allocation hooks.
880 ACE_ALLOC_HOOK_DECLARE;
884 * @class ACE_Hash_Map_Bucket_Iterator
886 * @brief Forward iterator for the ACE_Hash_Map_Manager_Ex which
887 * only traverses a particular bucket. The particular bucket is
888 * specified by the <EXT_ID> parameter specified in the constructor.
890 * This class does not perform any internal locking of the
891 * ACE_Hash_Map_Manager_Ex it is iterating upon since locking is
892 * inherently inefficient and/or error-prone within an STL-style
893 * iterator. If you require locking, you can explicitly use an
894 * ACE_Guard or ACE_Read_Guard on the ACE_Hash_Map_Manager_Ex's
895 * internal lock, which is accessible via its <mutex> method.
897 * Note that a creation method for this new iterator cannot be added
898 * to the hash map, since this would require adding explicit template
899 * instantiations for bucket iterators on platforms with broken
900 * templates.
902 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
903 class ACE_Hash_Map_Bucket_Iterator
905 public:
906 // = STL-style traits/typedefs
907 typedef ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
908 container_type;
910 // = std::iterator traits/typedefs
911 typedef std::bidirectional_iterator_tag iterator_category;
912 typedef typename container_type::value_type value_type;
913 typedef typename container_type::reference reference;
914 typedef typename container_type::pointer pointer;
915 typedef typename container_type::difference_type difference_type;
917 // = Initialization method.
918 ACE_Hash_Map_Bucket_Iterator (ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
919 const EXT_ID &ext_id,
920 int tail = 0);
922 // = STL styled iteration, compare, and reference functions.
924 /// Prefix advance.
925 ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
927 /// Postfix advance.
928 ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
930 /// Prefix reverse.
931 ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
933 /// Postfix reverse.
934 ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
936 /// Returns a reference to the interal element @c this is pointing to.
937 ACE_Hash_Map_Entry<EXT_ID, INT_ID>& operator* (void) const;
939 /// Returns a pointer to the interal element @c this is pointing to.
940 ACE_Hash_Map_Entry<EXT_ID, INT_ID>* operator-> (void) const;
942 /// Returns reference the Hash_Map_Manager_Ex that is being iterated
943 /// over.
944 ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>& map (void);
946 /// Check if two iterators point to the same position
947 bool operator== (const ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
948 bool operator!= (const ACE_Hash_Map_Bucket_Iterator<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &) const;
950 protected:
951 /// Move forward by one element in the set. Returns 0 when there's
952 /// no more item in the set after the current items, else 1.
953 int forward_i (void);
955 /// Move backward by one element in the set. Returns 0 when there's
956 /// no more item in the set before the current item, else 1.
957 int reverse_i (void);
959 /// Map we are iterating over.
960 ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> *map_man_;
962 /// Keeps track of how far we've advanced in the table.
963 ssize_t index_;
965 /// Keeps track of how far we've advanced in a linked list in each
966 /// table slot.
967 ACE_Hash_Map_Entry<EXT_ID, INT_ID> *next_;
971 * @class ACE_Hash_Map_Reverse_Iterator_Ex
973 * @brief Reverse iterator for the ACE_Hash_Map_Manager_Ex.
975 * This class does not perform any internal locking of the
976 * ACE_Hash_Map_Manager_Ex it is iterating upon since locking is
977 * inherently inefficient and/or error-prone within an STL-style
978 * iterator. If you require locking, you can explicitly use an
979 * ACE_Guard or ACE_Read_Guard on the ACE_Hash_Map_Manager_Ex's
980 * internal lock, which is accessible via its <mutex> method.
982 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
983 class ACE_Hash_Map_Reverse_Iterator_Ex : public ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
985 public:
986 // = STL-style traits/typedefs
987 typedef typename ACE_Hash_Map_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::container_type
988 container_type;
990 // = std::iterator_traits typedefs
991 typedef std::bidirectional_iterator_tag iterator_category;
992 typedef typename container_type::value_type value_type;
993 typedef typename container_type::reference reference;
994 typedef typename container_type::pointer pointer;
995 typedef typename container_type::difference_type difference_type;
997 // = Initialization method.
998 ACE_Hash_Map_Reverse_Iterator_Ex (ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
999 bool head = false);
1001 // = Iteration methods.
1002 /// Move forward by one element in the set. Returns 0 when all the
1003 /// items in the set have been seen, else 1.
1004 int advance (void);
1006 /// Dump the state of an object.
1007 void dump (void) const;
1009 // = STL styled iteration, compare, and reference functions.
1011 /// Prefix reverse.
1012 ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
1014 /// Postfix reverse.
1015 ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
1017 /// Prefix advance.
1018 ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
1020 /// Postfix advance.
1021 ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
1023 /// Declare the dynamic allocation hooks.
1024 ACE_ALLOC_HOOK_DECLARE;
1028 * @class ACE_Hash_Map_Const_Reverse_Iterator_Ex
1030 * @brief Const reverse iterator for the ACE_Hash_Map_Manager_Ex.
1032 * This class does not perform any internal locking of the
1033 * ACE_Hash_Map_Manager_Ex it is iterating upon since locking is
1034 * inherently inefficient and/or error-prone within an STL-style
1035 * iterator. If you require locking, you can explicitly use an
1036 * ACE_Guard or ACE_Read_Guard on the ACE_Hash_Map_Manager_Ex's
1037 * internal lock, which is accessible via its <mutex> method.
1039 template <class EXT_ID, class INT_ID, class HASH_KEY, class COMPARE_KEYS, class ACE_LOCK>
1040 class ACE_Hash_Map_Const_Reverse_Iterator_Ex : public ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>
1042 public:
1043 // = STL-style traits/typedefs
1044 typedef typename ACE_Hash_Map_Const_Iterator_Base_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK>::container_type
1045 container_type;
1047 // = std::iterator_traits typedefs
1048 typedef std::bidirectional_iterator_tag iterator_category;
1049 typedef typename container_type::value_type value_type;
1050 typedef typename container_type::reference reference;
1051 typedef typename container_type::pointer pointer;
1052 typedef typename container_type::difference_type difference_type;
1054 // = Initialization method.
1055 ACE_Hash_Map_Const_Reverse_Iterator_Ex (const ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &mm,
1056 bool head = false);
1058 // = Iteration methods.
1059 /// Move forward by one element in the set. Returns 0 when all the
1060 /// items in the set have been seen, else 1.
1061 int advance (void);
1063 /// Dump the state of an object.
1064 void dump (void) const;
1066 // = STL styled iteration, compare, and reference functions.
1068 /// Prefix reverse.
1069 ACE_Hash_Map_Const_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator++ (void);
1071 /// Postfix reverse.
1072 ACE_Hash_Map_Const_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator++ (int);
1074 /// Prefix advance.
1075 ACE_Hash_Map_Const_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> &operator-- (void);
1077 /// Postfix advance.
1078 ACE_Hash_Map_Const_Reverse_Iterator_Ex<EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK> operator-- (int);
1080 /// Declare the dynamic allocation hooks.
1081 ACE_ALLOC_HOOK_DECLARE;
1085 * @class ACE_Hash_Map_Manager
1087 * @brief Wrapper for backward compatibility.
1089 * This implementation of a map uses a hash table. This class
1090 * expects that the <EXT_ID> contains a method called <hash>.
1091 * In addition, the <EXT_ID> must support <operator==>. Both of
1092 * these constraints can be alleviated via template
1093 * specialization, as shown in the $ACE_ROOT/tests/Conn_Test.cpp
1094 * test.
1096 * <b> Requirements and Performance Characteristics</b>
1097 * - Internal Structure
1098 * Hash Table
1099 * - Duplicates allowed?
1100 * No
1101 * - Random access allowed?
1102 * Yes
1103 * - Search speed
1104 * O(1)
1105 * - Insert/replace speed
1106 * O(1), can be longer if the hash map has to resize
1107 * - Iterator still valid after change to container?
1108 * Yes
1109 * - Frees memory for removed elements?
1110 * Yes
1111 * - Items inserted by
1112 * Value
1113 * - Requirements for key type
1114 * -# Default constructor
1115 * -# Copy constructor
1116 * -# operator=
1117 * -# operator==
1118 * - Requirements for object type
1119 * -# Default constructor
1120 * -# Copy constructor
1121 * -# operator=
1122 * -# operator<
1124 template <class EXT_ID, class INT_ID, class ACE_LOCK>
1125 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>
1127 public:
1130 * Initialize a @c Hash_Map_Manager with default size elements.
1131 * @param table_alloc is a pointer to a memory allocator used for
1132 * table_, so it should supply size*sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>).
1133 * @param entry_alloc is a pointer to an additional allocator for
1134 * entries, so it should be able to allocate 'size' / chunks
1135 * of sizeof(ACE_Hash_Map_Entry<EXT_ID, INT_ID>) bytes each.
1136 * If @c table_alloc is 0 it defaults to @c ACE_Allocator::instance().
1137 * If @c entry_alloc is 0 then it defaults to the same allocator as
1138 * @c table_alloc.
1140 ACE_Hash_Map_Manager (ACE_Allocator *table_alloc = 0,
1141 ACE_Allocator *entry_alloc = 0);
1144 * Initialize a @c Hash_Map_Manager with @c size elements.
1145 * @param table_alloc is a pointer to a memory allocator used for
1146 * table_, so it should supply size*sizeof (ACE_Hash_Map_Entry<EXT_ID, INT_ID>).
1147 * @param entry_alloc is a pointer to an additional allocator for
1148 * entries, so it should be able to allocate 'size' / chunks
1149 * of sizeof(ACE_Hash_Map_Entry<EXT_ID, INT_ID>) bytes each.
1150 * If @c table_alloc is 0 it defaults to @c ACE_Allocator::instance().
1151 * If @c entry_alloc is 0 then it defaults to the same allocator as
1152 * @c table_alloc.
1154 ACE_Hash_Map_Manager (size_t size,
1155 ACE_Allocator *table_alloc = 0,
1156 ACE_Allocator *entry_alloc = 0);
1158 // = The following two are necessary for template specialization of
1159 // ACE_Hash_Map_Manager to work.
1160 int equal (const EXT_ID &id1, const EXT_ID &id2);
1161 u_long hash (const EXT_ID &ext_id);
1165 * @class ACE_Hash_Map_Iterator
1167 * @brief Wrapper for backward compatibility.
1169 template <class EXT_ID, class INT_ID, class ACE_LOCK>
1170 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>
1172 public:
1173 // = STL-style traits/typedefs
1174 typedef typename ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::container_type
1175 container_type;
1177 typedef typename ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::iterator_category
1178 iterator_category;
1180 typedef typename ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::value_type
1181 value_type;
1183 typedef typename ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::reference
1184 reference;
1186 typedef typename ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::pointer
1187 pointer;
1189 typedef typename ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::difference_type
1190 difference_type;
1192 // = Initialization method.
1193 /// Construct from map
1194 ACE_Hash_Map_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
1195 int tail = 0);
1197 /// Construct from base
1198 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);
1200 /// Assignment from base
1201 ACE_Hash_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
1202 operator= (const ACE_Hash_Map_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
1206 * @class ACE_Hash_Map_Const_Iterator
1208 * @brief Wrapper for backward compatibility.
1210 template <class EXT_ID, class INT_ID, class ACE_LOCK>
1211 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>
1213 public:
1214 // = STL-style traits/typedefs
1215 typedef typename ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::container_type
1216 container_type;
1218 // = std::iterator_traits typedefs
1219 typedef typename ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::iterator_category
1220 iterator_category;
1222 typedef typename ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::value_type
1223 value_type;
1225 typedef typename ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::reference
1226 reference;
1228 typedef typename ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::pointer
1229 pointer;
1231 typedef typename ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::difference_type
1232 difference_type;
1234 // = Initialization method.
1235 /// Construct from map
1236 ACE_Hash_Map_Const_Iterator (const ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
1237 int tail = 0);
1239 /// Construct from base
1240 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);
1242 /// Assignment from base
1243 ACE_Hash_Map_Const_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
1244 operator= (const ACE_Hash_Map_Const_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
1248 * @class ACE_Hash_Map_Reverse_Iterator
1250 * @brief Wrapper for backward compatibility.
1252 template <class EXT_ID, class INT_ID, class ACE_LOCK>
1253 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>
1255 public:
1256 // = STL-style traits/typedefs
1257 typedef typename ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::container_type
1258 container_type;
1260 // = std::iterator_traits typedefs
1261 typedef typename ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::iterator_category
1262 iterator_category;
1264 typedef typename ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::value_type
1265 value_type;
1267 typedef typename ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::reference
1268 reference;
1270 typedef typename ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::pointer
1271 pointer;
1273 typedef typename ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK>::difference_type
1274 difference_type;
1276 // = Initialization method.
1277 ACE_Hash_Map_Reverse_Iterator (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
1278 bool head = false);
1280 /// Construct from base
1281 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);
1283 /// Assignment from base
1284 ACE_Hash_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
1285 operator= (const ACE_Hash_Map_Reverse_Iterator_Ex<EXT_ID, INT_ID, ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_LOCK> &base);
1288 ACE_END_VERSIONED_NAMESPACE_DECL
1290 #if defined (__ACE_INLINE__)
1291 # include "ace/Hash_Map_Manager_T.inl"
1292 #endif /* __ACE_INLINE__ */
1294 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
1295 #include "ace/Hash_Map_Manager_T.cpp"
1296 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
1298 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
1299 #pragma implementation ("Hash_Map_Manager_T.cpp")
1300 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
1302 #include /**/ "ace/post.h"
1303 #endif /* ACE_HASH_MAP_MANAGER_T_H */