3 //=============================================================================
5 * @file Hash_Multi_Map_Manager_T.h
7 * The code in Hash_Multi_Map_Manager_T.* was based on the code in
8 * Hash_Map_Manager_T.*.
10 * ACE_Hash_Multi_Map_Manager maps a key type to more than one value types.
11 * The template takes the key and value types as parameters. The bind and
12 * unbind operations can take a key and the value or the set of the values that
13 * is to be associated with that key. The find operation can take a key or a
14 * key and the value that is associated with the key.
16 * ACE_Hash_Multi_Map_Manager uses @c ACE_Unbounded_Set to store differet values
19 * @author Shanshan Jiang <shanshan.jiang@vanderbilt.edu>
21 //=============================================================================
23 #ifndef ACE_HASH_MULTI_MAP_MANAGER_T_H
24 #define ACE_HASH_MULTI_MAP_MANAGER_T_H
25 #include /**/ "ace/pre.h"
27 #include /**/ "ace/config-all.h"
29 #if !defined (ACE_LACKS_PRAGMA_ONCE)
31 #endif /* ACE_LACKS_PRAGMA_ONCE */
33 #include "ace/Default_Constants.h"
34 #include "ace/Functor_T.h"
35 #include "ace/Log_Category.h"
37 #include "ace/Unbounded_Set.h"
39 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
42 * @class ACE_Hash_Multi_Map_Entry
44 * @brief Define an entry in the hash table.
46 template <class EXT_ID
, class INT_ID
>
47 class ACE_Hash_Multi_Map_Entry
50 friend class ACE_Unbounded_Set
<INT_ID
>;
52 typedef ACE_Unbounded_Set
<INT_ID
> VALUE_SET
;
53 typedef ACE_Unbounded_Set_Iterator
<INT_ID
> VALUE_SET_ITERATOR
;
56 ACE_Hash_Multi_Map_Entry (const EXT_ID
&ext_id
,
57 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
58 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next
= 0,
59 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *prev
= 0);
62 ACE_Hash_Multi_Map_Entry (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next
,
63 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *prev
);
66 ~ACE_Hash_Multi_Map_Entry () = default;
72 ACE_Unbounded_Set
<INT_ID
>& item ();
75 /// Key used to look up an entry.
76 /// @todo Should be private
79 /// The contents of the entry itself.
80 /// @todo Should be private
81 ACE_Unbounded_Set
<INT_ID
> int_id_set_
;
83 /// Pointer to the next item in the bucket of overflow nodes.
84 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next_
;
86 /// Pointer to the prev item in the bucket of overflow nodes.
87 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *prev_
;
89 /// Dump the state of an object.
94 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
95 class ACE_Hash_Multi_Map_Iterator_Base
;
98 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
99 class ACE_Hash_Multi_Map_Const_Iterator_Base
;
102 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
103 class ACE_Hash_Multi_Map_Iterator
;
106 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
107 class ACE_Hash_Multi_Map_Const_Iterator
;
110 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
111 class ACE_Hash_Multi_Map_Reverse_Iterator
;
114 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
115 class ACE_Hash_Multi_Map_Bucket_Iterator
;
121 * @class ACE_Hash_Multi_Map_Manager
123 * @brief Define a multi-map abstraction that efficiently associates the keys
124 * with their different values.
126 * This implementation of a multi-map uses a hash table. Key hashing
127 * is achieved through the @c HASH_KEY object and key comparison is
128 * achieved through the @c COMPARE_KEYS object.
129 * This class uses an @c ACE_Allocator to allocate memory. The
130 * user can make this a persistent class by providing an
131 * @c ACE_Allocator with a persistable memory pool.
134 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
135 class ACE_Hash_Multi_Map_Manager
138 friend class ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
139 friend class ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
140 friend class ACE_Hash_Multi_Map_Const_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
141 friend class ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
142 friend class ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
143 friend class ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
149 typedef ACE_LOCK lock_type
;
150 typedef ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>
153 // = ACE-style iterator typedefs.
154 typedef ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
156 typedef ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
158 typedef ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
161 // = STL-style iterator typedefs.
162 typedef ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
164 typedef ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
166 typedef ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
170 * Initialize a @c Hash_Multi_Map_Manager with default size elements.
171 * @param table_alloc is a pointer to a memory allocator used for
172 * table_, so it should supply size*sizeof (
173 * ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>).
174 * @param entry_alloc is a pointer to an additional allocator for
175 * entries, so it should be able to allocate 'size' / chunks
176 * of sizeof (ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>) bytes
178 * If @a table_alloc is 0 it defaults to @c ACE_Allocator::instance().
179 * If @a entry_alloc is 0 then it defaults to the same allocator as
182 ACE_Hash_Multi_Map_Manager (ACE_Allocator
*table_alloc
= 0,
183 ACE_Allocator
*entry_alloc
= 0);
186 * Initialize a @c Hash_Multi_Map_Manager with @a size elements.
187 * @param size is the number of elements in a Hash_Multi_Map_Manager.
188 * @param table_alloc is a pointer to a memory allocator used for
189 * table_, so it should supply size*sizeof (
190 * ACE_Hash_Multi_Map_Entry<@c EXT_ID, <@c INT_ID>).
191 * @param entry_alloc is a pointer to an additional allocator for
192 * entries, so it should be able to allocate 'size' / chunks
193 * of sizeof (ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>) bytes
195 * If @a table_alloc is 0 it defaults to @c ACE_Allocator::instance().
196 * If @a entry_alloc is 0 then it defaults to the same allocator as
199 ACE_Hash_Multi_Map_Manager (size_t size
,
200 ACE_Allocator
*table_alloc
= 0,
201 ACE_Allocator
*entry_alloc
= 0);
204 * Initialize a @c Hash_Multi_Map_Manager with @a size elements.
205 * @param size is the number of elements in a Hash_Multi_Map_Manager.
206 * @param table_alloc is a pointer to a memory allocator used for
207 * table_, so it should supply size*sizeof
208 * (ACE_Hash_Multi_Map_Entry<@c EXT_ID, <@c INT_ID>).
209 * @param entry_alloc is a pointer to an additional allocator for
210 * entries, so it should be able to allocate 'size' / chunks
211 * of sizeof (ACE_Hash_Multi_Map_Entry<@c EXT_ID, <@c INT_ID>) bytes
213 * If @a table_alloc is 0 it defaults to @c ACE_Allocator::instance().
214 * If @a entry_alloc is 0 then it defaults to the same allocator as
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 a Hash_Multi_Map_Manager and release dynamically allocated
227 /// Removes all the entries in Hash_Multi_Map_Manager.
230 /// Cleanup the Hash_Multi_Map_Manager.
231 ~ACE_Hash_Multi_Map_Manager ();
234 * Associate @a ext_id with @a int_id. If @a ext_id and @a int_id is already
235 * in the map then the @c ACE_Hash_Multi_Map_Entry is not changed. Returns 0 if
236 * a new entry is bound successfully, returns 1 if an attempt is made
237 * to bind an existing entry, and returns -1 if failures occur.
239 int bind (const EXT_ID
&ext_id
,
240 const INT_ID
&int_id
);
243 * Same as a normal bind, except the map entry is also passed back
244 * to the caller. The entry in this case will either be the newly
245 * created entry, or the existing one.
247 int bind (const EXT_ID
&ext_id
,
248 const INT_ID
&int_id
,
249 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
252 * Associate @a ext_id with @a int_id_set. If @a ext_id is already in the
253 * map then the @c ACE_Hash_Multi_Map_Entry is not changed. Returns 0 if a
254 * new entry is bound successfully, returns 1 if an attempt is made
255 * to bind an existing entry, and returns -1 if failures occur.
257 int bind (const EXT_ID
&ext_id
,
258 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
261 * Same as a normal bind, except the map entry is also passed back
262 * to the caller. The entry in this case will either be the newly
263 * created entry, or the existing one.
265 int bind (const EXT_ID
&ext_id
,
266 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
267 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
270 * Associate @a ext_id with @a int_id_set if and only if @a ext_id is
271 * not in the map. If @a ext_id is already in the map then the @a int_id_set
272 * parameter is assigned the existing value in the map. Returns 0
273 * if a new entry is bound successfully, returns 1 if an attempt is
274 * made to bind an existing entry, and returns -1 if failures occur.
276 int trybind (const EXT_ID
&ext_id
,
277 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
280 * Same as a normal trybind, except the map entry is also passed
281 * back to the caller. The entry in this case will either be the
282 * newly created entry, or the existing one.
284 int trybind (const EXT_ID
&ext_id
,
285 ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
286 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
289 * Reassociate @a ext_id with @a int_id_set. If @a ext_id is not in
290 * the map then behaves just like bind. Returns 0 if a new entry is
291 * bound successfully, returns 1 if an existing entry was rebound,
292 * and returns -1 if failures occur.
294 int rebind (const EXT_ID
&ext_id
,
295 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
298 * Same as a normal rebind, except the map entry is also passed back
299 * to the caller. The entry in this case will either be the newly
300 * created entry, or the existing one.
302 int rebind (const EXT_ID
&ext_id
,
303 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
304 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
307 * Associate @a ext_id with @a int_id_set. If @a ext_id is not in the map
308 * then behaves just like bind. Otherwise, store the old value of
309 * @a int_id_set into the "out" parameter and rebind the new parameters.
310 * Returns 0 if a new entry is bound successfully, returns 1 if an
311 * existing entry was rebound, and returns -1 if failures occur.
313 int rebind (const EXT_ID
&ext_id
,
314 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
315 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
);
318 * Same as a normal rebind, except the map entry is also passed back
319 * to the caller. The entry in this case will either be the newly
320 * created entry, or the existing one.
322 int rebind (const EXT_ID
&ext_id
,
323 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
324 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
,
325 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
328 * Associate @a ext_id with @a int_id_set. If @a ext_id is not in the map
329 * then behaves just like bind. Otherwise, store the old values
330 * of @a ext_id and @a int_id_set into the "out" parameters and rebind the
331 * new parameters. This is very useful if you need to have an
332 * atomic way of updating @c ACE_Hash_Multi_Map_Entry objects and you also
333 * need full control over memory allocation. Returns 0 if a new entry
334 * is bound successfully, returns 1 if an existing entry was rebound,
335 * and returns -1 if failures occur.
337 int rebind (const EXT_ID
&ext_id
,
338 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
340 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
);
343 * Same as a normal rebind, except the map entry is also passed back
344 * to the caller. The entry in this case will either be the newly
345 * created entry, or the existing one.
347 int rebind (const EXT_ID
&ext_id
,
348 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
350 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
,
351 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
353 /// Locate @a ext_id and pass out parameter via @a int_id_set.
354 /// Return 0 if found, returns -1 if not found.
355 int find (const EXT_ID
&ext_id
,
356 ACE_Unbounded_Set
<INT_ID
> &int_id_set
) const;
358 /// Locate @a ext_id and @a int_id.
359 /// Return 0 if found, returns -1 if not found.
360 int find (const EXT_ID
&ext_id
,
361 const INT_ID
&int_id
) const;
363 /// Returns 0 if the @a ext_id is in the mapping, otherwise -1.
364 int find (const EXT_ID
&ext_id
) const;
366 /// Locate @a ext_id and pass out parameter via @a entry. If found,
367 /// return 0, returns -1 if not found.
368 int find (const EXT_ID
&ext_id
,
369 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
) const;
372 * Unbind (remove) the @a ext_id from the map. Don't return the
373 * int_id to the caller (this is useful for collections where the
374 * int_ids are *not* dynamically allocated...)
376 int unbind (const EXT_ID
&ext_id
);
378 /// Break any association of @a ext_id. Returns the value of @a int_id_set
379 /// in case the caller needs to deallocate memory. Return 0 if the
380 /// unbind was successfully, and returns -1 if failures occur.
381 int unbind (const EXT_ID
&ext_id
,
382 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
384 /// Break any association of @a ext_id and @a int_id. Return 0 if the
385 /// unbind was successfully, and returns -1 if failures occur.
386 int unbind (const EXT_ID
&ext_id
,
387 const INT_ID
&int_id
);
389 /// Remove @a entry from map. Return 0 if the unbind was successfully,
390 /// and returns -1 if failures occur.
391 int unbind (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *entry
);
393 /// Returns the current number of @c ACE_Hash_Multi_Map_Entry objects in the
395 size_t current_size () const;
397 /// Return the size of the array that's used to point to the
398 /// linked lists of @c ACE_Hash_Multi_Map_Entry objects in the hash table.
399 size_t total_size () const;
402 * Returns a reference to the underlying @c ACE_LOCK. This makes it
403 * possible to acquire the lock explicitly, which can be useful in
404 * some cases if you instantiate the @c ACE_Atomic_Op with an
405 * @c ACE_Recursive_Mutex or @c ACE_Process_Mutex, or if you need to
406 * guard the state of an iterator.
407 * @note The right name would be lock, but HP/C++ will choke on that!
411 /// Dump the state of an object.
414 // = STL styled iterator factory functions.
416 /// Return forward iterator.
417 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> begin ();
418 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> end ();
420 /// Return reverse iterator.
421 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> rbegin ();
422 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> rend ();
424 /// Declare the dynamic allocation hooks.
425 ACE_ALLOC_HOOK_DECLARE
;
428 // = The following methods do the actual work.
430 /// Returns 1 if @a id1 == @a id2, else 0. This is defined as a
431 /// separate method to facilitate template specialization.
432 int equal (const EXT_ID
&id1
, const EXT_ID
&id2
);
434 /// Compute the hash value of the @a ext_id. This is defined as a
435 /// separate method to facilitate template specialization.
436 u_long
hash (const EXT_ID
&ext_id
);
438 // = These methods assume locks are held by private methods.
440 /// Performs bind. Must be called with locks held.
441 int bind_i (const EXT_ID
&ext_id
,
442 const INT_ID
&int_id
);
444 /// Performs bind. Must be called with locks held.
445 int bind_i (const EXT_ID
&ext_id
,
446 const INT_ID
&int_id
,
447 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
449 /// Performs bind. Must be called with locks held.
450 int bind_i (const EXT_ID
&ext_id
,
451 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
453 /// Performs bind. Must be called with locks held.
454 int bind_i (const EXT_ID
&ext_id
,
455 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
456 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
458 /// Performs trybind. Must be called with locks held.
459 int trybind_i (const EXT_ID
&ext_id
,
460 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
462 /// Performs trybind. Must be called with locks held.
463 int trybind_i (const EXT_ID
&ext_id
,
464 ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
465 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
467 /// Performs rebind. Must be called with locks held.
468 int rebind_i (const EXT_ID
&ext_id
,
469 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
471 /// Performs rebind. Must be called with locks held.
472 int rebind_i (const EXT_ID
&ext_id
,
473 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
474 ACE_Hash_Multi_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 ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
479 ACE_Unbounded_Set
<INT_ID
> &old_int_id
);
481 /// Performs rebind. Must be called with locks held.
482 int rebind_i (const EXT_ID
&ext_id
,
483 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
484 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
,
485 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
487 /// Performs rebind. Must be called with locks held.
488 int rebind_i (const EXT_ID
&ext_id
,
489 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
491 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
);
493 /// Performs rebind. Must be called with locks held.
494 int rebind_i (const EXT_ID
&ext_id
,
495 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
497 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
,
498 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
500 /// Performs a find of @a int_id_set using @a ext_id as the key. Must be
501 /// called with locks held.
502 int find_i (const EXT_ID
&ext_id
,
503 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
505 /// Performs a find of @a ext_id and @a int_id. Must be
506 /// called with locks held.
507 int find_i (const EXT_ID
&ext_id
,
508 const INT_ID
&int_id
);
510 /// Performs a find using @a ext_id as the key. Must be called with
512 int find_i (const EXT_ID
&ext_id
);
514 /// Performs a find using @a ext_id as the key. Must be called with
516 int find_i (const EXT_ID
&ext_id
,
517 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
519 /// Performs unbind. Must be called with locks held.
520 int unbind_i (const EXT_ID
&ext_id
,
521 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
523 /// Performs unbind. Must be called with locks held.
524 int unbind_i (const EXT_ID
&ext_id
,
525 const INT_ID
&int_id
);
527 /// Performs unbind. Must be called with locks held.
528 int unbind_i (const EXT_ID
&ext_id
);
530 /// Performs unbind. Must be called with locks held.
531 int unbind_i (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *entry
);
534 * Resize the map. Must be called with locks held.
535 * @note This method should never be called more than once or else all the
536 * hashing will get screwed up as the size will change.
538 int create_buckets (size_t size
);
540 /// Close down a Map_Manager. Must be called with
544 /// Removes all the entries in Map_Manager. Must be called with
548 /// Pointer to a memory allocator used for table_, so it should
549 /// supply size*sizeof (@c ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>),
550 ACE_Allocator
*table_allocator_
;
552 /// Addidtional allocator for entries, so it should be able to
553 /// allocate 'size' / chunks of sizeof
554 /// (@c ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>) bytes each.
555 ACE_Allocator
*entry_allocator_
;
557 /// Synchronization variable for the MT_SAFE
558 /// @c ACE_Hash_Multi_Map_Manager.
561 /// Function object used for hashing keys.
564 /// Function object used for comparing keys.
565 COMPARE_KEYS compare_keys_
;
568 /// Returns the @c ACE_Hash_Multi_Map_Entry object that corresponds to
570 int shared_find (const EXT_ID
&ext_id
,
571 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
,
574 /// Accessor of the underlying table
575 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *table ();
577 /// Accessor of the current size attribute
578 size_t cur_size () const;
582 * Array of the pointers to @c ACE_Hash_Multi_Map_Entry objects, each of
583 * which points to an @c ACE_Hash_Multi_Map_Entry that serves as the
584 * beginning of a linked list of @c EXT_ID that hash to that bucket.
586 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *table_
;
588 /// Total size of the hash table.
591 /// Current number of entries in the table
592 /// @note That this can be larger than total_size_ due to the
593 /// bucket chaining).
596 // = Disallow these operations.
597 void operator= (const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) = delete;
598 ACE_Hash_Multi_Map_Manager (const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) = delete;
602 * @class ACE_Hash_Multi_Map_Iterator_Base
604 * @brief Base iterator for the @c ACE_Hash_Multi_Map_Manager
606 * This class factors out common code from its templatized
609 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
610 class ACE_Hash_Multi_Map_Iterator_Base
613 /// Constructor. If @a head != 0, the iterator constructed is positioned
614 /// at the head of the map, it is positioned at the end otherwise.
615 ACE_Hash_Multi_Map_Iterator_Base (ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
618 // = ITERATION methods.
620 /// Pass back the @a next_entry that hasn't been seen in the Set.
621 /// Returns 0 when all items have been seen, else 1.
622 int next (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&next_entry
) const;
624 /// Returns 1 when all items have been seen, else 0.
627 /// Returns a reference to the interal element this object is pointing to.
628 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>& operator* () const;
630 /// Returns a pointer to the interal element this object is pointing to.
631 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>* operator-> () const;
633 /// Returns reference the @c Hash_Multi_Map_Manager that is being iterated
635 ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>& map ();
637 /// Check if two iterators point to the same position
638 bool operator== (const ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
639 bool operator!= (const ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
641 /// Declare the dynamic allocation hooks.
642 ACE_ALLOC_HOOK_DECLARE
;
645 /// Move forward by one element in the set. Returns 0 when there's
646 /// no more item in the set after the current items, else 1.
649 /// Move backward by one element in the set. Returns 0 when there's
650 /// no more item in the set before the current item, else 1.
653 /// Dump the state of an object.
654 void dump_i () const;
656 /// Map we are iterating over.
657 ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> *map_man_
;
659 /// Keeps track of how far we've advanced in the table.
662 /// Keeps track of how far we've advanced in a linked list in each
664 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next_
;
668 * @class ACE_Hash_Multi_Map_Const_Iterator_Base
670 * @brief Base const iterator for the @c ACE_Hash_Multi_Map_Manager
672 * This class factors out common code from its templatized
675 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
676 class ACE_Hash_Multi_Map_Const_Iterator_Base
679 /// Constructor. If @a head != 0, the iterator constructed is positioned
680 /// at the head of the map, it is positioned at the end otherwise.
681 ACE_Hash_Multi_Map_Const_Iterator_Base (const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
684 // = ITERATION methods.
686 /// Pass back the @a next_entry that hasn't been seen in the Set.
687 /// Returns 0 when all items have been seen, else 1.
688 int next (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&next_entry
) const;
690 /// Returns 1 when all items have been seen, else 0.
693 /// Returns a reference to the interal element this object is pointing to.
694 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>& operator* () const;
696 /// Returns a pointer to the interal element this object is pointing to.
697 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>* operator-> () const;
699 /// Returns reference the @c Hash_Multi_Map_Manager that is being iterated
701 const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>& map ();
703 /// Check if two iterators point to the same position
704 bool operator== (const ACE_Hash_Multi_Map_Const_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
705 bool operator!= (const ACE_Hash_Multi_Map_Const_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
707 /// Declare the dynamic allocation hooks.
708 ACE_ALLOC_HOOK_DECLARE
;
711 /// Move forward by one element in the set. Returns 0 when there's
712 /// no more item in the set after the current items, else 1.
715 /// Move backward by one element in the set. Returns 0 when there's
716 /// no more item in the set before the current item, else 1.
719 /// Dump the state of an object.
720 void dump_i () const;
722 /// Map we are iterating over.
723 const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> *map_man_
;
725 /// Keeps track of how far we've advanced in the table.
728 /// Keeps track of how far we've advanced in a linked list in each
730 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next_
;
734 * @class ACE_Hash_Multi_Map_Iterator
736 * @brief Forward iterator for the @c ACE_Hash_Multi_Map_Manager.
738 * This class does not perform any internal locking of the
739 * @c ACE_Hash_Multi_Map_Manager it is iterating upon since locking is
740 * inherently inefficient and/or error-prone within an STL-style
741 * iterator. If you require locking, you can explicitly use an
742 * @c ACE_GUARD or @c ACE_READ_GUARD on the @c ACE_Hash_Multi_Map_Manager's
743 * internal lock, which is accessible via its @c mutex method.
745 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
746 class ACE_Hash_Multi_Map_Iterator
: public ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
749 ACE_Hash_Multi_Map_Iterator (ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
752 // = Iteration methods.
753 /// Move forward by one element in the set. Returns 0 when all the
754 /// items in the set have been seen, else 1.
757 /// Dump the state of an object.
760 // = STL styled iteration, compare, and reference functions.
763 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator++ ();
766 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator++ (int);
769 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator-- ();
772 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator-- (int);
774 /// Declare the dynamic allocation hooks.
775 ACE_ALLOC_HOOK_DECLARE
;
779 * @class ACE_Hash_Multi_Map_Const_Iterator
781 * @brief Const forward iterator for the @c ACE_Hash_Multi_Map_Manager.
783 * This class does not perform any internal locking of the
784 * @c ACE_Hash_Multi_Map_Manager it is iterating upon since locking is
785 * inherently inefficient and/or error-prone within an STL-style
786 * iterator. If you require locking, you can explicitly use an
787 * @c ACE_GUARD or @c ACE_READ_GUARD on the @c ACE_Hash_Multi_Map_Manager's
788 * internal lock, which is accessible via its @c mutex() method.
790 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
791 class ACE_Hash_Multi_Map_Const_Iterator
: public ACE_Hash_Multi_Map_Const_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
794 ACE_Hash_Multi_Map_Const_Iterator (const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
797 // = Iteration methods.
798 /// Move forward by one element in the set. Returns 0 when all the
799 /// items in the set have been seen, else 1.
802 /// Dump the state of an object.
805 // = STL styled iteration, compare, and reference functions.
808 ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator++ ();
811 ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator++ (int);
814 ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator-- ();
817 ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator-- (int);
819 /// Declare the dynamic allocation hooks.
820 ACE_ALLOC_HOOK_DECLARE
;
824 * @class ACE_Hash_Multi_Map_Bucket_Iterator
826 * @brief Forward iterator for the @c ACE_Hash_Multi_Map_Manager which
827 * only traverses a particular bucket. The particular bucket is
828 * specified by the @c EXT_ID parameter specified in the constructor.
830 * This class does not perform any internal locking of the
831 * @c ACE_Hash_Multi_Map_Manager it is iterating upon since locking is
832 * inherently inefficient and/or error-prone within an STL-style
833 * iterator. If you require locking, you can explicitly use an
834 * @c ACE_GUARD or @c ACE_READ_GUARD on the @c ACE_Hash_Multi_Map_Manager's
835 * internal lock, which is accessible via its @c mutex method.
837 * Note that a creation method for this new iterator cannot be added
838 * to the hash map, since this would require adding explicit template
839 * instantiations for bucket iterators on platforms with broken
842 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
843 class ACE_Hash_Multi_Map_Bucket_Iterator
846 ACE_Hash_Multi_Map_Bucket_Iterator (ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
847 const EXT_ID
&ext_id
,
850 // = STL styled iteration, compare, and reference functions.
853 ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator++ ();
856 ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator++ (int);
859 ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator-- ();
862 ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator-- (int);
864 /// Returns a reference to the interal element this object is pointing to.
865 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>& operator* () const;
867 /// Returns a pointer to the interal element this object is pointing to.
868 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>* operator-> () const;
870 /// Returns reference the Hash_Multi_Map_Manager that is being iterated
872 ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>& map ();
874 /// Check if two iterators point to the same position
875 bool operator== (const ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
876 bool operator!= (const ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
879 /// Move forward by one element in the set. Returns 0 when there's
880 /// no more item in the set after the current items, else 1.
883 /// Move backward by one element in the set. Returns 0 when there's
884 /// no more item in the set before the current item, else 1.
887 /// Map we are iterating over.
888 ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> *map_man_
;
890 /// Keeps track of how far we've advanced in the table.
893 /// Keeps track of how far we've advanced in a linked list in each
895 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next_
;
899 * @class ACE_Hash_Multi_Map_Reverse_Iterator
901 * @brief Reverse iterator for the @c ACE_Hash_Multi_Map_Manager.
903 * This class does not perform any internal locking of the
904 * @c ACE_Hash_Multi_Map_Manager it is iterating upon since locking is
905 * inherently inefficient and/or error-prone within an STL-style
906 * iterator. If you require locking, you can explicitly use an
907 * @c ACE_GUARD or @c ACE_READ_GUARD on the @c ACE_Hash_Multi_Map_Manager's
908 * internal lock, which is accessible via its @c mutex method.
910 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
911 class ACE_Hash_Multi_Map_Reverse_Iterator
: public ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
914 ACE_Hash_Multi_Map_Reverse_Iterator (ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
917 // = Iteration methods.
918 /// Move forward by one element in the set. Returns 0 when all the
919 /// items in the set have been seen, else 1.
922 /// Dump the state of an object.
925 // = STL styled iteration, compare, and reference functions.
928 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator++ ();
931 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator++ (int);
934 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator-- ();
937 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator-- (int);
939 /// Declare the dynamic allocation hooks.
940 ACE_ALLOC_HOOK_DECLARE
;
943 ACE_END_VERSIONED_NAMESPACE_DECL
945 #if defined (__ACE_INLINE__)
946 # include "ace/Hash_Multi_Map_Manager_T.inl"
947 #endif /* __ACE_INLINE__ */
949 #include "ace/Hash_Multi_Map_Manager_T.cpp"
951 #include /**/ "ace/post.h"
952 #endif /* ACE_HASH_MULTI_MAP_MANAGER_T_H */