summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-01-23 12:04:27 +0000
committerirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-01-23 12:04:27 +0000
commite9904f13828378317f57150034d9ceccf86b62f9 (patch)
tree018d8bd882f5c484fc5d29b03e65d55cdeaa092c
parent972642245aea9c803541ce0390dec403dbc92f16 (diff)
downloadATCD-e9904f13828378317f57150034d9ceccf86b62f9.tar.gz
*** empty log message ***
-rw-r--r--ChangeLog-99b45
-rw-r--r--ace/Active_Map_Manager.cpp12
-rw-r--r--ace/Active_Map_Manager.h78
-rw-r--r--ace/Active_Map_Manager.i49
-rw-r--r--ace/Active_Map_Manager_T.cpp20
-rw-r--r--ace/Active_Map_Manager_T.h158
-rw-r--r--ace/Active_Map_Manager_T.i235
-rw-r--r--ace/Containers_T.h2
-rw-r--r--ace/Makefile2
-rw-r--r--ace/Map_Manager.cpp1000
-rw-r--r--ace/Map_Manager.h190
-rw-r--r--ace/Map_Manager.i429
-rw-r--r--ace/ace_dll.dsp72
-rw-r--r--ace/ace_lib.dsp68
-rw-r--r--tests/Map_Manager_Test.cpp694
-rw-r--r--tests/SString_Test.cpp3
16 files changed, 2041 insertions, 1016 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b
index 095737589ca..7135d8cf083 100644
--- a/ChangeLog-99b
+++ b/ChangeLog-99b
@@ -1,3 +1,48 @@
+Sat Jan 23 04:53:12 1999 Irfan Pyarali <irfan@cs.wustl.edu>
+
+ * ace/Active_Map_Manager: Added a new associative container (map
+ abstraction) that associates system generated keys with user
+ specified values. Since the key is system generated, searches
+ are very fast and take a constant amount of time. This map uses
+ a key that keeps information of the index and the generation
+ count of the slot it represents. Since the index information is
+ part of the key, lookups are super fast and predictable.
+
+ This performance of this map is truely awesome:
+
+ - inserts O(1)
+ - lookups O(1)
+ - deletes O(1)
+
+ * ace/Map_Manager: Completely reworked the internals of the
+ Map_Manager. A number of problems were addressed:
+
+ (a) Finding an empty slot took O(n). New code takes O(1).
+
+ (b) Resizing was lame as it increased by ACE_DEFAULT_MAP_SIZE
+ everytime. The new scheme is cool since it grows
+ exponentially up to 64K and after that grow in chunks of
+ 32K.
+
+ (c) Old scheme used a simple but inefficient <is_free_> flag.
+ The new scheme uses two doubly linked list to track used and
+ free slots. Note that this scheme still uses an array to
+ manage the search structure but manages the two linked list
+ on top of the array. Thanks to Carlos for this cool idea.
+
+ (d) current_size() was broken. This is fixed in the new code.
+
+ (e) Inlined a bunch of small functions.
+
+ * tests/SString_Test.cpp: Added empty string test.
+
+ * ace/Containers_T.h (operator=): ACE_Array_Base must be fully
+ qualified: ACE_Array_Base<T>. Thanks to Susan Liebeskind
+ <shl@janis.gtri.gatech.edu> for pointing this out.
+
+ * tests/Map_Manager_Test.cpp (test_map_manager): Added
+ Active_Map_Manager to the test.
+
Fri Jan 22 21:27:14 1999 Kirthika Parameswaran <kirthika@cs.wustl.edu>
* ace/Hash_Map_Manager_T.h
diff --git a/ace/Active_Map_Manager.cpp b/ace/Active_Map_Manager.cpp
new file mode 100644
index 00000000000..255d16ccfeb
--- /dev/null
+++ b/ace/Active_Map_Manager.cpp
@@ -0,0 +1,12 @@
+// $Id$
+
+#define ACE_BUILD_DLL
+
+#include "ace/Active_Map_Manager.h"
+
+ACE_RCSID(ace, Active_Map_Manager, "$Id$")
+
+#if !defined (__ACE_INLINE__)
+#include "ace/Active_Map_Manager.i"
+#endif /* __ACE_INLINE__ */
+
diff --git a/ace/Active_Map_Manager.h b/ace/Active_Map_Manager.h
new file mode 100644
index 00000000000..f87dcacb2ee
--- /dev/null
+++ b/ace/Active_Map_Manager.h
@@ -0,0 +1,78 @@
+/* -*- C++ -*- */
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// ace
+//
+// = FILENAME
+// Active_Map_Manager.h
+//
+// = AUTHOR
+// Irfan Pyarali
+//
+// ============================================================================
+
+#ifndef ACE_ACTIVE_MAP_MANAGER_H
+#define ACE_ACTIVE_MAP_MANAGER_H
+
+#include "ace/OS.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+class ACE_Export ACE_Active_Map_Manager_Key
+{
+ // = TITLE
+ // Key used in the Active Object Map.
+ //
+ // = DESCRIPTION
+ // This key keeps information of the index and the generation
+ // count of the slot it represents. Since the index information
+ // is part of the key, lookups are super fast and predictable,
+public:
+ ACE_Active_Map_Manager_Key (void);
+ // Default constructor.
+
+ ACE_Active_Map_Manager_Key (u_long index,
+ u_long generation);
+ // Constructor given the index and generation number. This is
+ // useful once the user has somehow recovered the index and
+ // generation number from the client.
+
+ u_long index (void) const;
+ // Get the index.
+
+ u_long generation (void) const;
+ // Get the generation number.
+
+ // = These really should be protected but because of template
+ // friends, they are not.
+
+ void index (u_long i);
+ // Set the index.
+
+ void generation (u_long g);
+ // Set the generation number.
+
+ void increment_generation_count (void);
+ // Increment the generation number.
+
+private:
+ u_long index_;
+ // Index in the active map.
+
+ u_long generation_;
+ // Generation number of <index_> slot in the active map.
+};
+
+// Include the templates here.
+#include "ace/Active_Map_Manager_T.h"
+
+#if defined (__ACE_INLINE__)
+#include "ace/Active_Map_Manager.i"
+#endif /* __ACE_INLINE__ */
+
+#endif /* ACE_ACTIVE_MAP_MANAGER_H */
diff --git a/ace/Active_Map_Manager.i b/ace/Active_Map_Manager.i
new file mode 100644
index 00000000000..17308cbcaa0
--- /dev/null
+++ b/ace/Active_Map_Manager.i
@@ -0,0 +1,49 @@
+// $Id$
+
+ACE_INLINE
+ACE_Active_Map_Manager_Key::ACE_Active_Map_Manager_Key (void)
+ : index_ (~0),
+ generation_ (0)
+{
+ // If you change ~0, please change ACE_Map_Manager::free_list_id()
+ // accordingly.
+}
+
+ACE_INLINE
+ACE_Active_Map_Manager_Key::ACE_Active_Map_Manager_Key (u_long index,
+ u_long generation)
+ : index_ (index),
+ generation_ (generation)
+{
+}
+
+ACE_INLINE u_long
+ACE_Active_Map_Manager_Key::index (void) const
+{
+ return this->index_;
+}
+
+ACE_INLINE u_long
+ACE_Active_Map_Manager_Key::generation (void) const
+{
+ return this->generation_;
+}
+
+ACE_INLINE void
+ACE_Active_Map_Manager_Key::index (u_long i)
+{
+ this->index_ = i;
+}
+
+ACE_INLINE void
+ACE_Active_Map_Manager_Key::generation (u_long g)
+{
+ this->generation_ = g;
+}
+
+ACE_INLINE void
+ACE_Active_Map_Manager_Key::increment_generation_count (void)
+{
+ ++this->generation_;
+}
+
diff --git a/ace/Active_Map_Manager_T.cpp b/ace/Active_Map_Manager_T.cpp
new file mode 100644
index 00000000000..b7432589dc0
--- /dev/null
+++ b/ace/Active_Map_Manager_T.cpp
@@ -0,0 +1,20 @@
+// $Id$
+
+#ifndef ACE_ACTIVE_MAP_MANAGER_T_C
+#define ACE_ACTIVE_MAP_MANAGER_T_C
+
+#include "ace/Active_Map_Manager_T.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#if !defined (__ACE_INLINE__)
+#include "ace/Active_Map_Manager_T.i"
+#endif /* __ACE_INLINE__ */
+
+ACE_RCSID(ace, Active_Map_Manager_T, "$Id$")
+
+ACE_ALLOC_HOOK_DEFINE(ACE_Active_Map_Manager)
+
+#endif /* ACE_ACTIVE_MAP_MANAGER_C */
diff --git a/ace/Active_Map_Manager_T.h b/ace/Active_Map_Manager_T.h
new file mode 100644
index 00000000000..8448a335a0a
--- /dev/null
+++ b/ace/Active_Map_Manager_T.h
@@ -0,0 +1,158 @@
+/* -*- C++ -*- */
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// ace
+//
+// = FILENAME
+// Active_Map_Manager_T.h
+//
+// = AUTHOR
+// Irfan Pyarali
+//
+// ============================================================================
+
+#ifndef ACE_ACTIVE_MAP_MANAGER_T_H
+#define ACE_ACTIVE_MAP_MANAGER_T_H
+
+#include "ace/Map_Manager.h"
+#include "ace/Active_Map_Manager.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+template <class T>
+class ACE_Active_Map_Manager : public ACE_Map_Manager<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex>
+{
+ // = TITLE
+ // Define a map abstraction that associates system generated
+ // keys with user specified values.
+ //
+ // = DESCRIPTION
+ // Since the key is system generated, searches are very fast and
+ // take a constant amount of time.
+public:
+
+ // = Traits.
+ typedef ACE_Active_Map_Manager_Key key_type;
+ typedef T mapped_type;
+
+ typedef ACE_Map_Entry<ACE_Active_Map_Manager_Key, T> ENTRY;
+ typedef ACE_Map_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> ITERATOR;
+ typedef ACE_Map_Reverse_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> REVERSE_ITERATOR;
+
+ typedef ENTRY entry;
+ typedef ITERATOR iterator;
+ typedef REVERSE_ITERATOR reverse_iterator;
+
+ // = Initialization and termination methods.
+ ACE_Active_Map_Manager (ACE_Allocator *alloc = 0);
+ // Initialize a <Active_Map_Manager> with the <ACE_DEFAULT_MAP_SIZE>.
+
+ ACE_Active_Map_Manager (size_t size,
+ ACE_Allocator *alloc = 0);
+ // Initialize a <Active_Map_Manager> with <size> entries.
+
+ ~ACE_Active_Map_Manager (void);
+ // Close down a <Active_Map_Manager> and release dynamically
+ // allocated resources.
+
+ int open (size_t length = ACE_DEFAULT_MAP_SIZE,
+ ACE_Allocator *alloc = 0);
+ // Initialize a <Active_Map_Manager> with size <length>.
+
+ int close (void);
+ // Close down a <Active_Map_Manager> and release dynamically
+ // allocated resources.
+
+ int bind (const T &value,
+ ACE_Active_Map_Manager_Key &key);
+ // Add <value> to the map, and the corresponding key produced by the
+ // Active_Map_Manager is returned through <key>.
+
+ int bind (const T &value);
+ // Add <value> to the map. The user does not care about the
+ // corresponding key produced by the Active_Map_Manager.
+
+ int rebind (const ACE_Active_Map_Manager_Key &key,
+ const T &value,
+ T &old_value);
+ // Reassociate <key> with <value>, storing the old value into the
+ // "out" parameter <old_value>. The function fails if <key> is not
+ // in the map.
+
+ int rebind (const ACE_Active_Map_Manager_Key &key,
+ const T &value);
+ // Reassociate <key> with <value>. The function fails if <key> is
+ // not in the map.
+
+ int find (const ACE_Active_Map_Manager_Key &key,
+ T &value);
+ // Locate <value> associated with <key>.
+
+ int find (const ACE_Active_Map_Manager_Key &key);
+ // Is <key> in the map?
+
+ int unbind (const ACE_Active_Map_Manager_Key &key);
+ // Remove <key> from the map.
+
+ int unbind (const ACE_Active_Map_Manager_Key &key, T &value);
+ // Remove <key> from the map, and return the <value> associated with
+ // <key>.
+
+ size_t current_size (void);
+ // Return the current size of the map.
+
+ size_t total_size (void);
+ // Return the total size of the map.
+
+ void dump (void) const;
+ // Dump the state of an object.
+
+ // = STL styled iterator factory functions.
+
+ ACE_Map_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> begin (void);
+ ACE_Map_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> end (void);
+ // Return forward iterator.
+
+ ACE_Map_Reverse_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> rbegin (void);
+ ACE_Map_Reverse_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> rend (void);
+ // Return reverse iterator.
+
+ ACE_ALLOC_HOOK_DECLARE;
+ // Declare the dynamic allocation hooks.
+
+protected:
+
+ typedef ACE_Map_Manager<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex> BASE;
+ // Private base class
+
+ int create_key (ACE_Active_Map_Manager_Key &key);
+ // Creates a key.
+
+ void shared_unbind (const ACE_Active_Map_Manager_Key &key);
+ // Remove <key> from the map.
+
+private:
+
+ // = Disallow these operations.
+ ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Active_Map_Manager<T> &))
+ ACE_UNIMPLEMENTED_FUNC (ACE_Active_Map_Manager (const ACE_Active_Map_Manager<T> &))
+};
+
+#if defined (__ACE_INLINE__)
+#include "ace/Active_Map_Manager_T.i"
+#endif /* __ACE_INLINE__ */
+
+#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
+#include "ace/Active_Map_Manager_T.cpp"
+#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
+
+#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
+#pragma implementation "Active_Map_Manager_T.cpp"
+#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
+
+#endif /* ACE_ACTIVE_MAP_MANAGER_T_H */
diff --git a/ace/Active_Map_Manager_T.i b/ace/Active_Map_Manager_T.i
new file mode 100644
index 00000000000..934da2b75c0
--- /dev/null
+++ b/ace/Active_Map_Manager_T.i
@@ -0,0 +1,235 @@
+// $Id$
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::create_key (ACE_Active_Map_Manager_Key &key)
+{
+ size_t index;
+ int result = this->next_free (index);
+
+ if (result == 0)
+ {
+ // Move from free list to occupied list
+ this->move_from_free_list_to_occupied_list (index);
+
+ // Reset the key.
+ this->search_structure_[index].ext_id_.increment_generation_count ();
+ this->search_structure_[index].ext_id_.index (index);
+
+ // Copy the key for the user.
+ key = this->search_structure_[index].ext_id_;
+ }
+
+ return result;
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::bind (const T &value)
+{
+ ACE_Active_Map_Manager_Key key;
+ return this->bind (value, key);
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::bind (const T &value,
+ ACE_Active_Map_Manager_Key &key)
+{
+ int result = this->create_key (key);
+
+ if (result == 0)
+ {
+ // Store new value.
+ this->search_structure_[key.index ()].int_id_ = value;
+
+ // Update the current size.
+ ++this->cur_size_;
+ }
+
+ return result;
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::find (const ACE_Active_Map_Manager_Key &key)
+{
+ size_t index = key.index ();
+ size_t generation = key.generation ();
+
+ if (index > this->total_size_ ||
+ this->search_structure_[index].ext_id_.generation () != generation ||
+ this->search_structure_[index].ext_id_.index () == this->free_list_id ())
+ return -1;
+
+ return 0;
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::find (const ACE_Active_Map_Manager_Key &key,
+ T &value)
+{
+ int result = this->find (key);
+
+ if (result == 0)
+ {
+ // Get current value for key.
+ size_t index = key.index ();
+ value = this->search_structure_[index].int_id_;
+ }
+
+ return result;
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::rebind (const ACE_Active_Map_Manager_Key &key,
+ const T &value,
+ T &old_value)
+{
+ int result = this->find (key);
+
+ if (result == 0)
+ {
+ // Copy old value.
+ old_value = this->search_structure_[key.index ()].int_id_;
+
+ // Store new value.
+ this->search_structure_[key.index ()].int_id_ = value;
+ }
+
+ return result;
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::rebind (const ACE_Active_Map_Manager_Key &key,
+ const T &value)
+{
+ int result = this->find (key);
+
+ if (result == 0)
+ {
+ // Store new value.
+ this->search_structure_[key.index ()].int_id_ = value;
+ }
+
+ return result;
+}
+
+template <class T> ACE_INLINE void
+ACE_Active_Map_Manager<T>::shared_unbind (const ACE_Active_Map_Manager_Key &key)
+{
+ size_t index = key.index ();
+
+ // Move from occupied list to free list
+ this->move_from_occupied_list_to_free_list (index);
+
+ // Reset the index. This will tell us that this entry is free.
+ this->search_structure_[index].ext_id_.index (this->free_list_id ());
+
+ // Update the current size.
+ --this->cur_size_;
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::unbind (const ACE_Active_Map_Manager_Key &key,
+ T &value)
+{
+ int result = this->find (key);
+
+ if (result == 0)
+ {
+ // Copy old value.
+ size_t index = key.index ();
+ value = this->search_structure_[index].int_id_;
+
+ // Unbind.
+ this->shared_unbind (key);
+ }
+
+ return result;
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::unbind (const ACE_Active_Map_Manager_Key &key)
+{
+ int result = this->find (key);
+
+ if (result == 0)
+ {
+ // Unbind.
+ this->shared_unbind (key);
+ }
+
+ return result;
+}
+
+template <class T> ACE_INLINE
+ACE_Active_Map_Manager<T>::ACE_Active_Map_Manager (ACE_Allocator *alloc)
+ : BASE (alloc)
+{
+}
+
+template <class T> ACE_INLINE
+ACE_Active_Map_Manager<T>::ACE_Active_Map_Manager (size_t size,
+ ACE_Allocator *alloc)
+ : BASE (size,
+ alloc)
+{
+}
+
+template <class T> ACE_INLINE
+ACE_Active_Map_Manager<T>::~ACE_Active_Map_Manager (void)
+{
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::open (size_t length,
+ ACE_Allocator *alloc)
+{
+ return BASE::open (length, alloc);
+}
+
+template <class T> ACE_INLINE int
+ACE_Active_Map_Manager<T>::close (void)
+{
+ return BASE::close ();
+}
+
+template <class T> ACE_INLINE size_t
+ACE_Active_Map_Manager<T>::current_size (void)
+{
+ return BASE::current_size ();
+}
+
+template <class T> ACE_INLINE size_t
+ACE_Active_Map_Manager<T>::total_size (void)
+{
+ return BASE::total_size ();
+}
+
+template <class T> ACE_INLINE void
+ACE_Active_Map_Manager<T>::dump (void) const
+{
+ return BASE::dump ();
+}
+
+template <class T> ACE_Map_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex>
+ACE_Active_Map_Manager<T>::begin (void)
+{
+ return BASE::begin ();
+}
+
+template <class T> ACE_INLINE ACE_Map_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex>
+ACE_Active_Map_Manager<T>::end (void)
+{
+ return BASE::end ();
+}
+
+template <class T> ACE_INLINE ACE_Map_Reverse_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex>
+ACE_Active_Map_Manager<T>::rbegin (void)
+{
+ return BASE::rbegin ();
+}
+
+template <class T> ACE_INLINE ACE_Map_Reverse_Iterator<ACE_Active_Map_Manager_Key, T, ACE_Null_Mutex>
+ACE_Active_Map_Manager<T>::rend (void)
+{
+ return BASE::rend ();
+}
+
diff --git a/ace/Containers_T.h b/ace/Containers_T.h
index 361430dc9fb..2bca82f0b46 100644
--- a/ace/Containers_T.h
+++ b/ace/Containers_T.h
@@ -1410,7 +1410,7 @@ public:
// copy of the contents of parameter <s>, i.e., *this == s will
// return true.
- ACE_Array_Base& operator= (const ACE_Array_Base<T> &s);
+ ACE_Array_Base<T>& operator= (const ACE_Array_Base<T> &s);
// Assignment operator performs an assignment by making an exact
// copy of the contents of parameter <s>, i.e., *this == s will
// return true. Note that if the <max_size_> of <array_> is >= than
diff --git a/ace/Makefile b/ace/Makefile
index 84f28fc747a..5dfa933543e 100644
--- a/ace/Makefile
+++ b/ace/Makefile
@@ -11,6 +11,7 @@ SHLIB = libACE.$(SOEXT)
FILES = Log_Msg \
ACE \
Activation_Queue \
+ Active_Map_Manager \
Addr \
ARGV \
Arg_Shifter \
@@ -152,6 +153,7 @@ FILES = Log_Msg \
TEMPLATE_FILES = \
Acceptor \
+ Active_Map_Manager_T \
Asynch_Acceptor \
Auto_Ptr \
Connector \
diff --git a/ace/Map_Manager.cpp b/ace/Map_Manager.cpp
index 73933478cd2..143aa8864a3 100644
--- a/ace/Map_Manager.cpp
+++ b/ace/Map_Manager.cpp
@@ -19,402 +19,189 @@
ACE_RCSID(ace, Map_Manager, "$Id$")
-ACE_ALLOC_HOOK_DEFINE(ACE_Map_Entry)
-
-# if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
-template <class EXT_ID, class INT_ID>
-ACE_Map_Entry<EXT_ID, INT_ID>::~ACE_Map_Entry (void)
-{
- // No-op just to keep some compilers happy...
-}
-#endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */
-
-template <class EXT_ID, class INT_ID> void
-ACE_Map_Entry<EXT_ID, INT_ID>::dump (void) const
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::open (size_t size,
+ ACE_Allocator *alloc)
{
- ACE_TRACE ("ACE_Map_Entry<EXT_ID, INT_ID>::dump");
-
- ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("is_free_ = %d"), this->is_free_));
- ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
-}
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
-ACE_ALLOC_HOOK_DEFINE(ACE_Map_Manager)
+ // Use the user specified allocator or the default singleton one.
+ if (alloc == 0)
+ alloc = ACE_Allocator::instance ();
-template <class EXT_ID, class INT_ID, class ACE_LOCK> void
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::dump");
+ this->allocator_ = alloc;
- ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("total_size_ = %d"), this->total_size_));
- ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("\ncur_size_ = %d"), this->cur_size_));
- this->allocator_->dump ();
- this->lock_.dump ();
- ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
-}
+ // This assertion is here to help track a situation that shouldn't
+ // happen.
+ ACE_ASSERT (size != 0);
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager (size_t size,
- ACE_Allocator *alloc)
- : search_structure_ (0),
- allocator_ (0),
- total_size_ (0),
- cur_size_ (0)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager");
+ // Reset circular occupied list.
+ this->occupied_list_.next (this->occupied_list_id ());
+ this->occupied_list_.prev (this->occupied_list_id ());
- if (this->open (size, alloc) == -1)
- ACE_ERROR ((LM_ERROR, ASYS_TEXT ("ACE_Map_Manager\n")));
-}
+ // Reset circular free list.
+ this->free_list_.next (this->free_list_id ());
+ this->free_list_.prev (this->free_list_id ());
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager (ACE_Allocator *alloc)
- : search_structure_ (0),
- allocator_ (0),
- total_size_ (0),
- cur_size_ (0)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager");
- if (this->open (ACE_DEFAULT_MAP_SIZE, alloc) == -1)
- ACE_ERROR ((LM_ERROR, ASYS_TEXT ("ACE_Map_Manager\n")));
+ // Resize from 0 to <size>. Note that this will also set up the
+ // circular free list.
+ return this->resize_i (size);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close_i (void)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close_i");
-
+ // Free entries.
this->free_search_structure ();
+
+ // Reset sizes.
this->total_size_ = 0;
this->cur_size_ = 0;
- return 0;
-}
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close (void)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+ // Reset circular free list.
+ this->free_list_.next (this->free_list_id ());
+ this->free_list_.prev (this->free_list_id ());
- return this->close_i ();
-}
+ // Reset circular occupied list.
+ this->occupied_list_.next (this->occupied_list_id ());
+ this->occupied_list_.prev (this->occupied_list_id ());
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::~ACE_Map_Manager (void)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::~ACE_Map_Manager");
- this->close ();
+ return 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::resize_i (size_t size)
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind_i (const EXT_ID &ext_id,
+ const INT_ID &int_id)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::resize_i");
-
- // If we need to grow buffer, then remove the existing buffer.
- void *ptr;
-
- ACE_ALLOCATOR_RETURN (ptr,
- this->allocator_->malloc (size * sizeof (ACE_Map_Entry<EXT_ID, INT_ID>)),
- -1);
-
- size_t i;
-
- ACE_Map_Entry<EXT_ID, INT_ID> *temp = (ACE_Map_Entry<EXT_ID, INT_ID> *) ptr;
-
- // Copy over the currently active elements.
- for (i = 0; i < this->cur_size_; i++)
- new (&(temp[i])) ACE_Map_Entry<EXT_ID, INT_ID> (this->search_structure_[i]); // Structure assignment.
-
- // Mark the newly allocated elements as being "free".
-
- for (i = this->cur_size_; i < size; i++)
+ // Try to find the key.
+ size_t index = 0;
+ int result = this->find_i (ext_id, index);
+
+ if (result == 0)
{
- // Call the constructor for each element in the array. Note
- // that this requires a default constructor for <EXT_ID> and
- // <INT_ID>.
- new (&(temp[i])) ACE_Map_Entry<EXT_ID, INT_ID>;
- temp[i].is_free_ = 1;
+ // We found the key. Nothing to change.
+ return 1;
}
-
- // Remove/free old elements, update the new totoal size.
- this->free_search_structure ();
- this->total_size_ = size;
-
- // Start using new elements.
- this->search_structure_ = temp;
- return 0;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::begin (void)
-{
- return ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this);
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::end (void)
-{
- return ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1);
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rbegin (void)
-{
- return ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this);
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rend (void)
-{
- return ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1);
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> void
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::free_search_structure (void)
-{
- if (this->search_structure_ != 0)
+ else
{
- for (size_t i = 0; i < this->total_size_; i++)
- // Explicitly call the destructor.
- {
- ACE_Map_Entry<EXT_ID, INT_ID> *ss = &this->search_structure_[i];
- // The "if" second argument results in a no-op instead of
- // deallocation.
- ACE_DES_FREE_TEMPLATE2 (ss, ACE_NOOP,
- ACE_Map_Entry, EXT_ID, INT_ID);
- }
-
- // Actually free the memory.
- this->allocator_->free (this->search_structure_);
- this->search_structure_ = 0;
+ // We didn't find the key.
+ return this->shared_bind (ext_id,
+ int_id);
}
}
-// Create a new search_structure of size SIZE.
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::open (size_t size,
- ACE_Allocator *alloc)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::open");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
-
- if (alloc == 0)
- alloc = ACE_Allocator::instance ();
-
- this->allocator_ = alloc;
-
- // This assertion is here to help track a situation that shouldn't happen
- ACE_ASSERT (size != 0);
-
- return this->resize_i (size);
-}
-
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_find (const EXT_ID &ext_id,
- int &first_free)
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::next_free (size_t &free_slot)
{
- // See if the entry is already there, keeping track of the first
- // free slot.
+ // Find an empty slot.
+ free_slot = this->free_list_.next ();
- for (size_t i = 0; i < this->cur_size_; i++)
+ // Make sure we haven't run out of free slots.
+ if (free_slot != this->free_list_id ())
{
- ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[i];
-
- if (ss.is_free_ == 0)
+ return 0;
+ }
+ else
+ {
+ // Resize the map.
+ int result = this->resize_i (this->new_size ());
+
+ // Check for errors.
+ if (result == 0)
{
- if (ss.ext_id_ == ext_id)
- return i;
+ // New free slot.
+ free_slot = this->free_list_.next ();
}
- else if (first_free == -1)
- first_free = int (i);
- }
-
- errno = ENOENT;
- return -1;
-}
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::equal (const EXT_ID &id1,
- const EXT_ID &id2)
-{
- return id1 == id2;
+ return result;
+ }
}
-// Find the <int_id> corresponding to the <ext_id>.
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_find (const EXT_ID &ext_id)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_find");
-
- for (size_t i = 0; i < this->cur_size_; i++)
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_move (size_t index,
+ ACE_Map_Entry<EXT_ID, INT_ID> &current_list,
+ size_t current_list_id,
+ ACE_Map_Entry<EXT_ID, INT_ID> &new_list,
+ size_t new_list_id)
+{
+ // Grab the entry.
+ ENTRY &entry = this->search_structure_[index];
+
+ //
+ // Remove from current list.
+ //
+
+ // Fix the entry before us.
+ size_t current_list_prev = entry.prev ();
+ if (current_list_prev == current_list_id)
{
- const ACE_Map_Entry<EXT_ID, INT_ID> &ss
- = this->search_structure_[i];
-
- if (ss.is_free_ == 0 && this->equal (ss.ext_id_, ext_id))
- // We found it!
- return i;
+ current_list.next (entry.next ());
}
-
- // not found
- errno = ENOENT;
- return -1;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_bind (const EXT_ID &ext_id,
- const INT_ID &int_id,
- int first_free)
-{
- if (first_free > -1)
+ else
{
- // We found a free spot, let's reuse it.
-
- ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[first_free];
-
- ss.ext_id_ = ext_id;
- ss.int_id_ = int_id;
- ss.is_free_ = 0;
- this->allocator_->sync ((void *) &this->search_structure_[first_free], sizeof ss);
- return 0;
+ this->search_structure_[current_list_prev].next (entry.next ());
}
-
- // Check if we have reached total_size_
- else if (this->cur_size_ == this->total_size_)
- // We are out of room so grow the map
- if (this->resize_i (this->total_size_ + ACE_DEFAULT_MAP_SIZE) == -1)
- return -1;
-
- // Insert at the end of the active portion.
-
- ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[this->cur_size_];
-
- ss.int_id_ = int_id;
- ss.ext_id_ = ext_id;
- ss.is_free_ = 0;
- this->allocator_->sync ((void *) &this->search_structure_[this->cur_size_], sizeof ss);
- this->cur_size_++;
- this->allocator_->sync ((void *) &this->cur_size_, sizeof this->cur_size_);
- return 0;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind_i (const EXT_ID &ext_id,
- INT_ID &int_id)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind_i");
- int first_free = -1;
- int index = this->shared_find (ext_id, first_free);
-
- if (index >= 0)
+
+ // Fix the entry after us.
+ size_t current_list_next = entry.next ();
+ if (current_list_next == current_list_id)
{
- // There was already something there, so make a copy, but
- // *don't* update anything in the map!
-
- int_id = this->search_structure_[index].int_id_;
- return 1;
+ current_list.prev (entry.prev ());
}
else
- // We didn't find it, so let's bind it!
- return this->shared_bind (ext_id, int_id, first_free);
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind (const EXT_ID &ext_id,
- INT_ID &int_id)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
-
- return this->trybind_i (ext_id, int_id);
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i (const EXT_ID &ext_id)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i");
- return this->shared_find (ext_id);
-}
-
-// Find the INT_ID corresponding to the EXT_ID.
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find (const EXT_ID &ext_id)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find");
- ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+ {
+ this->search_structure_[current_list_next].prev (entry.prev ());
+ }
- return this->find_i (ext_id);
-}
+ //
+ // Add to new list.
+ //
-// Unbind (remove) the EXT_ID from the map and return it via an out
-// parameter. Note that this method does *not* free up the INT_ID
-// structure. Thus, if there is dynamic memory associated with this,
-// the caller is responsible for freeing this memory.
+ // Fix us.
+ size_t new_list_next = new_list.next ();
+ entry.next (new_list_next);
+ entry.prev (new_list_id);
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i (const EXT_ID &ext_id,
- INT_ID &int_id)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i");
+ // Fix entry before us.
+ new_list.next (index);
- ssize_t index = this->shared_unbind (ext_id);
-
- if (index == -1)
- return -1;
+ // Fix entry after us.
+ if (new_list_next == new_list_id)
+ {
+ new_list.prev (index);
+ }
else
{
- int_id = this->search_structure_[index].int_id_;
- return 0;
+ this->search_structure_[new_list_next].prev (index);
}
}
-// Associate <ext_id> with <int_id>. If <ext_id> is already in the
-// map then the <Map_Entry> is not changed. Returns 0 if a new
-// entry is bound successfully, returns 1 if an attempt is made to
-// bind an existing entry, and returns -1 if failures occur.
-
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind_i (const EXT_ID &ext_id,
- const INT_ID &int_id)
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_bind (const EXT_ID &ext_id,
+ const INT_ID &int_id)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind_i");
-
- int first_free = -1;
- // We need to save errno since <shared_find> may set errno to
- // ENOENT.
- int error = errno;
- int index = this->shared_find (ext_id, first_free);
+ // This function assumes that the find() has already been done, and
+ // therefore, simply adds to the map.
- if (index >= 0)
- // It was already bound, so return 1.
- return 1;
+ // Find an empty slot.
+ size_t index = 0;
+ int result = this->next_free (index);
- else
+ if (result == 0)
{
- // Restore errno.
- errno = error;
- // We didn't find it, so let's bind it!
- return this->shared_bind (ext_id, int_id, first_free);
+ // Copy key and value.
+ this->search_structure_[index].int_id_ = int_id;
+ this->search_structure_[index].ext_id_ = ext_id;
+
+ // Move from free list to occupied list
+ this->move_from_free_list_to_occupied_list (index);
+
+ // Update the current size.
+ ++this->cur_size_;
}
-}
-// Associate <ext_id> with <int_id>. If <ext_id> is not in the
-// map then behaves just like <bind>. Otherwise, store the old
-// values of <ext_id> and <int_id> into the "out" parameters and
-// rebind the new parameters. This is very useful if you need to
-// have an atomic way of updating <Map_Entries> and you also need
-// full control over memory allocation. Returns 0 if a new entry is
-// bound successfully, returns 1 if an existing entry was rebound,
-// and returns -1 if failures occur.
+ return result;
+}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind_i (const EXT_ID &ext_id,
@@ -422,433 +209,314 @@ ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind_i (const EXT_ID &ext_id,
EXT_ID &old_ext_id,
INT_ID &old_int_id)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind_i");
+ // First try to find the key.
+ size_t index = 0;
+ int result = this->find_i (ext_id,
+ index);
- int first_free = -1;
- int index = this->shared_find (ext_id, first_free);
-
- if (index >= 0)
+ if (result == 0)
{
// We found it, so make copies of the old entries and rebind
// current entries.
-
- ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[index];
-
+ ENTRY &ss = this->search_structure_[index];
old_ext_id = ss.ext_id_;
old_int_id = ss.int_id_;
ss.ext_id_ = ext_id;
ss.int_id_ = int_id;
- this->allocator_->sync ((void *) &this->search_structure_[index], sizeof ss);
+
+ // Sync changed entry.
+ this->allocator_->sync (&ss, sizeof ss);
+
return 1;
}
else
- // We didn't find it, so let's bind it!
- return this->shared_bind (ext_id, int_id, first_free);
+ {
+ // We didn't find it, so let's add it.
+ return this->shared_bind (ext_id,
+ int_id);
+ }
}
-// Find the INT_ID corresponding to the EXT_ID.
-
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i (const EXT_ID &ext_id,
- INT_ID &int_id)
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind_i (const EXT_ID &ext_id,
+ const INT_ID &int_id)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i");
- int index = this->shared_find (ext_id);
+ // First try to find the key.
+ size_t index = 0;
+ int result = this->find_i (ext_id,
+ index);
+
+ if (result == 0)
+ {
+ // We found it, so rebind current entries.
+ ENTRY &ss = this->search_structure_[index];
+ ss.ext_id_ = ext_id;
+ ss.int_id_ = int_id;
+
+ // Sync changed entry.
+ this->allocator_->sync (&ss, sizeof ss);
- if (index == -1)
- // Didn't find it.
- return -1;
+ return 1;
+ }
else
{
- // Found it, so assign a copy.
- int_id = this->search_structure_[index].int_id_;
- return index;
+ // We didn't find it, so let's add it.
+ return this->shared_bind (ext_id,
+ int_id);
}
}
-// Unbind (remove) the EXT_ID from the map. Keeps track of where
-// the EXT_ID was found so that this->unbind (EXT_ID, INT_ID)
-// can return it to the caller.
-
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_unbind (const EXT_ID &ext_id)
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind_i (const EXT_ID &ext_id,
+ INT_ID &int_id)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_unbind");
- for (size_t i = 0; i < this->cur_size_; i++)
+ // Try to find the key.
+ size_t index = 0;
+ int result = this->find_i (ext_id,
+ index);
+
+ if (result == 0)
+ {
+ // Key was found. Make a copy of value, but *don't* update
+ // anything in the map!
+ int_id = this->search_structure_[index].int_id_;
+ return 1;
+ }
+ else
{
- ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[i];
+ // We didn't find it, so let's bind it!
+ return this->bind_i (ext_id,
+ int_id);
+ }
+}
- if (ss.is_free_ == 0 && this->equal (ss.ext_id_, ext_id))
+template <class EXT_ID, class INT_ID, class ACE_LOCK> int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i (const EXT_ID &ext_id,
+ size_t &index)
+{
+ // Go through the entire occupied list looking for the key.
+ for (size_t i = this->occupied_list_.next ();
+ i != this->occupied_list_id ();
+ i = this->search_structure_[i].next ())
+ {
+ if (this->equal (this->search_structure_[i].ext_id_,
+ ext_id))
{
- size_t index = i;
-
- // Mark this entry as being free.
- ss.is_free_ = 1;
-
- this->allocator_->sync ((void *) &ss.is_free_,
- sizeof ss.is_free_);
-
- // If we just unbound the highest active entry, then we need
- // to figure out where the next highest active entry is.
-
- if (i + 1 == this->cur_size_)
- {
- while (i > 0 && this->search_structure_[--i].is_free_)
- continue;
-
- if (i == 0 && this->search_structure_[i].is_free_)
- this->cur_size_ = 0;
- else
- this->cur_size_ = i + 1;
- this->allocator_->sync ((void *) &this->cur_size_,
- sizeof this->cur_size_);
- }
- return index;
+ // If found, return index.
+ index = i;
+ return 0;
}
}
- errno = ENOENT;
+
+ // Key was not found.
return -1;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind (const EXT_ID &ext_id,
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+ // Try to find the key.
+ size_t index = 0;
+ int result = this->find_i (ext_id,
+ index);
- return this->unbind_i (ext_id, int_id);
+ if (result == 0)
+ {
+ // Key was found. Make a copy of value.
+ int_id = this->search_structure_[index].int_id_;
+ }
+
+ return result;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind (const EXT_ID &ext_id,
- const INT_ID &int_id)
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i (const EXT_ID &ext_id,
+ size_t &index)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+ // Try to find the key.
+ int result = this->find_i (ext_id,
+ index);
- return this->bind_i (ext_id, int_id);
-}
+ if (result == 0)
+ {
+ // Move from occupied list to free list
+ this->move_from_occupied_list_to_free_list (index);
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind (const EXT_ID &ext_id,
- const INT_ID &int_id,
- EXT_ID &old_ext_id,
- INT_ID &old_int_id)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+ // Update the current size.
+ --this->cur_size_;
+ }
- return this->rebind_i (ext_id, int_id, old_ext_id, old_int_id);
+ return result;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find (const EXT_ID &ext_id,
- INT_ID &int_id)
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i (const EXT_ID &ext_id,
+ INT_ID &int_id)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find");
- ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
-
- return this->find_i (ext_id, int_id);
-}
+ // Unbind the entry.
+ size_t index = 0;
+ int result = this->unbind_i (ext_id,
+ index);
-// Unbind (remove) the EXT_ID from the map. Don't return the INT_ID
-// to the caller (this is useful for collections where the INT_IDs are
-// *not* dynamically allocated...)
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i (const EXT_ID &ext_id)
-{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i");
- return this->shared_unbind (ext_id) == -1 ? -1 : 0;
+ if (result == 0)
+ {
+ // If found, copy the value.
+ int_id = this->search_structure_[index].int_id_;
+ }
+
+ return result;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind (const EXT_ID &ext_id)
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::resize_i (size_t new_size)
{
- ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
- return this->unbind_i (ext_id) == -1 ? -1 : 0;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> size_t
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::current_size (void)
-{
- ACE_TRACE ("ACE_Map_Manager::current_size");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_,
- ACE_static_cast(size_t, -1));
- return this->cur_size_;
-}
+ size_t i;
+ ENTRY *temp = 0;
-template <class EXT_ID, class INT_ID, class ACE_LOCK> size_t
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::total_size (void)
-{
- ACE_TRACE ("ACE_Map_Manager::total_size");
- ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_,
- ACE_static_cast (size_t, -1));
- return this->total_size_;
-}
+ // Allocate new memory.
+ ACE_ALLOCATOR_RETURN (temp,
+ (ENTRY *) this->allocator_->malloc (new_size * sizeof (ENTRY)),
+ -1);
-template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_LOCK &
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::mutex (void)
-{
- ACE_TRACE ("ACE_Map_Manager::mutex");
- return this->lock_;
-}
+ // Copy over the occupied entires.
+ for (i = this->occupied_list_.next ();
+ i != this->occupied_list_id ();
+ i = this->search_structure_[i].next ())
+ {
+ // Copy constructor.
+ new (&(temp[i])) ENTRY (this->search_structure_[i]);
+ }
-// @@ && @@
+ // Copy over the free entires.
+ for (i = this->free_list_.next ();
+ i != this->free_list_id ();
+ i = this->search_structure_[i].next ())
+ {
+ // Copy constructor.
+ new (&(temp[i])) ENTRY (this->search_structure_[i]);
+ }
-ACE_ALLOC_HOOK_DEFINE(ACE_Map_Iterator_Base)
+ // Construct the new elements.
+ for (i = this->total_size_; i < new_size; i++)
+ {
+ // Call the constructor for each element in the array. Note
+ // that this requires a default constructor for <EXT_ID> and
+ // <INT_ID>.
+ new (&(temp[i])) ENTRY;
+ temp[i].next (i + 1);
+ temp[i].prev (i - 1);
+ }
-template <class EXT_ID, class INT_ID, class ACE_LOCK> void
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump_i (void) const
-{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump");
+ // Add new entries to the free list.
+ this->free_list_.next (this->total_size_);
+ this->free_list_.prev (new_size - 1);
+ temp[new_size - 1].next (this->free_list_id ());
+ temp[this->total_size_].prev (this->free_list_id ());
- ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("next_ = %d"), this->next_));
- ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
-}
+ // Remove/free old elements, update the new totoal size.
+ this->free_search_structure ();
+ this->total_size_ = new_size;
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator_Base (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int head)
- : map_man_ (&mm),
- next_ (-1)
-{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator_Base");
+ // Start using new elements.
+ this->search_structure_ = temp;
- if (head == 0)
- this->next_ = this->map_man_->cur_size_;
+ return 0;
}
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Map_Entry<EXT_ID, INT_ID> *&mm)
+template <class EXT_ID, class INT_ID, class ACE_LOCK> size_t
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::new_size (void)
{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::next");
+ // Calculate the new size.
+ size_t current_size = this->total_size_;
- if (this->map_man_->search_structure_ != 0
- // Note that this->next_ is never negative at this point...
- && ACE_static_cast(size_t, this->next_) < this->map_man_->cur_size_
- && this->next_ > -1)
+ if (current_size < MAX_EXPONENTIAL)
{
- mm = &this->map_man_->search_structure_[this->next_];
- return 1;
+ // Exponentially increase if we haven't reached MAX_EXPONENTIAL.
+ current_size *= 2;
}
else
- return 0;
+ {
+ // Linear increase if we have reached MAX_EXPONENTIAL.
+ current_size += LINEAR_INCREASE;
+ }
+
+ // This should be the new size.
+ return current_size;
}
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::free_search_structure (void)
{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::done");
+ // Free up the structure.
+ if (this->search_structure_ != 0)
+ {
+ for (size_t i = 0; i < this->total_size_; i++)
+ // Explicitly call the destructor.
+ {
+ ENTRY *ss = &this->search_structure_[i];
+ // The "if" second argument results in a no-op instead of
+ // deallocation.
+ ACE_DES_FREE_TEMPLATE2 (ss, ACE_NOOP,
+ ACE_Map_Entry, EXT_ID, INT_ID);
+ }
- return this->map_man_->search_structure_ == 0
- // Note that this->next_ is never negative at this point...
- || ACE_static_cast (ACE_CAST_CONST size_t, this->next_) >=
- this->map_man_->cur_size_
- || this->next_ <= -1;
+ // Actually free the memory.
+ this->allocator_->free (this->search_structure_);
+ this->search_structure_ = 0;
+ }
}
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::forward_i (void)
-{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::forward_i");
-
- for (++this->next_;
- ACE_static_cast(size_t, this->next_) < this->map_man_->cur_size_
- && this->map_man_->search_structure_[this->next_].is_free_;
- this->next_++)
- continue;
- return ACE_static_cast(size_t, this->next_) < this->map_man_->cur_size_;
-}
+ACE_ALLOC_HOOK_DEFINE(ACE_Map_Entry)
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::reverse_i (void)
-{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::reverse_i");
-
- for (--this->next_;
- this->next_ >= 0
- && this->map_man_->search_structure_[this->next_].is_free_;
- this->next_--)
- continue;
- return this->next_ >= 0;
-}
+ACE_ALLOC_HOOK_DEFINE(ACE_Map_Manager)
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Entry<EXT_ID, INT_ID>&
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator* (void)
-{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator*");
- ACE_Map_Entry<EXT_ID, INT_ID> *retv = 0;
+ACE_ALLOC_HOOK_DEFINE(ACE_Map_Iterator_Base)
- int result = this->next (retv);
- ACE_ASSERT (result != 0);
- ACE_UNUSED_ARG (result);
+ACE_ALLOC_HOOK_DEFINE(ACE_Map_Iterator)
- return *retv;
-}
+ACE_ALLOC_HOOK_DEFINE(ACE_Map_Reverse_Iterator)
-// Returns the reference to the map_manager that is being
-// iterated over.
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>&
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::map (void)
+template <class EXT_ID, class INT_ID> void
+ACE_Map_Entry<EXT_ID, INT_ID>::dump (void) const
{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::map");
- return *this->map_man_;
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("next_ = %d"), this->next_));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("prev_ = %d"), this->prev_));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator== (const ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator==");
- return (this->map_man_ == rhs.map_man_ && this->next_ == rhs.next_);
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("total_size_ = %d"), this->total_size_));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("\ncur_size_ = %d"), this->cur_size_));
+ this->allocator_->dump ();
+ this->lock_.dump ();
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!= (const ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
+template <class EXT_ID, class INT_ID, class ACE_LOCK> void
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump_i (void) const
{
- ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!=");
- return (this->next_ != rhs.next_ || this->map_man_ != rhs.map_man_);
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("next_ = %d"), this->next_));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-ACE_ALLOC_HOOK_DEFINE(ACE_Map_Iterator)
-
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
- ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump");
-
this->dump_i ();
}
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int tail)
- : ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm, (tail == 0 ? 1 : 0))
-{
- ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator");
- if (tail == 0 && this->map_man_->search_structure_ != 0)
- this->forward_i ();
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
-{
- ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance");
- return this->forward_i ();
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
-{
- ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)");
-
- this->forward_i ();
- return *this;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
-{
- ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)");
-
- ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
- this->forward_i ();
- return retv;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
-{
- ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)");
-
- this->reverse_i ();
- return *this;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
-ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
-{
- ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)");
-
- ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
- this->reverse_i ();
- return retv;
-}
-
-ACE_ALLOC_HOOK_DEFINE(ACE_Map_Reverse_Iterator)
-
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
- ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump");
-
this->dump_i ();
}
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Reverse_Iterator (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int head)
- : ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm, head)
-{
- ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Reverse_Iterator");
- if (head == 0 && this->map_man_->search_structure_ != 0)
- this->reverse_i ();
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK> int
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
-{
- ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance");
- return this->reverse_i ();
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
-{
- ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)");
-
- this->reverse_i ();
- return *this;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
-{
- ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)");
-
- ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
- this->reverse_i ();
- return retv;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
-{
- ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)");
-
- this->forward_i ();
- return *this;
-}
-
-template <class EXT_ID, class INT_ID, class ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
-ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
-{
- ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)");
-
- ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
- this->forward_i ();
- return retv;
-}
-
#endif /* ACE_MAP_MANAGER_C */
+
diff --git a/ace/Map_Manager.h b/ace/Map_Manager.h
index 4d305266dcf..cfc721e2d01 100644
--- a/ace/Map_Manager.h
+++ b/ace/Map_Manager.h
@@ -40,9 +40,6 @@ public:
INT_ID int_id_;
// The contents of the entry itself.
- int is_free_;
- // Keeps track whether entry is free or not.
-
# if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
~ACE_Map_Entry (void);
// We need this destructor to keep some compilers from complaining.
@@ -54,6 +51,25 @@ public:
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
+
+ //
+ // = These are really private, but unfortunately template friends
+ // don't work too well.
+ //
+
+ size_t next (void) const;
+ void next (size_t n);
+ // Get/Set next entry.
+
+ size_t prev (void) const;
+ void prev (size_t p);
+ // Get/Set prev entry.
+
+ size_t next_;
+ // Keeps track of the next entry.
+
+ size_t prev_;
+ // Keeps track of the previous entry.
};
// Forward decl.
@@ -122,15 +138,6 @@ public:
// Close down a <Map_Manager> and release dynamically allocated
// resources.
- int trybind (const EXT_ID &ext_id,
- INT_ID &int_id);
- // Associate <ext_id> with <int_id> if and only if <ext_id> is not
- // in the map. If <ext_id> is already in the map then the <int_id>
- // parameter is overwritten with the existing value in the map
- // Returns 0 if a new entry is bound successfully, returns 1 if an
- // attempt is made to bind an existing entry, and returns -1 if
- // failures occur.
-
int bind (const EXT_ID &ext_id,
const INT_ID &int_id);
// Associate <ext_id> with <int_id>. If <ext_id> is already in the
@@ -142,7 +149,7 @@ public:
const INT_ID &int_id,
EXT_ID &old_ext_id,
INT_ID &old_int_id);
- // Associate <ext_id> with <int_id>. If <ext_id> is not in the
+ // Reassociate <ext_id> with <int_id>. If <ext_id> is not in the
// map then behaves just like <bind>. Otherwise, store the old
// values of <ext_id> and <int_id> into the "out" parameters and
// rebind the new parameters. This is very useful if you need to
@@ -151,7 +158,22 @@ public:
// bound successfully, returns 1 if an existing entry was rebound,
// and returns -1 if failures occur.
- int find (const EXT_ID &ext_id, INT_ID &int_id);
+ int rebind (const EXT_ID &ext_id,
+ const INT_ID &int_id);
+ // Reassociate <ext_id> with <int_id>. Old values in the map are
+ // ignored.
+
+ int trybind (const EXT_ID &ext_id,
+ INT_ID &int_id);
+ // Associate <ext_id> with <int_id> if and only if <ext_id> is not
+ // in the map. If <ext_id> is already in the map then the <int_id>
+ // parameter is overwritten with the existing value in the map
+ // Returns 0 if a new entry is bound successfully, returns 1 if an
+ // attempt is made to bind an existing entry, and returns -1 if
+ // failures occur.
+
+ int find (const EXT_ID &ext_id,
+ INT_ID &int_id);
// Locate <ext_id> and pass out parameter via <int_id>. If found,
// returns and non-negative integer; returns -1 if not found.
@@ -164,7 +186,8 @@ public:
// <int_id>s are *not* dynamically allocated...) Returns 0 if
// successful, else -1.
- int unbind (const EXT_ID &ext_id, INT_ID &int_id);
+ int unbind (const EXT_ID &ext_id,
+ INT_ID &int_id);
// Break any association of <ext_id>. Returns the value of <int_id>
// in case the caller needs to deallocate memory. Returns 0 if
// successful, else -1.
@@ -201,36 +224,50 @@ public:
protected:
- void free_search_structure (void);
- // Explicitly call the destructors and free up the search_structure_.
-
- ACE_Map_Entry<EXT_ID, INT_ID> *search_structure_;
- // Implementation of the Map (should use hashing instead of
- // array...).
-
// = The following methods do the actual work.
// These methods assume that the locks are held by the private
// methods.
- int bind_i (const EXT_ID &ext_id, const INT_ID &int_id);
- // Performs the binding of <ext_id> to <int_id>. Must be
- // called with locks held.
+ int bind_i (const EXT_ID &ext_id,
+ const INT_ID &int_id);
+ // Performs the binding of <ext_id> to <int_id>. Must be called
+ // with locks held.
+
+ int shared_bind (const EXT_ID &ext_id,
+ const INT_ID &int_id);
+ // Bind an entry (without finding first). Must be called with locks
+ // held.
- int rebind_i (const EXT_ID &ext_id, const INT_ID &int_id,
- EXT_ID &old_ext_id, INT_ID &old_int_id);
+ int rebind_i (const EXT_ID &ext_id,
+ const INT_ID &int_id,
+ EXT_ID &old_ext_id,
+ INT_ID &old_int_id);
+ // Performs a rebinding of <ext_it> to <int_id>. Also, recovers old
+ // values. Must be called with locks held.
+
+ int rebind_i (const EXT_ID &ext_id,
+ const INT_ID &int_id);
// Performs a rebinding of <ext_it> to <int_id>. Must be called
// with locks held.
- int find_i (const EXT_ID &ext_id, INT_ID &int_id);
+ int trybind_i (const EXT_ID &ext_id,
+ INT_ID &int_id);
+ // Performs a conditional bind of <int_id> using <ext_id> as the
+ // key. Must be called with locks held.
+
+ int find_i (const EXT_ID &ext_id,
+ INT_ID &int_id);
// Performs a find of <int_id> using <ext_id> as the key. Must be
// called with locks held.
- int find_i (const EXT_ID &ext_id);
+ int find_i (const EXT_ID &ext_id,
+ size_t &index);
// Performs a find using <ext_id> as the key. Must be called with
// locks held.
- int unbind_i (const EXT_ID &ext_id, INT_ID &int_id);
+ int unbind_i (const EXT_ID &ext_id,
+ INT_ID &int_id);
// Performs an unbind of <int_id> using <ext_id> as the key. Must
// be called with locks held.
@@ -238,49 +275,83 @@ protected:
// Performs an unbind using <ext_id> as the key. Must be called
// with locks held.
- int trybind_i (const EXT_ID &ext_id, INT_ID &int_id);
- // Performs a conditional bind of <int_id> using <ext_id> as the
- // key. Must be called with locks held.
+ int unbind_i (const EXT_ID &ext_id,
+ size_t &index);
+ // Performs an unbind using <ext_id> as the key. Must be called
+ // with locks held.
int resize_i (size_t size);
// Resize the map. Must be called with locks held.
int close_i (void);
- // Close down a <Map_Manager>. Must be called with
- // locks held.
-
- ACE_Allocator *allocator_;
- // Pointer to a memory allocator.
-
- ACE_LOCK lock_;
- // Synchronization variable for the MT_SAFE <ACE_Map_Manager>.
+ // Close down a <Map_Manager>. Must be called with locks held.
int equal (const EXT_ID &id1, const EXT_ID &id2);
// Returns 1 if <id1> == <id2>, else 0. This is defined as a
// separate method to facilitate template specialization.
-private:
+ virtual size_t new_size (void);
+ // This function returns the new size of the Map Manager. This
+ // function is called when we run out of room and need to resize.
- int shared_find (const EXT_ID &ext_id, int &first_free);
- // Locate an entry, keeping track of the first free slot. Must be
- // called with locks held.
+ void free_search_structure (void);
+ // Explicitly call the destructors and free up the
+ // <search_structure_>.
+
+ size_t free_list_id (void) const;
+ // Id of the free list sentinel.
- int shared_find (const EXT_ID &ext_id);
- // Locate an entry. Must be called with locks held.
+ size_t occupied_list_id (void) const;
+ // Id of the occupied list sentinel.
- int shared_bind (const EXT_ID &ext_id, const INT_ID &int_id, int first_free);
- // Bind an entry. Must be called with locks held.
+ int next_free (size_t &index);
+ // Finds the next free slot.
- int shared_unbind (const EXT_ID &ext_id);
- // Unbind (remove) the <ext_id> from the map. Keeps track of where
- // the <ext_id> was found so that this->unbind (<ext_id>, <int_id>)
- // can return it to the caller. Must be called with locks held.
+ void move_from_free_list_to_occupied_list (size_t index);
+ // Move from free list to occupied list.
+
+ void move_from_occupied_list_to_free_list (size_t index);
+ // Move from occupied list to free list.
+
+ void shared_move (size_t index,
+ ACE_Map_Entry<EXT_ID, INT_ID> &current_list,
+ size_t current_list_id,
+ ACE_Map_Entry<EXT_ID, INT_ID> &new_list,
+ size_t new_list_id);
+ // Move helper.
+
+ ACE_Allocator *allocator_;
+ // Pointer to a memory allocator.
+
+ ACE_LOCK lock_;
+ // Synchronization variable for the MT_SAFE <ACE_Map_Manager>.
+
+ ACE_Map_Entry<EXT_ID, INT_ID> *search_structure_;
+ // Implementation of the Map (should use hashing instead of
+ // array...).
size_t total_size_;
// Total number of elements in this->search_structure_.
size_t cur_size_;
- // Index of highest active elementin this->search_structure_.
+ // Current size of the map.
+
+ ACE_Map_Entry<EXT_ID, INT_ID> free_list_;
+ // Free list.
+
+ ACE_Map_Entry<EXT_ID, INT_ID> occupied_list_;
+ // Occupied list.
+
+ enum
+ {
+ // Grow map exponentially up to 64K
+ MAX_EXPONENTIAL = 64 * 1024,
+
+ // Afterwards grow in chunks of 32K
+ LINEAR_INCREASE = 32 * 1024
+ };
+
+private:
// = Disallow these operations.
ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &))
@@ -298,8 +369,7 @@ class ACE_Map_Iterator_Base
// subclasses.
public:
// = Initialization method.
- ACE_Map_Iterator_Base (ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm,
- int head);
+ ACE_Map_Iterator_Base (ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm);
// Contructor. If head != 0, the iterator constructed is positioned
// at the head of the map, it is positioned at the end otherwise.
@@ -338,10 +408,10 @@ protected:
void dump_i (void) const;
// Dump the state of an object.
- ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> *map_man_;
+ ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &map_man_;
// Map we are iterating over.
- ssize_t next_;
+ size_t next_;
// Keeps track of how far we've advanced...
};
@@ -361,7 +431,7 @@ class ACE_Map_Iterator : public ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>
public:
// = Initialization method.
ACE_Map_Iterator (ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm,
- int tail = 0);
+ int pass_end = 0);
// = Iteration methods.
@@ -406,7 +476,7 @@ class ACE_Map_Reverse_Iterator : public ACE_Map_Iterator_Base<EXT_ID, INT_ID, AC
public:
// = Initialization method.
ACE_Map_Reverse_Iterator (ACE_Map_Manager <EXT_ID, INT_ID, ACE_LOCK> &mm,
- int head = 0);
+ int pass_end = 0);
// = Iteration methods.
diff --git a/ace/Map_Manager.i b/ace/Map_Manager.i
index 7e1703cd066..b905a1c5538 100644
--- a/ace/Map_Manager.i
+++ b/ace/Map_Manager.i
@@ -1,4 +1,431 @@
/* -*- C++ -*- */
// $Id$
-// Map_Manager.i
+# if ! defined (ACE_HAS_BROKEN_NOOP_DTORS)
+template <class EXT_ID, class INT_ID> ACE_INLINE
+ACE_Map_Entry<EXT_ID, INT_ID>::~ACE_Map_Entry (void)
+{
+ // No-op just to keep some compilers happy...
+}
+#endif /* ! defined (ACE_HAS_BROKEN_NOOP_DTORS) */
+
+template <class EXT_ID, class INT_ID> ACE_INLINE size_t
+ACE_Map_Entry<EXT_ID, INT_ID>::next (void) const
+{
+ return this->next_;
+}
+
+template <class EXT_ID, class INT_ID> ACE_INLINE void
+ACE_Map_Entry<EXT_ID, INT_ID>::next (size_t n)
+{
+ this->next_ = n;
+}
+
+template <class EXT_ID, class INT_ID> ACE_INLINE size_t
+ACE_Map_Entry<EXT_ID, INT_ID>::prev (void) const
+{
+ return this->prev_;
+}
+
+template <class EXT_ID, class INT_ID> ACE_INLINE void
+ACE_Map_Entry<EXT_ID, INT_ID>::prev (size_t p)
+{
+ this->prev_ = p;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager (size_t size,
+ ACE_Allocator *alloc)
+ : search_structure_ (0),
+ allocator_ (0),
+ total_size_ (0),
+ cur_size_ (0)
+{
+ if (this->open (size, alloc) == -1)
+ ACE_ERROR ((LM_ERROR, ASYS_TEXT ("ACE_Map_Manager\n")));
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager (ACE_Allocator *alloc)
+ : search_structure_ (0),
+ allocator_ (0),
+ total_size_ (0),
+ cur_size_ (0)
+{
+ if (this->open (ACE_DEFAULT_MAP_SIZE, alloc) == -1)
+ ACE_ERROR ((LM_ERROR, ASYS_TEXT ("ACE_Map_Manager\n")));
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close (void)
+{
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+
+ return this->close_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::~ACE_Map_Manager (void)
+{
+ this->close ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind (const EXT_ID &ext_id,
+ const INT_ID &int_id)
+{
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+
+ return this->bind_i (ext_id,
+ int_id);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind (const EXT_ID &ext_id,
+ const INT_ID &int_id,
+ EXT_ID &old_ext_id,
+ INT_ID &old_int_id)
+{
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+
+ return this->rebind_i (ext_id,
+ int_id,
+ old_ext_id,
+ old_int_id);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind (const EXT_ID &ext_id,
+ INT_ID &int_id)
+{
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+
+ return this->trybind_i (ext_id,
+ int_id);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find (const EXT_ID &ext_id)
+{
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+
+ size_t index = 0;
+ return this->find_i (ext_id,
+ index);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find (const EXT_ID &ext_id,
+ INT_ID &int_id)
+{
+ ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+
+ return this->find_i (ext_id,
+ int_id);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i (const EXT_ID &ext_id)
+{
+ // Unbind the entry.
+ size_t index = 0;
+ return this->unbind_i (ext_id,
+ index);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind (const EXT_ID &ext_id,
+ INT_ID &int_id)
+{
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+
+ return this->unbind_i (ext_id,
+ int_id);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind (const EXT_ID &ext_id)
+{
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
+ return this->unbind_i (ext_id);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE size_t
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::current_size (void)
+{
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_,
+ ACE_static_cast(size_t, -1));
+ return this->cur_size_;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE size_t
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::total_size (void)
+{
+ ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_,
+ ACE_static_cast (size_t, -1));
+ return this->total_size_;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE ACE_LOCK &
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::mutex (void)
+{
+ return this->lock_;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE void
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::move_from_free_list_to_occupied_list (size_t index)
+{
+ this->shared_move (index,
+ this->free_list_,
+ this->free_list_id (),
+ this->occupied_list_,
+ this->occupied_list_id ());
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE void
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::move_from_occupied_list_to_free_list (size_t index)
+{
+ this->shared_move (index,
+ this->occupied_list_,
+ this->occupied_list_id (),
+ this->free_list_,
+ this->free_list_id ());
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::equal (const EXT_ID &id1,
+ const EXT_ID &id2)
+{
+ return id1 == id2;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE size_t
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::free_list_id (void) const
+{
+ // If you change ~0, please change
+ // ACE_Active_Map_Manager_Key::ACE_Active_Map_Manager_Key()
+ // accordingly.
+ return ~0;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE size_t
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::occupied_list_id (void) const
+{
+ return ~1;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::begin (void)
+{
+ return ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::end (void)
+{
+ return ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rbegin (void)
+{
+ return ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rend (void)
+{
+ return ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator_Base (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm)
+ : map_man_ (mm),
+ next_ (this->map_man_.occupied_list_id ())
+{
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Map_Entry<EXT_ID, INT_ID> *&mm)
+{
+ if (this->next_ != this->map_man_.occupied_list_id ())
+ {
+ mm = &this->map_man_.search_structure_[this->next_];
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
+{
+ return this->next_ == this->map_man_.occupied_list_id ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::forward_i (void)
+{
+ if (this->next_ == this->map_man_.occupied_list_id ())
+ {
+ this->next_ = this->map_man_.occupied_list_.next ();
+ }
+ else
+ {
+ this->next_ = this->map_man_.search_structure_[this->next_].next ();
+ }
+
+ return this->next_ != this->map_man_.occupied_list_id ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::reverse_i (void)
+{
+ if (this->next_ == this->map_man_.occupied_list_id ())
+ {
+ this->next_ = this->map_man_.occupied_list_.prev ();
+ }
+ else
+ {
+ this->next_ = this->map_man_.search_structure_[this->next_].prev ();
+ }
+
+ return this->next_ != this->map_man_.occupied_list_id ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Entry<EXT_ID, INT_ID>&
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator* (void)
+{
+ ACE_Map_Entry<EXT_ID, INT_ID> *retv = 0;
+
+ int result = this->next (retv);
+ ACE_ASSERT (result != 0);
+ ACE_UNUSED_ARG (result);
+
+ return *retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>&
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::map (void)
+{
+ return this->map_man_;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator== (const ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
+{
+ return (&this->map_man_ == &rhs.map_man_ &&
+ this->next_ == rhs.next_);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!= (const ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
+{
+ return !this->operator== (rhs);
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
+ int pass_end)
+ : ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm)
+{
+ if (!pass_end)
+ this->forward_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
+{
+ return this->forward_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
+{
+ this->forward_i ();
+ return *this;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
+{
+ ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
+ this->forward_i ();
+ return retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
+{
+ this->reverse_i ();
+ return *this;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
+{
+ ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
+ this->reverse_i ();
+ return retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Reverse_Iterator (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm,
+ int pass_end)
+ : ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm)
+{
+ if (!pass_end)
+ this->reverse_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE int
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
+{
+ return this->reverse_i ();
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
+{
+ this->reverse_i ();
+ return *this;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
+{
+ ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
+ this->reverse_i ();
+ return retv;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> &
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
+{
+ this->forward_i ();
+ return *this;
+}
+
+template <class EXT_ID, class INT_ID, class ACE_LOCK> ACE_INLINE
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
+ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
+{
+ ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
+ this->forward_i ();
+ return retv;
+}
diff --git a/ace/ace_dll.dsp b/ace/ace_dll.dsp
index d5a2451317d..b3de4b843d8 100644
--- a/ace/ace_dll.dsp
+++ b/ace/ace_dll.dsp
@@ -183,9 +183,9 @@ MTL=midl.exe
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /o /win32 "NUL"
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /o /win32 "NUL"
CPP=cl.exe
-# ADD BASE CPP /nologo /MTd /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D ACE_HAS_DLL=1 /FD /c
+# ADD BASE CPP /nologo /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D ACE_HAS_DLL=1 /FD /MTd /c
# SUBTRACT BASE CPP /YX /Yc /Yu
-# ADD CPP /nologo /MDd /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D ACE_HAS_DLL=1 /FD /c
+# ADD CPP /nologo /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D ACE_HAS_DLL=1 /FD /MDd /c
# SUBTRACT CPP /YX /Yc /Yu
RSC=rc.exe
# ADD BASE RSC /l 0x409 /d "_DEBUG"
@@ -251,9 +251,9 @@ MTL=midl.exe
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /o /win32 "NUL"
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /o /win32 "NUL"
CPP=cl.exe
-# ADD BASE CPP /nologo /MTd /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D ACE_HAS_DLL=1 /D "UNICODE" /FD /c
+# ADD BASE CPP /nologo /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D ACE_HAS_DLL=1 /D "UNICODE" /FD /MTd /c
# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MTd /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D ACE_HAS_DLL=1 /D "UNICODE" /FD /c
+# ADD CPP /nologo /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D ACE_HAS_DLL=1 /D "UNICODE" /FD /MTd /c
# SUBTRACT CPP /YX
RSC=rc.exe
# ADD BASE RSC /l 0x409 /d "_DEBUG"
@@ -698,6 +698,29 @@ DEP_CPP_ACTIV=\
# End Source File
# Begin Source File
+SOURCE=.\Active_Map_Manager.cpp
+
+!IF "$(CFG)" == "ACE dynamic library - Win32 Debug"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Release"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Unicode Debug"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Unicode Release"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Alpha Debug"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Alpha Release"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Alpha Unicode Debug"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Alpha Unicode Release"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
SOURCE=.\Addr.cpp
!IF "$(CFG)" == "ACE dynamic library - Win32 Debug"
@@ -25450,6 +25473,14 @@ SOURCE=.\Activation_Queue.h
# End Source File
# Begin Source File
+SOURCE=.\Active_Map_Manager.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Active_Map_Manager_T.h
+# End Source File
+# Begin Source File
+
SOURCE=.\Addr.h
# End Source File
# Begin Source File
@@ -26230,6 +26261,14 @@ SOURCE=.\Activation_Queue.i
# End Source File
# Begin Source File
+SOURCE=.\Active_Map_Manager.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\Active_Map_Manager_T.i
+# End Source File
+# Begin Source File
+
SOURCE=.\Addr.i
# End Source File
# Begin Source File
@@ -26837,6 +26876,31 @@ SOURCE=.\Acceptor.cpp
# End Source File
# Begin Source File
+SOURCE=.\Active_Map_Manager_T.cpp
+
+!IF "$(CFG)" == "ACE dynamic library - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Release"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Unicode Debug"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Unicode Release"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Alpha Debug"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Alpha Release"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Alpha Unicode Debug"
+
+!ELSEIF "$(CFG)" == "ACE dynamic library - Win32 Alpha Unicode Release"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
SOURCE=.\Asynch_Acceptor.cpp
!IF "$(CFG)" == "ACE dynamic library - Win32 Debug"
diff --git a/ace/ace_lib.dsp b/ace/ace_lib.dsp
index c812accae74..e3d8617abda 100644
--- a/ace/ace_lib.dsp
+++ b/ace/ace_lib.dsp
@@ -152,7 +152,7 @@ LIB32=link.exe -lib
CPP=cl.exe
# ADD BASE CPP /nologo /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MTd /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /MTd /c
# SUBTRACT CPP /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo /o".\ace.bsc"
@@ -200,7 +200,7 @@ LIB32=link.exe -lib
CPP=cl.exe
# ADD BASE CPP /nologo /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "UNICODE" /FD /c
# SUBTRACT BASE CPP /YX
-# ADD CPP /nologo /MTd /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "UNICODE" /FD /c
+# ADD CPP /nologo /Gt0 /W3 /GX /Zi /Od /Gy /I "..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "UNICODE" /FD /MTd /c
# SUBTRACT CPP /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo /o".\ace.bsc"
@@ -463,6 +463,29 @@ DEP_CPP_ACTIV=\
# End Source File
# Begin Source File
+SOURCE=.\Active_Map_Manager.cpp
+
+!IF "$(CFG)" == "ACE static library - Win32 Debug"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Release"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Unicode Debug"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Unicode Release"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Alpha Debug"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Alpha Release"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Alpha Unicode Debug"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Alpha Unicode Release"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
SOURCE=.\Addr.cpp
!IF "$(CFG)" == "ACE static library - Win32 Debug"
@@ -14426,6 +14449,14 @@ SOURCE=.\Activation_Queue.h
# End Source File
# Begin Source File
+SOURCE=.\Active_Map_Manager.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\Active_Map_Manager_T.h
+# End Source File
+# Begin Source File
+
SOURCE=.\Addr.h
# End Source File
# Begin Source File
@@ -15134,6 +15165,14 @@ SOURCE=.\ACE.i
# End Source File
# Begin Source File
+SOURCE=.\Active_Map_Manager.i
+# End Source File
+# Begin Source File
+
+SOURCE=.\Active_Map_Manager_T.i
+# End Source File
+# Begin Source File
+
SOURCE=.\Addr.i
# End Source File
# Begin Source File
@@ -15689,6 +15728,31 @@ SOURCE=.\Acceptor.cpp
# End Source File
# Begin Source File
+SOURCE=.\Active_Map_Manager_T.cpp
+
+!IF "$(CFG)" == "ACE static library - Win32 Debug"
+
+# PROP Exclude_From_Build 1
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Release"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Unicode Debug"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Unicode Release"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Alpha Debug"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Alpha Release"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Alpha Unicode Debug"
+
+!ELSEIF "$(CFG)" == "ACE static library - Win32 Alpha Unicode Release"
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
SOURCE=.\Asynch_Acceptor.cpp
!IF "$(CFG)" == "ACE static library - Win32 Debug"
diff --git a/tests/Map_Manager_Test.cpp b/tests/Map_Manager_Test.cpp
index eaa66c9561c..3e625647cba 100644
--- a/tests/Map_Manager_Test.cpp
+++ b/tests/Map_Manager_Test.cpp
@@ -21,6 +21,7 @@
#include "test_config.h"
#include "ace/Map_Manager.h"
#include "ace/Hash_Map_Manager.h"
+#include "ace/Active_Map_Manager.h"
#include "ace/Profile_Timer.h"
#include "ace/Synch.h"
@@ -33,6 +34,7 @@ USELIB("..\ace\aced.lib");
typedef ACE_Null_Mutex MUTEX;
typedef unsigned long TYPE;
+typedef ACE_Active_Map_Manager_Key ACTIVE_KEY;
typedef ACE_Hash<TYPE> HASH_KEY;
typedef ACE_Equal_To<TYPE> COMPARE_KEYS;
@@ -44,190 +46,282 @@ typedef ACE_Hash_Map_Manager_Ex <TYPE, TYPE, HASH_KEY, COMPARE_KEYS, MUTEX> HASH
typedef ACE_Hash_Map_Iterator_Ex <TYPE, TYPE, HASH_KEY, COMPARE_KEYS, MUTEX> HASH_ITERATOR;
typedef ACE_Hash_Map_Reverse_Iterator_Ex <TYPE, TYPE, HASH_KEY, COMPARE_KEYS, MUTEX> HASH_REVERSE_ITERATOR;
typedef ACE_Hash_Map_Entry <TYPE, TYPE> HASH_ENTRY;
+typedef ACE_Active_Map_Manager <TYPE> ACTIVE_MAP_MANAGER;
static void
-test_hash_map_manager (size_t table_size, size_t iterations)
+test_active_map_manager (size_t table_size,
+ size_t iterations,
+ int test_iterators)
{
- HASH_MAP_MANAGER map (table_size);
+ ACTIVE_MAP_MANAGER map (table_size);
TYPE i;
TYPE j;
ssize_t k;
- for (i = 0; i < iterations; i++)
- ACE_ASSERT (map.bind (i, i) != -1);
+ ACTIVE_MAP_MANAGER::key_type *active_keys
+ = new ACTIVE_MAP_MANAGER::key_type[iterations];
- {
- i = 0;
-
- HASH_ITERATOR end = map.end ();
+ for (i = 0; i < iterations; i++)
+ ACE_ASSERT (map.bind (i, active_keys[i]) != -1);
- for (HASH_ITERATOR iter = map.begin ();
- iter != end;
- ++iter)
+ if (test_iterators)
+ {
{
- HASH_ENTRY &entry = *iter;
+ i = 0;
+
+ ACTIVE_MAP_MANAGER::iterator end = map.end ();
+ for (ACTIVE_MAP_MANAGER::iterator iter = map.begin ();
+ iter != end;
+ ++iter)
+ {
+ ACTIVE_MAP_MANAGER::ENTRY &entry = *iter;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d-%d|%d)"),
+ i,
+ entry.ext_id_.index (),
+ entry.ext_id_.generation (),
+ entry.int_id_));
+ ++i;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- i,
- entry.ext_id_,
- entry.int_id_));
- ++i;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (i == iterations);
- }
-
- {
- HASH_ENTRY *entry = 0;
-
- i = 0;
-
- for (HASH_ITERATOR iterator (map);
- iterator.next (entry) != 0;
- iterator.advance ())
{
+ k = iterations - 1;
+
+ ACTIVE_MAP_MANAGER::reverse_iterator rend = map.rend ();
+
+ for (ACTIVE_MAP_MANAGER::reverse_iterator iter = map.rbegin ();
+ iter != rend;
+ ++iter)
+ {
+ ACTIVE_MAP_MANAGER::ENTRY &entry = *iter;
+ ACE_UNUSED_ARG (entry);
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d-%d|%d)"),
+ k,
+ entry.ext_id_.index (),
+ entry.ext_id_.generation (),
+ entry.int_id_));
+ k--;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- i,
- entry->ext_id_,
- entry->int_id_));
- ++i;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
+ }
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (i == iterations);
- }
+ for (i = 0; i < iterations; ++i)
+ {
+ ACE_ASSERT (map.find (active_keys[i], j) != -1);
+ ACE_ASSERT (i == j);
+ }
- {
- k = iterations - 1;
+ size_t remaining_entries = iterations;
+ for (i = 0; i < iterations; ++i)
+ {
+ ACE_ASSERT (map.unbind (active_keys[i]) != -1);
+ --remaining_entries;
+ ACE_ASSERT (map.current_size () == remaining_entries);
+ }
- HASH_REVERSE_ITERATOR rend = map.rend ();
+ delete[] active_keys;
+}
- for (HASH_REVERSE_ITERATOR iter = map.rbegin ();
- iter != rend;
- ++iter)
+static void
+test_hash_map_manager (size_t table_size,
+ size_t iterations,
+ int test_iterators)
+{
+ HASH_MAP_MANAGER map (table_size);
+ TYPE i;
+ TYPE j;
+ ssize_t k;
+
+ for (i = 0; i < iterations; i++)
+ ACE_ASSERT (map.bind (i, i) != -1);
+
+ if (test_iterators)
+ {
{
- HASH_ENTRY &entry = *iter;
+ i = 0;
+
+ HASH_ITERATOR end = map.end ();
+
+ for (HASH_ITERATOR iter = map.begin ();
+ iter != end;
+ ++iter)
+ {
+ HASH_ENTRY &entry = *iter;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ i,
+ entry.ext_id_,
+ entry.int_id_));
+ ++i;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- k,
- entry.ext_id_,
- entry.int_id_));
- k--;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (k == -1);
- }
+ {
+ HASH_ENTRY *entry = 0;
+
+ i = 0;
+
+ for (HASH_ITERATOR iterator (map);
+ iterator.next (entry) != 0;
+ iterator.advance ())
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ i,
+ entry->ext_id_,
+ entry->int_id_));
+ ++i;
+ }
- {
- HASH_ENTRY *entry = 0;
- k = iterations - 1;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
+ }
- for (HASH_REVERSE_ITERATOR iterator (map);
- iterator.next (entry) != 0;
- iterator.advance ())
{
+ k = iterations - 1;
+
+ HASH_REVERSE_ITERATOR rend = map.rend ();
+
+ for (HASH_REVERSE_ITERATOR iter = map.rbegin ();
+ iter != rend;
+ ++iter)
+ {
+ HASH_ENTRY &entry = *iter;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ k,
+ entry.ext_id_,
+ entry.int_id_));
+ k--;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- k,
- entry->ext_id_,
- entry->int_id_));
- k--;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (k == -1);
- }
-
- {
- i = 0;
-
- HASH_MAP_MANAGER::iterator end = map.end ();
- for (HASH_MAP_MANAGER::iterator iter = map.begin ();
- iter != end;
- ++iter)
+
{
- HASH_MAP_MANAGER::ENTRY &entry = *iter;
+ HASH_ENTRY *entry = 0;
+ k = iterations - 1;
+
+ for (HASH_REVERSE_ITERATOR iterator (map);
+ iterator.next (entry) != 0;
+ iterator.advance ())
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ k,
+ entry->ext_id_,
+ entry->int_id_));
+ k--;
+ }
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- i,
- entry.ext_id_,
- entry.int_id_));
- ++i;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (i == iterations);
- }
- {
- i = 0;
- HASH_MAP_MANAGER::ENTRY *entry = 0;
-
- for (HASH_MAP_MANAGER::ITERATOR iterator (map);
- iterator.next (entry) != 0;
- iterator.advance ())
{
+ i = 0;
+
+ HASH_MAP_MANAGER::iterator end = map.end ();
+ for (HASH_MAP_MANAGER::iterator iter = map.begin ();
+ iter != end;
+ ++iter)
+ {
+ HASH_MAP_MANAGER::ENTRY &entry = *iter;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ i,
+ entry.ext_id_,
+ entry.int_id_));
+ ++i;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- i,
- entry->ext_id_,
- entry->int_id_));
- ++i;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (i == iterations);
- }
-
- {
- k = iterations - 1;
+ {
+ i = 0;
+ HASH_MAP_MANAGER::ENTRY *entry = 0;
+
+ for (HASH_MAP_MANAGER::ITERATOR iterator (map);
+ iterator.next (entry) != 0;
+ iterator.advance ())
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ i,
+ entry->ext_id_,
+ entry->int_id_));
+ ++i;
+ }
- HASH_MAP_MANAGER::reverse_iterator rend = map.rend ();
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
+ }
- for (HASH_MAP_MANAGER::reverse_iterator iter = map.rbegin ();
- iter != rend;
- ++iter)
{
- HASH_MAP_MANAGER::ENTRY &entry = *iter;
- ACE_UNUSED_ARG (entry);
+ k = iterations - 1;
+
+ HASH_MAP_MANAGER::reverse_iterator rend = map.rend ();
+
+ for (HASH_MAP_MANAGER::reverse_iterator iter = map.rbegin ();
+ iter != rend;
+ ++iter)
+ {
+ HASH_MAP_MANAGER::ENTRY &entry = *iter;
+ ACE_UNUSED_ARG (entry);
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ k,
+ entry.ext_id_,
+ entry.int_id_));
+ k--;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- k,
- entry.ext_id_,
- entry.int_id_));
- k--;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (k == -1);
- }
- {
- k = iterations - 1;
- HASH_MAP_MANAGER::ENTRY *entry = 0;
- for (HASH_MAP_MANAGER::REVERSE_ITERATOR iterator (map);
- iterator.next (entry) != 0;
- iterator.advance ())
{
+ k = iterations - 1;
+ HASH_MAP_MANAGER::ENTRY *entry = 0;
+ for (HASH_MAP_MANAGER::REVERSE_ITERATOR iterator (map);
+ iterator.next (entry) != 0;
+ iterator.advance ())
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ k,
+ entry->ext_id_,
+ entry->int_id_));
+ k--;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- k,
- entry->ext_id_,
- entry->int_id_));
- k--;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
-
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (k == -1);
- }
+ }
for (i = 0; i < iterations; ++i)
{
@@ -235,14 +329,19 @@ test_hash_map_manager (size_t table_size, size_t iterations)
ACE_ASSERT (i == j);
}
+ size_t remaining_entries = iterations;
for (i = 0; i < iterations; ++i)
- ACE_ASSERT (map.unbind (i) != -1);
-
- ACE_ASSERT (map.current_size () == 0);
+ {
+ ACE_ASSERT (map.unbind (i) != -1);
+ --remaining_entries;
+ ACE_ASSERT (map.current_size () == remaining_entries);
+ }
}
static void
-test_map_manager (size_t table_size, size_t iterations)
+test_map_manager (size_t table_size,
+ size_t iterations,
+ int test_iterators)
{
MAP_MANAGER map (table_size);
TYPE i;
@@ -252,166 +351,173 @@ test_map_manager (size_t table_size, size_t iterations)
for (i = 0; i < iterations; ++i)
ACE_ASSERT (map.bind (i, i) != -1);
- {
- i = 0;
-
- ITERATOR end = map.end ();
- for (ITERATOR iter = map.begin ();
- iter != end;
- ++iter)
+ if (test_iterators)
+ {
{
- ENTRY &entry = *iter;
+ i = 0;
+
+ ITERATOR end = map.end ();
+ for (ITERATOR iter = map.begin ();
+ iter != end;
+ ++iter)
+ {
+ ENTRY &entry = *iter;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ i,
+ entry.ext_id_,
+ entry.int_id_));
+ ++i;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- i,
- entry.ext_id_,
- entry.int_id_));
- ++i;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (i == iterations);
- }
- {
- i = 0;
- ENTRY *entry = 0;
- for (ITERATOR iterator (map);
- iterator.next (entry) != 0;
- iterator.advance ())
{
+ i = 0;
+ ENTRY *entry = 0;
+ for (ITERATOR iterator (map);
+ iterator.next (entry) != 0;
+ iterator.advance ())
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ i,
+ entry->ext_id_,
+ entry->int_id_));
+ ++i;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- i,
- entry->ext_id_,
- entry->int_id_));
- ++i;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (i == iterations);
- }
-
- {
- ENTRY entry;
- k = iterations - 1;
- REVERSE_ITERATOR rend = map.rend ();
-
- for (REVERSE_ITERATOR iter = map.rbegin ();
- iter != rend;
- ++iter)
{
- entry = *iter;
+ ENTRY entry;
+ k = iterations - 1;
+ REVERSE_ITERATOR rend = map.rend ();
+
+ for (REVERSE_ITERATOR iter = map.rbegin ();
+ iter != rend;
+ ++iter)
+ {
+ entry = *iter;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("%u "),
+ entry.int_id_));
+ k--;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("%u "),
- entry.int_id_));
- k--;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (k == -1);
- }
- {
-
- k = iterations - 1;
- ENTRY *entry = 0;
-
- for (REVERSE_ITERATOR iterator (map);
- iterator.next (entry) != 0;
- iterator.advance ())
{
+ k = iterations - 1;
+ ENTRY *entry = 0;
+
+ for (REVERSE_ITERATOR iterator (map);
+ iterator.next (entry) != 0;
+ iterator.advance ())
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ k,
+ entry->ext_id_,
+ entry->int_id_));
+ k--;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- k,
- entry->ext_id_,
- entry->int_id_));
- k--;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (k == -1);
- }
- {
- MAP_MANAGER::ENTRY entry;
- i = 0;
- MAP_MANAGER::iterator end = map.end ();
- for (MAP_MANAGER::iterator iter = map.begin ();
- iter != end;
- ++iter)
{
- entry = *iter;
+ MAP_MANAGER::ENTRY entry;
+ i = 0;
+ MAP_MANAGER::iterator end = map.end ();
+ for (MAP_MANAGER::iterator iter = map.begin ();
+ iter != end;
+ ++iter)
+ {
+ entry = *iter;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("%u "),
+ entry.int_id_));
+ ++i;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("%u "),
- entry.int_id_));
- ++i;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (i == iterations);
- }
- {
- MAP_MANAGER::ENTRY *entry = 0;
- i = 0;
-
- for (MAP_MANAGER::ITERATOR iterator (map);
- iterator.next (entry) != 0;
- iterator.advance ())
{
+ MAP_MANAGER::ENTRY *entry = 0;
+ i = 0;
+
+ for (MAP_MANAGER::ITERATOR iterator (map);
+ iterator.next (entry) != 0;
+ iterator.advance ())
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ i,
+ entry->ext_id_,
+ entry->int_id_));
+ ++i;
+ }
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- i,
- entry->ext_id_,
- entry->int_id_));
- ++i;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (i == iterations);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (i == iterations);
- }
- {
- ENTRY entry;
- k = iterations - 1;
-
- MAP_MANAGER::reverse_iterator rend = map.rend ();
-
- for (MAP_MANAGER::reverse_iterator iter = map.rbegin ();
- iter != rend;
- ++iter)
+
{
- entry = *iter;
+ ENTRY entry;
+ k = iterations - 1;
+
+ MAP_MANAGER::reverse_iterator rend = map.rend ();
+
+ for (MAP_MANAGER::reverse_iterator iter = map.rbegin ();
+ iter != rend;
+ ++iter)
+ {
+ entry = *iter;
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("%u "),
+ entry.int_id_));
+ k--;
+ }
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("%u "),
- entry.int_id_));
- k--;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (k == -1);
- }
-
- {
- MAP_MANAGER::ENTRY *entry = 0;
- k = iterations - 1;
- for (MAP_MANAGER::REVERSE_ITERATOR iterator (map);
- iterator.next (entry) != 0;
- iterator.advance ())
{
+ MAP_MANAGER::ENTRY *entry = 0;
+ k = iterations - 1;
+ for (MAP_MANAGER::REVERSE_ITERATOR iterator (map);
+ iterator.next (entry) != 0;
+ iterator.advance ())
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ASYS_TEXT ("(%d|%d|%d)"),
+ k,
+ entry->ext_id_,
+ entry->int_id_));
+ k--;
+ }
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("(%d|%d|%d)"),
- k,
- entry->ext_id_,
- entry->int_id_));
- k--;
+ ASYS_TEXT ("\n")));
+ ACE_ASSERT (k == -1);
}
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("\n")));
- ACE_ASSERT (k == -1);
- }
+ }
for (i = 0; i < iterations; ++i)
{
@@ -419,22 +525,26 @@ test_map_manager (size_t table_size, size_t iterations)
ACE_ASSERT (i == j);
}
+ size_t remaining_entries = iterations;
for (i = 0; i < iterations; ++i)
- ACE_ASSERT (map.unbind (i) != -1);
-
- ACE_ASSERT (map.current_size () == 0);
+ {
+ ACE_ASSERT (map.unbind (i) != -1);
+ --remaining_entries;
+ ACE_ASSERT (map.current_size () == remaining_entries);
+ }
}
static void
-run_test (void (*ptf) (size_t, size_t),
+run_test (void (*ptf) (size_t, size_t, int),
size_t table_size,
size_t iterations,
+ int test_iterators,
const ASYS_TCHAR *test_name)
{
ACE_Profile_Timer timer;
timer.start ();
- (*ptf) (table_size, iterations);
+ (*ptf) (table_size, iterations, test_iterators);
timer.stop ();
@@ -442,11 +552,18 @@ run_test (void (*ptf) (size_t, size_t),
timer.elapsed_time (et);
+ ASYS_TCHAR *test_iterators_string = 0;
+ if (test_iterators)
+ test_iterators_string = ASYS_TEXT ("includes executing iterators");
+ else
+ test_iterators_string = ASYS_TEXT ("doesn't include executing iterators");
+
ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("time to test a map of size %d for %d iterations using %s\n"),
+ ASYS_TEXT ("time to test a map of size %d for %d iterations using %s (%s)\n"),
table_size,
iterations,
- test_name));
+ test_name,
+ test_iterators_string));
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("real time = %f secs, user time = %f secs, system time = %f secs\n"),
@@ -467,6 +584,7 @@ main (int argc, ASYS_TCHAR *argv[])
size_t table_size = ACE_MAX_ITERATIONS / 2;
size_t iterations = ACE_MAX_ITERATIONS;
+ int test_iterators = 1;
if (argc > 1)
table_size = ACE_OS::atoi (argv[1]);
@@ -474,17 +592,29 @@ main (int argc, ASYS_TCHAR *argv[])
if (argc > 2)
iterations = ACE_OS::atoi (argv[2]);
+ if (argc > 3)
+ test_iterators = ACE_OS::atoi (argv[3]);
+
+ // Test the <ACE_Map_Manager>.
+ run_test (&test_map_manager,
+ table_size,
+ iterations,
+ test_iterators,
+ ASYS_TEXT ("Map_Manager"));
+
// Test the <ACE_Hash_Map_Manager>.
run_test (&test_hash_map_manager,
table_size,
iterations,
+ test_iterators,
ASYS_TEXT ("Hash_Map_Manager"));
- // Test the <ACE_Map_Manager>.
- run_test (&test_map_manager,
+ // Test the <ACE_Hash_Map_Manager>.
+ run_test (&test_active_map_manager,
table_size,
iterations,
- ASYS_TEXT ("Map_Manager"));
+ test_iterators,
+ ASYS_TEXT ("Active_Map_Manager"));
ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);
ACE_END_TEST;
diff --git a/tests/SString_Test.cpp b/tests/SString_Test.cpp
index 92172eeede6..e759e75d89c 100644
--- a/tests/SString_Test.cpp
+++ b/tests/SString_Test.cpp
@@ -34,6 +34,7 @@ main (int, ASYS_TCHAR *[])
ACE_START_TEST (ASYS_TEXT ("SString_Test"));
{
+ ACE_CString empty_string;
ACE_CString s1 ("hello");
ACE_CString s2 ("world");
ACE_CString s3 ("ll");
@@ -58,6 +59,7 @@ main (int, ASYS_TCHAR *[])
}
{
+ ACE_CString empty_string (0, 0, 0);
ACE_CString s1 ("hello", 0, 0);
ACE_CString s2 ("world", 0, 0);
ACE_CString s3 ("ll", 0, 0);
@@ -82,6 +84,7 @@ main (int, ASYS_TCHAR *[])
}
{
+ ACE_WString empty_string;
ACE_WString s1 ("hello");
ACE_WString s2 ("world");
ACE_WString s3 ("ll");