3 //=============================================================================
5 * @file Hash_Multi_Map_Manager_T.h
7 * $Id: Hash_Multi_Map_Manager_T.h 80826 2008-03-04 14:51:23Z wotte $
9 * The code in Hash_Multi_Map_Manager_T.* was based on the code in
10 * Hash_Map_Manager_T.*.
12 * ACE_Hash_Multi_Map_Manager maps a key type to more than one value types.
13 * The template takes the key and value types as parameters. The bind and
14 * unbind operations can take a key and the value or the set of the values that
15 * is to be associated with that key. The find operation can take a key or a
16 * key and the value that is associated with the key.
18 * ACE_Hash_Multi_Map_Manager uses @c ACE_Unbounded_Set to store differet values
21 * @author Shanshan Jiang <shanshan.jiang@vanderbilt.edu>
23 //=============================================================================
25 #ifndef ACE_HASH_MULTI_MAP_MANAGER_T_H
26 #define ACE_HASH_MULTI_MAP_MANAGER_T_H
27 #include /**/ "ace/pre.h"
29 #include /**/ "ace/config-all.h"
31 #if !defined (ACE_LACKS_PRAGMA_ONCE)
33 #endif /* ACE_LACKS_PRAGMA_ONCE */
35 #include "ace/Default_Constants.h"
36 #include "ace/Functor_T.h"
37 #include "ace/Log_Msg.h"
39 #include "ace/Unbounded_Set.h"
41 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
44 * @class ACE_Hash_Multi_Map_Entry
46 * @brief Define an entry in the hash table.
48 template <class EXT_ID
, class INT_ID
>
49 class ACE_Hash_Multi_Map_Entry
52 friend class ACE_Unbounded_Set
<INT_ID
>;
54 typedef ACE_Unbounded_Set
<INT_ID
> VALUE_SET
;
55 typedef ACE_Unbounded_Set_Iterator
<INT_ID
> VALUE_SET_ITERATOR
;
57 // = Initialization and termination methods.
59 ACE_Hash_Multi_Map_Entry (const EXT_ID
&ext_id
,
60 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
61 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next
= 0,
62 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *prev
= 0);
65 ACE_Hash_Multi_Map_Entry (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next
,
66 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *prev
);
68 # if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
70 ~ACE_Hash_Multi_Map_Entry (void);
71 #endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */
77 ACE_Unbounded_Set
<INT_ID
>& item (void);
79 /// Key used to look up an entry.
80 /// @deprecated Use key()
83 /// The contents of the entry itself.
84 /// @deprecated Use item()
85 ACE_Unbounded_Set
<INT_ID
> int_id_set_
;
87 /// Pointer to the next item in the bucket of overflow nodes.
88 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next_
;
90 /// Pointer to the prev item in the bucket of overflow nodes.
91 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *prev_
;
93 /// Dump the state of an object.
94 void dump (void) const;
98 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
99 class ACE_Hash_Multi_Map_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_Const_Iterator_Base
;
106 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
107 class ACE_Hash_Multi_Map_Iterator
;
110 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
111 class ACE_Hash_Multi_Map_Const_Iterator
;
114 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
115 class ACE_Hash_Multi_Map_Reverse_Iterator
;
118 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
119 class ACE_Hash_Multi_Map_Bucket_Iterator
;
125 * @class ACE_Hash_Multi_Map_Manager
127 * @brief Define a multi-map abstraction that efficiently associates the keys
128 * with their different values.
130 * This implementation of a multi-map uses a hash table. Key hashing
131 * is achieved through the @c HASH_KEY object and key comparison is
132 * achieved through the @c COMPARE_KEYS object.
133 * This class uses an @c ACE_Allocator to allocate memory. The
134 * user can make this a persistent class by providing an
135 * @c ACE_Allocator with a persistable memory pool.
138 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
139 class ACE_Hash_Multi_Map_Manager
142 friend class ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
143 friend class ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
144 friend class ACE_Hash_Multi_Map_Const_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
145 friend class ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
146 friend class ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
147 friend class ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>;
153 typedef ACE_LOCK lock_type
;
154 typedef ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>
157 // = ACE-style iterator typedefs.
158 typedef ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
160 typedef ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
162 typedef ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
165 // = STL-style iterator typedefs.
166 typedef ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
168 typedef ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
170 typedef ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
173 // = Initialization and termination methods.
176 * Initialize a @c Hash_Multi_Map_Manager with default size elements.
177 * @param table_alloc is a pointer to a memory allocator used for
178 * table_, so it should supply size*sizeof (
179 * ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>).
180 * @param entry_alloc is a pointer to an additional allocator for
181 * entries, so it should be able to allocate 'size' / chunks
182 * of sizeof (ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>) bytes
184 * If @a table_alloc is 0 it defaults to @c ACE_Allocator::instance().
185 * If @a entry_alloc is 0 then it defaults to the same allocator as
188 ACE_Hash_Multi_Map_Manager (ACE_Allocator
*table_alloc
= 0,
189 ACE_Allocator
*entry_alloc
= 0);
192 * Initialize a @c Hash_Multi_Map_Manager with @a size elements.
193 * @param size is the number of elements in a Hash_Multi_Map_Manager.
194 * @param table_alloc is a pointer to a memory allocator used for
195 * table_, so it should supply size*sizeof (
196 * ACE_Hash_Multi_Map_Entry<@c EXT_ID, <@c INT_ID>).
197 * @param entry_alloc is a pointer to an additional allocator for
198 * entries, so it should be able to allocate 'size' / chunks
199 * of sizeof (ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>) bytes
201 * If @a table_alloc is 0 it defaults to @c ACE_Allocator::instance().
202 * If @a entry_alloc is 0 then it defaults to the same allocator as
205 ACE_Hash_Multi_Map_Manager (size_t size
,
206 ACE_Allocator
*table_alloc
= 0,
207 ACE_Allocator
*entry_alloc
= 0);
210 * Initialize a @c Hash_Multi_Map_Manager with @a size elements.
211 * @param size is the number of elements in a Hash_Multi_Map_Manager.
212 * @param table_alloc is a pointer to a memory allocator used for
213 * table_, so it should supply size*sizeof
214 * (ACE_Hash_Multi_Map_Entry<@c EXT_ID, <@c INT_ID>).
215 * @param entry_alloc is a pointer to an additional allocator for
216 * entries, so it should be able to allocate 'size' / chunks
217 * of sizeof (ACE_Hash_Multi_Map_Entry<@c EXT_ID, <@c INT_ID>) bytes
219 * If @a table_alloc is 0 it defaults to @c ACE_Allocator::instance().
220 * If @a entry_alloc is 0 then it defaults to the same allocator as
222 * @return -1 on failure, 0 on success
225 int open (size_t size
= ACE_DEFAULT_MAP_SIZE
,
226 ACE_Allocator
*table_alloc
= 0,
227 ACE_Allocator
*entry_alloc
= 0);
229 /// Close down a Hash_Multi_Map_Manager and release dynamically allocated
233 /// Removes all the entries in Hash_Multi_Map_Manager.
234 int unbind_all (void);
236 /// Cleanup the Hash_Multi_Map_Manager.
237 ~ACE_Hash_Multi_Map_Manager (void);
240 * Associate @a ext_id with @a int_id. If @a ext_id and @a int_id is already
241 * in the map then the @c ACE_Hash_Multi_Map_Entry is not changed. Returns 0 if
242 * a new entry is bound successfully, returns 1 if an attempt is made
243 * to bind an existing entry, and returns -1 if failures occur.
245 int bind (const EXT_ID
&ext_id
,
246 const INT_ID
&int_id
);
249 * Same as a normal bind, except the map entry is also passed back
250 * to the caller. The entry in this case will either be the newly
251 * created entry, or the existing one.
253 int bind (const EXT_ID
&ext_id
,
254 const INT_ID
&int_id
,
255 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
258 * Associate @a ext_id with @a int_id_set. If @a ext_id is already in the
259 * map then the @c ACE_Hash_Multi_Map_Entry is not changed. Returns 0 if a
260 * new entry is bound successfully, returns 1 if an attempt is made
261 * to bind an existing entry, and returns -1 if failures occur.
263 int bind (const EXT_ID
&ext_id
,
264 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
267 * Same as a normal bind, except the map entry is also passed back
268 * to the caller. The entry in this case will either be the newly
269 * created entry, or the existing one.
271 int bind (const EXT_ID
&ext_id
,
272 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
273 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
276 * Associate @a ext_id with @a int_id_set if and only if @a ext_id is
277 * not in the map. If @a ext_id is already in the map then the @a int_id_set
278 * parameter is assigned the existing value in the map. Returns 0
279 * if a new entry is bound successfully, returns 1 if an attempt is
280 * made to bind an existing entry, and returns -1 if failures occur.
282 int trybind (const EXT_ID
&ext_id
,
283 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
286 * Same as a normal trybind, except the map entry is also passed
287 * back to the caller. The entry in this case will either be the
288 * newly created entry, or the existing one.
290 int trybind (const EXT_ID
&ext_id
,
291 ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
292 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
295 * Reassociate @a ext_id with @a int_id_set. If @a ext_id is not in
296 * the map then behaves just like bind. Returns 0 if a new entry is
297 * bound successfully, returns 1 if an existing entry was rebound,
298 * and returns -1 if failures occur.
300 int rebind (const EXT_ID
&ext_id
,
301 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
304 * Same as a normal rebind, except the map entry is also passed back
305 * to the caller. The entry in this case will either be the newly
306 * created entry, or the existing one.
308 int rebind (const EXT_ID
&ext_id
,
309 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
310 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
313 * Associate @a ext_id with @a int_id_set. If @a ext_id is not in the map
314 * then behaves just like bind. Otherwise, store the old value of
315 * @a int_id_set into the "out" parameter and rebind the new parameters.
316 * Returns 0 if a new entry is bound successfully, returns 1 if an
317 * existing entry was rebound, and returns -1 if failures occur.
319 int rebind (const EXT_ID
&ext_id
,
320 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
321 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
);
324 * Same as a normal rebind, except the map entry is also passed back
325 * to the caller. The entry in this case will either be the newly
326 * created entry, or the existing one.
328 int rebind (const EXT_ID
&ext_id
,
329 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
330 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
,
331 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
334 * Associate @a ext_id with @a int_id_set. If @a ext_id is not in the map
335 * then behaves just like bind. Otherwise, store the old values
336 * of @a ext_id and @a int_id_set into the "out" parameters and rebind the
337 * new parameters. This is very useful if you need to have an
338 * atomic way of updating @c ACE_Hash_Multi_Map_Entry objects and you also
339 * need full control over memory allocation. Returns 0 if a new entry
340 * is bound successfully, returns 1 if an existing entry was rebound,
341 * and returns -1 if failures occur.
343 int rebind (const EXT_ID
&ext_id
,
344 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
346 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
);
349 * Same as a normal rebind, except the map entry is also passed back
350 * to the caller. The entry in this case will either be the newly
351 * created entry, or the existing one.
353 int rebind (const EXT_ID
&ext_id
,
354 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
356 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
,
357 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
359 /// Locate @a ext_id and pass out parameter via @a int_id_set.
360 /// Return 0 if found, returns -1 if not found.
361 int find (const EXT_ID
&ext_id
,
362 ACE_Unbounded_Set
<INT_ID
> &int_id_set
) const;
364 /// Locate @a ext_id and @a int_id.
365 /// Return 0 if found, returns -1 if not found.
366 int find (const EXT_ID
&ext_id
,
367 const INT_ID
&int_id
) const;
369 /// Returns 0 if the @a ext_id is in the mapping, otherwise -1.
370 int find (const EXT_ID
&ext_id
) const;
372 /// Locate @a ext_id and pass out parameter via @a entry. If found,
373 /// return 0, returns -1 if not found.
374 int find (const EXT_ID
&ext_id
,
375 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
) const;
378 * Unbind (remove) the @a ext_id from the map. Don't return the
379 * int_id to the caller (this is useful for collections where the
380 * int_ids are *not* dynamically allocated...)
382 int unbind (const EXT_ID
&ext_id
);
384 /// Break any association of @a ext_id. Returns the value of @a int_id_set
385 /// in case the caller needs to deallocate memory. Return 0 if the
386 /// unbind was successfully, and returns -1 if failures occur.
387 int unbind (const EXT_ID
&ext_id
,
388 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
390 /// Break any association of @a ext_id and @a int_id. Return 0 if the
391 /// unbind was successfully, and returns -1 if failures occur.
392 int unbind (const EXT_ID
&ext_id
,
393 const INT_ID
&int_id
);
395 /// Remove @a entry from map. Return 0 if the unbind was successfully,
396 /// and returns -1 if failures occur.
397 int unbind (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *entry
);
399 /// Returns the current number of @c ACE_Hash_Multi_Map_Entry objects in the
401 size_t current_size (void) const;
403 /// Return the size of the array that's used to point to the
404 /// linked lists of @c ACE_Hash_Multi_Map_Entry objects in the hash table.
405 size_t total_size (void) const;
408 * Returns a reference to the underlying @c ACE_LOCK. This makes it
409 * possible to acquire the lock explicitly, which can be useful in
410 * some cases if you instantiate the @c ACE_Atomic_Op with an
411 * @c ACE_Recursive_Mutex or @c ACE_Process_Mutex, or if you need to
412 * guard the state of an iterator.
413 * @note The right name would be lock, but HP/C++ will choke on that!
415 ACE_LOCK
&mutex (void);
417 /// Dump the state of an object.
418 void dump (void) const;
420 // = STL styled iterator factory functions.
422 /// Return forward iterator.
423 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> begin (void);
424 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> end (void);
426 /// Return reverse iterator.
427 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> rbegin (void);
428 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> rend (void);
431 // = The following methods do the actual work.
433 /// Returns 1 if @a id1 == @a id2, else 0. This is defined as a
434 /// separate method to facilitate template specialization.
435 int equal (const EXT_ID
&id1
, const EXT_ID
&id2
);
437 /// Compute the hash value of the @a ext_id. This is defined as a
438 /// separate method to facilitate template specialization.
439 u_long
hash (const EXT_ID
&ext_id
);
441 // = These methods assume locks are held by private methods.
443 /// Performs bind. Must be called with locks held.
444 int bind_i (const EXT_ID
&ext_id
,
445 const INT_ID
&int_id
);
447 /// Performs bind. Must be called with locks held.
448 int bind_i (const EXT_ID
&ext_id
,
449 const INT_ID
&int_id
,
450 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
452 /// Performs bind. Must be called with locks held.
453 int bind_i (const EXT_ID
&ext_id
,
454 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
456 /// Performs bind. Must be called with locks held.
457 int bind_i (const EXT_ID
&ext_id
,
458 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
459 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
461 /// Performs trybind. Must be called with locks held.
462 int trybind_i (const EXT_ID
&ext_id
,
463 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
465 /// Performs trybind. Must be called with locks held.
466 int trybind_i (const EXT_ID
&ext_id
,
467 ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
468 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
470 /// Performs rebind. Must be called with locks held.
471 int rebind_i (const EXT_ID
&ext_id
,
472 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
474 /// Performs rebind. Must be called with locks held.
475 int rebind_i (const EXT_ID
&ext_id
,
476 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
477 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
479 /// Performs rebind. Must be called with locks held.
480 int rebind_i (const EXT_ID
&ext_id
,
481 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
482 ACE_Unbounded_Set
<INT_ID
> &old_int_id
);
484 /// Performs rebind. Must be called with locks held.
485 int rebind_i (const EXT_ID
&ext_id
,
486 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
487 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
,
488 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
490 /// Performs rebind. Must be called with locks held.
491 int rebind_i (const EXT_ID
&ext_id
,
492 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
494 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
);
496 /// Performs rebind. Must be called with locks held.
497 int rebind_i (const EXT_ID
&ext_id
,
498 const ACE_Unbounded_Set
<INT_ID
> &int_id_set
,
500 ACE_Unbounded_Set
<INT_ID
> &old_int_id_set
,
501 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
503 /// Performs a find of @a int_id_set using @a ext_id as the key. Must be
504 /// called with locks held.
505 int find_i (const EXT_ID
&ext_id
,
506 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
508 /// Performs a find of @a ext_id and @a int_id. Must be
509 /// called with locks held.
510 int find_i (const EXT_ID
&ext_id
,
511 const INT_ID
&int_id
);
513 /// Performs a find using @a ext_id as the key. Must be called with
515 int find_i (const EXT_ID
&ext_id
);
517 /// Performs a find using @a ext_id as the key. Must be called with
519 int find_i (const EXT_ID
&ext_id
,
520 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
);
522 /// Performs unbind. Must be called with locks held.
523 int unbind_i (const EXT_ID
&ext_id
,
524 ACE_Unbounded_Set
<INT_ID
> &int_id_set
);
526 /// Performs unbind. Must be called with locks held.
527 int unbind_i (const EXT_ID
&ext_id
,
528 const INT_ID
&int_id
);
530 /// Performs unbind. Must be called with locks held.
531 int unbind_i (const EXT_ID
&ext_id
);
533 /// Performs unbind. Must be called with locks held.
534 int unbind_i (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *entry
);
537 * Resize the map. Must be called with locks held.
538 * @note This method should never be called more than once or else all the
539 * hashing will get screwed up as the size will change.
541 int create_buckets (size_t size
);
543 /// Close down a Map_Manager. Must be called with
547 /// Removes all the entries in Map_Manager. Must be called with
549 int unbind_all_i (void);
551 /// Pointer to a memory allocator used for table_, so it should
552 /// supply size*sizeof (@c ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>),
553 ACE_Allocator
*table_allocator_
;
555 /// Addidtional allocator for entries, so it should be able to
556 /// allocate 'size' / chunks of sizeof
557 /// (@c ACE_Hash_Multi_Map_Entry<@c EXT_ID, @c INT_ID>) bytes each.
558 ACE_Allocator
*entry_allocator_
;
560 /// Synchronization variable for the MT_SAFE
561 /// @c ACE_Hash_Multi_Map_Manager.
564 /// Function object used for hashing keys.
567 /// Function object used for comparing keys.
568 COMPARE_KEYS compare_keys_
;
571 /// Returns the @c ACE_Hash_Multi_Map_Entry object that corresponds to
573 int shared_find (const EXT_ID
&ext_id
,
574 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&entry
,
577 /// Accessor of the underlying table
578 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *table (void);
580 /// Accessor of the current size attribute
581 size_t cur_size (void) const;
585 * Array of the pointers to @c ACE_Hash_Multi_Map_Entry objects, each of
586 * which points to an @c ACE_Hash_Multi_Map_Entry that serves as the
587 * beginning of a linked list of @c EXT_ID that hash to that bucket.
589 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *table_
;
591 /// Total size of the hash table.
594 /// Current number of entries in the table
595 /// @note That this can be larger than total_size_ due to the
596 /// bucket chaining).
599 // = Disallow these operations.
600 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &))
601 ACE_UNIMPLEMENTED_FUNC (ACE_Hash_Multi_Map_Manager (const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &))
605 * @class ACE_Hash_Multi_Map_Iterator_Base
607 * @brief Base iterator for the @c ACE_Hash_Multi_Map_Manager
609 * This class factors out common code from its templatized
612 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
613 class ACE_Hash_Multi_Map_Iterator_Base
616 // = Initialization method.
617 /// Contructor. If @a head != 0, the iterator constructed is positioned
618 /// at the head of the map, it is positioned at the end otherwise.
619 ACE_Hash_Multi_Map_Iterator_Base (ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
622 // = ITERATION methods.
624 /// Pass back the @a next_entry that hasn't been seen in the Set.
625 /// Returns 0 when all items have been seen, else 1.
626 int next (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&next_entry
) const;
628 /// Returns 1 when all items have been seen, else 0.
629 int done (void) const;
631 /// Returns a reference to the interal element this object is pointing to.
632 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>& operator* (void) const;
634 /// Returns a pointer to the interal element this object is pointing to.
635 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>* operator-> (void) const;
637 /// Returns reference the @c Hash_Multi_Map_Manager that is being iterated
639 ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>& map (void);
641 /// Check if two iterators point to the same position
642 bool operator== (const ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
643 bool operator!= (const ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
645 /// Declare the dynamic allocation hooks.
646 ACE_ALLOC_HOOK_DECLARE
;
649 /// Move forward by one element in the set. Returns 0 when there's
650 /// no more item in the set after the current items, else 1.
651 int forward_i (void);
653 /// Move backward by one element in the set. Returns 0 when there's
654 /// no more item in the set before the current item, else 1.
655 int reverse_i (void);
657 /// Dump the state of an object.
658 void dump_i (void) const;
660 /// Map we are iterating over.
661 ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> *map_man_
;
663 /// Keeps track of how far we've advanced in the table.
666 /// Keeps track of how far we've advanced in a linked list in each
668 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next_
;
672 * @class ACE_Hash_Multi_Map_Const_Iterator_Base
674 * @brief Base const iterator for the @c ACE_Hash_Multi_Map_Manager
676 * This class factors out common code from its templatized
679 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
680 class ACE_Hash_Multi_Map_Const_Iterator_Base
683 // = Initialization method.
684 /// Contructor. If @a head != 0, the iterator constructed is positioned
685 /// at the head of the map, it is positioned at the end otherwise.
686 ACE_Hash_Multi_Map_Const_Iterator_Base (const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
689 // = ITERATION methods.
691 /// Pass back the @a next_entry that hasn't been seen in the Set.
692 /// Returns 0 when all items have been seen, else 1.
693 int next (ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *&next_entry
) const;
695 /// Returns 1 when all items have been seen, else 0.
696 int done (void) const;
698 /// Returns a reference to the interal element this object is pointing to.
699 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>& operator* (void) const;
701 /// Returns a pointer to the interal element this object is pointing to.
702 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>* operator-> (void) const;
704 /// Returns reference the @c Hash_Multi_Map_Manager that is being iterated
706 const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>& map (void);
708 /// Check if two iterators point to the same position
709 bool operator== (const ACE_Hash_Multi_Map_Const_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
710 bool operator!= (const ACE_Hash_Multi_Map_Const_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
712 /// Declare the dynamic allocation hooks.
713 ACE_ALLOC_HOOK_DECLARE
;
716 /// Move forward by one element in the set. Returns 0 when there's
717 /// no more item in the set after the current items, else 1.
718 int forward_i (void);
720 /// Move backward by one element in the set. Returns 0 when there's
721 /// no more item in the set before the current item, else 1.
722 int reverse_i (void);
724 /// Dump the state of an object.
725 void dump_i (void) const;
727 /// Map we are iterating over.
728 const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> *map_man_
;
730 /// Keeps track of how far we've advanced in the table.
733 /// Keeps track of how far we've advanced in a linked list in each
735 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next_
;
739 * @class ACE_Hash_Multi_Map_Iterator
741 * @brief Forward iterator for the @c ACE_Hash_Multi_Map_Manager.
743 * This class does not perform any internal locking of the
744 * @c ACE_Hash_Multi_Map_Manager it is iterating upon since locking is
745 * inherently inefficient and/or error-prone within an STL-style
746 * iterator. If you require locking, you can explicitly use an
747 * @c ACE_Guard or @c ACE_Read_Guard on the @c ACE_Hash_Multi_Map_Manager's
748 * internal lock, which is accessible via its @c mutex method.
750 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
751 class ACE_Hash_Multi_Map_Iterator
: public ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
754 // = Initialization method.
755 ACE_Hash_Multi_Map_Iterator (ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
758 // = Iteration methods.
759 /// Move forward by one element in the set. Returns 0 when all the
760 /// items in the set have been seen, else 1.
763 /// Dump the state of an object.
764 void dump (void) const;
766 // = STL styled iteration, compare, and reference functions.
769 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator++ (void);
772 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator++ (int);
775 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator-- (void);
778 ACE_Hash_Multi_Map_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator-- (int);
780 /// Declare the dynamic allocation hooks.
781 ACE_ALLOC_HOOK_DECLARE
;
785 * @class ACE_Hash_Multi_Map_Const_Iterator
787 * @brief Const forward iterator for the @c ACE_Hash_Multi_Map_Manager.
789 * This class does not perform any internal locking of the
790 * @c ACE_Hash_Multi_Map_Manager it is iterating upon since locking is
791 * inherently inefficient and/or error-prone within an STL-style
792 * iterator. If you require locking, you can explicitly use an
793 * @c ACE_Guard or @c ACE_Read_Guard on the @c ACE_Hash_Multi_Map_Manager's
794 * internal lock, which is accessible via its @c mutex method.
796 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
797 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
>
800 // = Initialization method.
801 ACE_Hash_Multi_Map_Const_Iterator (const ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
804 // = Iteration methods.
805 /// Move forward by one element in the set. Returns 0 when all the
806 /// items in the set have been seen, else 1.
809 /// Dump the state of an object.
810 void dump (void) const;
812 // = STL styled iteration, compare, and reference functions.
815 ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator++ (void);
818 ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator++ (int);
821 ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator-- (void);
824 ACE_Hash_Multi_Map_Const_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator-- (int);
826 /// Declare the dynamic allocation hooks.
827 ACE_ALLOC_HOOK_DECLARE
;
831 * @class ACE_Hash_Multi_Map_Bucket_Iterator
833 * @brief Forward iterator for the @c ACE_Hash_Multi_Map_Manager which
834 * only traverses a particular bucket. The particular bucket is
835 * specified by the @c EXT_ID parameter specified in the constructor.
837 * This class does not perform any internal locking of the
838 * @c ACE_Hash_Multi_Map_Manager it is iterating upon since locking is
839 * inherently inefficient and/or error-prone within an STL-style
840 * iterator. If you require locking, you can explicitly use an
841 * @c ACE_Guard or @c ACE_Read_Guard on the @c ACE_Hash_Multi_Map_Manager's
842 * internal lock, which is accessible via its @c mutex method.
844 * Note that a creation method for this new iterator cannot be added
845 * to the hash map, since this would require adding explicit template
846 * instantiations for bucket iterators on platforms with broken
849 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
850 class ACE_Hash_Multi_Map_Bucket_Iterator
853 // = Initialization method.
854 ACE_Hash_Multi_Map_Bucket_Iterator (ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
855 const EXT_ID
&ext_id
,
858 // = STL styled iteration, compare, and reference functions.
861 ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator++ (void);
864 ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator++ (int);
867 ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator-- (void);
870 ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator-- (int);
872 /// Returns a reference to the interal element this object is pointing to.
873 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>& operator* (void) const;
875 /// Returns a pointer to the interal element this object is pointing to.
876 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
>* operator-> (void) const;
878 /// Returns reference the Hash_Multi_Map_Manager that is being iterated
880 ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>& map (void);
882 /// Check if two iterators point to the same position
883 bool operator== (const ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
884 bool operator!= (const ACE_Hash_Multi_Map_Bucket_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &) const;
887 /// Move forward by one element in the set. Returns 0 when there's
888 /// no more item in the set after the current items, else 1.
889 int forward_i (void);
891 /// Move backward by one element in the set. Returns 0 when there's
892 /// no more item in the set before the current item, else 1.
893 int reverse_i (void);
895 /// Map we are iterating over.
896 ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> *map_man_
;
898 /// Keeps track of how far we've advanced in the table.
901 /// Keeps track of how far we've advanced in a linked list in each
903 ACE_Hash_Multi_Map_Entry
<EXT_ID
, INT_ID
> *next_
;
907 * @class ACE_Hash_Multi_Map_Reverse_Iterator
909 * @brief Reverse iterator for the @c ACE_Hash_Multi_Map_Manager.
911 * This class does not perform any internal locking of the
912 * @c ACE_Hash_Multi_Map_Manager it is iterating upon since locking is
913 * inherently inefficient and/or error-prone within an STL-style
914 * iterator. If you require locking, you can explicitly use an
915 * @c ACE_Guard or @c ACE_Read_Guard on the @c ACE_Hash_Multi_Map_Manager's
916 * internal lock, which is accessible via its @c mutex method.
918 template <class EXT_ID
, class INT_ID
, class HASH_KEY
, class COMPARE_KEYS
, class ACE_LOCK
>
919 class ACE_Hash_Multi_Map_Reverse_Iterator
: public ACE_Hash_Multi_Map_Iterator_Base
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
>
922 // = Initialization method.
923 ACE_Hash_Multi_Map_Reverse_Iterator (ACE_Hash_Multi_Map_Manager
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &mm
,
926 // = Iteration methods.
927 /// Move forward by one element in the set. Returns 0 when all the
928 /// items in the set have been seen, else 1.
931 /// Dump the state of an object.
932 void dump (void) const;
934 // = STL styled iteration, compare, and reference functions.
937 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator++ (void);
940 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator++ (int);
943 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> &operator-- (void);
946 ACE_Hash_Multi_Map_Reverse_Iterator
<EXT_ID
, INT_ID
, HASH_KEY
, COMPARE_KEYS
, ACE_LOCK
> operator-- (int);
948 /// Declare the dynamic allocation hooks.
949 ACE_ALLOC_HOOK_DECLARE
;
952 ACE_END_VERSIONED_NAMESPACE_DECL
954 #if defined (__ACE_INLINE__)
955 # include "ace/Hash_Multi_Map_Manager_T.inl"
956 #endif /* __ACE_INLINE__ */
958 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
959 #include "ace/Hash_Multi_Map_Manager_T.cpp"
960 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
962 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
963 #pragma implementation ("Hash_Multi_Map_Manager_T.cpp")
964 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
966 #include /**/ "ace/post.h"
967 #endif /* ACE_HASH_MULTI_MAP_MANAGER_T_H */