ACE_Array_Map< Key, Value, EqualTo > Class Template Reference

Light weight array-based map with fast iteration, but linear (i.e. O(n)) search times. More...

#include <Array_Map.h>

List of all members.

Public Types

typedef Key key_type
typedef Value data_type
typedef std::pair< key_type,
data_type
value_type
typedef value_typeiterator
typedef value_type const * const_iterator
typedef value_typereference
typedef value_type const & const_reference
typedef value_typepointer
typedef value_type const * const_pointer
typedef ptrdiff_t difference_type
typedef size_t size_type

Public Member Functions

ACE_DECLARE_STL_REVERSE_ITERATORS ACE_Array_Map (size_type s=0)
 Default Constructor.
template<typename InputIterator >
 ACE_Array_Map (InputIterator f, InputIterator l)
 ACE_Array_Map (ACE_Array_Map const &map)
ACE_Array_Mapoperator= (ACE_Array_Map const &map)
 ~ACE_Array_Map (void)
 Destructor.
size_type size (void) const
 Return current size of map.
size_type max_size (void) const
 Maximum number of elements the map can hold.
bool is_empty (void) const
 Return true if the map is empty, else false.
bool empty (void) const
void swap (ACE_Array_Map &map)
std::pair< iterator, bool > insert (value_type const &x)
 Insert the value x into the map.
template<typename InputIterator >
void insert (InputIterator f, InputIterator l)
 Insert range of elements into map.
void erase (iterator pos)
 Remove element at position pos from the map.
size_type erase (key_type const &k)
 Remove element corresponding to key k from the map.
void erase (iterator first, iterator last)
 Remove range of elements [first, last) from the map.
void clear (void)
 Clear contents of map.
size_type count (key_type const &k)
 Count the number of elements corresponding to key k.
data_typeoperator[] (key_type const &k)
 Convenience array index operator.
Forward Iterator Accessors

Forward iterator accessors.



iterator begin (void)
iterator end (void)
const_iterator begin (void) const
const_iterator end (void) const
Reverse Iterator Accessors

Reverse iterator accessors.



reverse_iterator rbegin (void)
reverse_iterator rend (void)
const_reverse_iterator rbegin (void) const
const_reverse_iterator rend (void) const
Search Operations

Search the map for data corresponding to key k.



iterator find (key_type const &k)
const_iterator find (key_type const &k) const

Private Member Functions

void grow (size_type s)
 Increase size of underlying buffer by s.

Private Attributes

size_type size_
 Number of elements in the map.
size_type capacity_
 Current size of underlying array.
value_typenodes_
 Underlying array containing keys and data.

Detailed Description

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
class ACE_Array_Map< Key, Value, EqualTo >

Light weight array-based map with fast iteration, but linear (i.e. O(n)) search times.

Map implementation that focuses on small footprint and fast iteration. Search times are, however, linear (O(n)) meaning that this map isn't suitable for large data sets that will be searched in performance critical areas of code. Iteration over large data sets, however, is faster than linked list-based maps, for example, since spatial locality is maximized through the use of contiguous arrays as the underlying storage.

An ACE_Array_Map is a unique associative container, meaning that duplicate values may not be added to the map. It is also pair associative (value_type is a std::pair<>). It is not a sorted container.
An STL std::map -like interface is exposed by this class portability. Furthermore, this map's iterators are compatible with STL algorithms.
Requirements and Performance Characteristics
  • Internal Structure Array
  • Duplicates allowed? No
  • Random access allowed? Yes
  • Search speed O(n)
  • Insert/replace speed O(n), can be longer if the map has to resize
  • Iterator still valid after change to container? No
  • Frees memory for removed elements? Yes
  • Items inserted by Value
  • Requirements for key type
    1. Default constructor
    2. Copy constructor
    3. operator=
    4. operator==
  • Requirements for object type
    1. Default constructor
    2. Copy constructor
    3. operator=

Definition at line 88 of file Array_Map.h.


Member Typedef Documentation

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef value_type const* ACE_Array_Map< Key, Value, EqualTo >::const_iterator

Definition at line 97 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef value_type const* ACE_Array_Map< Key, Value, EqualTo >::const_pointer

Definition at line 101 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef value_type const& ACE_Array_Map< Key, Value, EqualTo >::const_reference

Definition at line 99 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef Value ACE_Array_Map< Key, Value, EqualTo >::data_type

Definition at line 94 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef ptrdiff_t ACE_Array_Map< Key, Value, EqualTo >::difference_type

Definition at line 102 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef value_type* ACE_Array_Map< Key, Value, EqualTo >::iterator

Definition at line 96 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef Key ACE_Array_Map< Key, Value, EqualTo >::key_type

Definition at line 93 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef value_type* ACE_Array_Map< Key, Value, EqualTo >::pointer

Definition at line 100 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef value_type& ACE_Array_Map< Key, Value, EqualTo >::reference

Definition at line 98 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef size_t ACE_Array_Map< Key, Value, EqualTo >::size_type

Definition at line 103 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
typedef std::pair<key_type, data_type> ACE_Array_Map< Key, Value, EqualTo >::value_type

Definition at line 95 of file Array_Map.h.


Constructor & Destructor Documentation

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::ACE_Array_Map ( typename ACE_Array_Map< Key, Value, EqualTo >::size_type  s = 0  )  [inline]

Default Constructor.

Create an empty map with a preallocated buffer of size s.

Definition at line 9 of file Array_Map.inl.

00011   : size_ (0)
00012   , capacity_ (s)
00013   , nodes_ (s == 0 ? 0 : new value_type[s])
00014 {
00015 }

template<typename Key , typename Value , class EqualTo >
template<typename InputIterator >
ACE_Array_Map< Key, Value, EqualTo >::ACE_Array_Map ( InputIterator  f,
InputIterator  l 
) [inline]

Definition at line 21 of file Array_Map.cpp.

00023   : size_ (l - f)
00024   , capacity_ (size_)
00025   , nodes_ (size_ == 0 ? 0 : new value_type[size_])
00026 {
00027   (void) std::copy (f,
00028                     l,
00029                     ACE_make_checked_array_iterator (this->begin (),
00030                                                      this->size_));
00031 
00032 //   iterator n = this->begin ();
00033 
00034 //   for (InputIterator i = f; i != l; ++i, ++n)
00035 //     *n = *i;
00036 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::ACE_Array_Map ( ACE_Array_Map< Key, Value, EqualTo > const &  map  )  [inline]

Definition at line 59 of file Array_Map.cpp.

00061   : size_ (map.size_)
00062   , capacity_ (map.size_)
00063   , nodes_ (size_ == 0 ? 0 : new value_type[size_])
00064 {
00065   std::copy (map.begin (),
00066              map.end (),
00067              ACE_make_checked_array_iterator (this->begin (),
00068                                               this->size_));
00069 
00070 //   iterator f = map.begin ();
00071 //   iterator l = map.end ();
00072 //   iterator n = this->begin ();
00073 
00074 //   for (iterator i = f; i != l; ++i, ++n)
00075 //     *n = *i;
00076 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::~ACE_Array_Map ( void   )  [inline]

Destructor.

Definition at line 79 of file Array_Map.cpp.

00080 {
00081   delete[] this->nodes_;
00082 }


Member Function Documentation

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::const_iterator ACE_Array_Map< Key, Value, EqualTo >::begin ( void   )  const [inline]

Definition at line 45 of file Array_Map.inl.

00046 {
00047   return this->nodes_;
00048 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::iterator ACE_Array_Map< Key, Value, EqualTo >::begin ( void   )  [inline]

Definition at line 31 of file Array_Map.inl.

00032 {
00033   return this->nodes_;
00034 }

template<typename Key , typename Value , class EqualTo >
void ACE_Array_Map< Key, Value, EqualTo >::clear ( void   )  [inline]

Clear contents of map.

Note:
This a constant time (O(1)) operation.

Definition at line 205 of file Array_Map.cpp.

00206 {
00207   this->size_ = 0;  // No need to deallocate array nor destroy elements.
00208 }

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
size_type ACE_Array_Map< Key, Value, EqualTo >::count ( key_type const &  k  ) 

Count the number of elements corresponding to key k.

Returns:
In the case of this map, the count will always be one if such exists in the map.
template<typename Key , typename Value , class EqualTo >
bool ACE_Array_Map< Key, Value, EqualTo >::empty ( void   )  const [inline]

Return true if the map is empty, else false. We recommend using is_empty() instead since it's more consistent with the ACE container naming conventions.

Definition at line 110 of file Array_Map.inl.

00111 {
00112   return this->is_empty ();
00113 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::const_iterator ACE_Array_Map< Key, Value, EqualTo >::end ( void   )  const [inline]

Definition at line 52 of file Array_Map.inl.

00053 {
00054   return this->nodes_ + this->size_;
00055 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::iterator ACE_Array_Map< Key, Value, EqualTo >::end ( void   )  [inline]

Definition at line 38 of file Array_Map.inl.

00039 {
00040   return this->nodes_ + this->size_;
00041 }

template<typename Key, typename Value, class EqualTo>
void ACE_Array_Map< Key, Value, EqualTo >::erase ( typename ACE_Array_Map< Key, Value, EqualTo >::iterator  first,
typename ACE_Array_Map< Key, Value, EqualTo >::iterator  last 
) [inline]

Remove range of elements [first, last) from the map.

Note:
[first, last) must be valid range within the map.

Definition at line 194 of file Array_Map.cpp.

00197 {
00198   if (this->begin () <= first && first < last && last < this->end ())
00199     for (iterator i = first; i != last; ++i)
00200       this->erase (i);
00201 }

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
size_type ACE_Array_Map< Key, Value, EqualTo >::erase ( key_type const &  k  ) 

Remove element corresponding to key k from the map.

Returns:
Number of elements that were erased.
template<typename Key , typename Value , class EqualTo >
void ACE_Array_Map< Key, Value, EqualTo >::erase ( typename ACE_Array_Map< Key, Value, EqualTo >::iterator  pos  )  [inline]

Remove element at position pos from the map.

Definition at line 153 of file Array_Map.cpp.

00155 {
00156   iterator const first = this->begin ();
00157   iterator const last = this->end ();
00158 
00159   if (pos >= first && pos < last)
00160     {
00161       if (pos != last - 1)
00162         {
00163           // Relocate the tail element to the location of the erased
00164           // element to prevent introduction of "holes" in the
00165           // underlying array.
00166           *pos = *(last - 1);
00167         }
00168 
00169       // Explicitly destroy the tail element by assigning a default
00170       // constructed instance to it.  Note that this also works for
00171       // the case of a map of size 1.
00172       *(last - 1) = value_type ();
00173 
00174       --this->size_;
00175     }
00176 }

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
const_iterator ACE_Array_Map< Key, Value, EqualTo >::find ( key_type const &  k  )  const
Returns:
end() if data corresponding to key k is not in the map.
template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
iterator ACE_Array_Map< Key, Value, EqualTo >::find ( key_type const &  k  ) 
Returns:
end() if data corresponding to key k is not in the map.
template<typename Key , typename Value , class EqualTo >
void ACE_Array_Map< Key, Value, EqualTo >::grow ( typename ACE_Array_Map< Key, Value, EqualTo >::size_type  s  )  [inline, private]

Increase size of underlying buffer by s.

Definition at line 244 of file Array_Map.cpp.

00246 {
00247   if (this->size () + s > this->capacity_)
00248     {
00249       // This implementation focuses more on static footprint than
00250       // speed.
00251 
00252       // Strongly exception safe.
00253 
00254       ACE_Array_Map<Key, Value, EqualTo> temp (this->size () + s);
00255 
00256       std::copy (this->begin (),
00257                  this->end (),
00258                  ACE_make_checked_array_iterator (temp.begin (),
00259                                                   temp.capacity_));
00260 
00261       size_type const n = this->size ();  // Do not swap out the size
00262                                           // since we bypassed the
00263                                           // temporary map's element
00264                                           // counting code.
00265       this->swap (temp);
00266 
00267       this->size_ = n;
00268     }
00269 }

template<typename Key , typename Value , class EqualTo >
template<typename InputIterator >
void ACE_Array_Map< Key, Value, EqualTo >::insert ( InputIterator  f,
InputIterator  l 
) [inline]

Insert range of elements into map.

Definition at line 126 of file Array_Map.cpp.

00127 {
00128   this->grow (l - f);  // Preallocate storage.
00129 
00130   for (InputIterator i = f; i != l; ++i)
00131     {
00132       (void) this->insert (*i);
00133     }
00134 }

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
std::pair<iterator, bool> ACE_Array_Map< Key, Value, EqualTo >::insert ( value_type const &  x  ) 

Insert the value x into the map.

STL-style map insertion method.

Parameters:
x std::pair containing key and datum.
Returns:
std::pair::second will be false if the map already contains a value with the same key as x.
template<typename Key , typename Value , class EqualTo >
bool ACE_Array_Map< Key, Value, EqualTo >::is_empty ( void   )  const [inline]

Return true if the map is empty, else false.

Definition at line 101 of file Array_Map.inl.

00102 {
00103   return this->size_ == 0;
00104 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::size_type ACE_Array_Map< Key, Value, EqualTo >::max_size ( void   )  const [inline]

Maximum number of elements the map can hold.

Definition at line 94 of file Array_Map.inl.

00095 {
00096   return size_type (-1) / sizeof (value_type);
00097 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo > & ACE_Array_Map< Key, Value, EqualTo >::operator= ( ACE_Array_Map< Key, Value, EqualTo > const &  map  )  [inline]

Definition at line 19 of file Array_Map.inl.

00021 {
00022   // Strongly exception-safe assignment.
00023 
00024   ACE_Array_Map<Key, Value, EqualTo> temp (map);
00025   this->swap (temp);
00026   return *this;
00027 }

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
data_type& ACE_Array_Map< Key, Value, EqualTo >::operator[] ( key_type const &  k  ) 

Convenience array index operator.

Array index operator that allows insertion and retrieval of elements using an array index syntax, such as:

map["Foo"] = 12;
template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::const_reverse_iterator ACE_Array_Map< Key, Value, EqualTo >::rbegin ( void   )  const [inline]

Definition at line 73 of file Array_Map.inl.

00074 {
00075   return const_reverse_iterator (this->end ());
00076 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::reverse_iterator ACE_Array_Map< Key, Value, EqualTo >::rbegin ( void   )  [inline]

Definition at line 59 of file Array_Map.inl.

00060 {
00061   return reverse_iterator (this->end ());
00062 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::const_reverse_iterator ACE_Array_Map< Key, Value, EqualTo >::rend ( void   )  const [inline]

Definition at line 80 of file Array_Map.inl.

00081 {
00082   return const_reverse_iterator (this->begin ());
00083 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::reverse_iterator ACE_Array_Map< Key, Value, EqualTo >::rend ( void   )  [inline]

Definition at line 66 of file Array_Map.inl.

00067 {
00068   return reverse_iterator (this->begin ());
00069 }

template<typename Key , typename Value , class EqualTo >
ACE_Array_Map< Key, Value, EqualTo >::size_type ACE_Array_Map< Key, Value, EqualTo >::size ( void   )  const [inline]

Return current size of map.

Returns:
The number of elements in the map.

Definition at line 87 of file Array_Map.inl.

00088 {
00089   return this->size_;
00090 }

template<typename Key , typename Value , class EqualTo >
void ACE_Array_Map< Key, Value, EqualTo >::swap ( ACE_Array_Map< Key, Value, EqualTo > &  map  )  [inline]

Swap the contents of this map with the given map in an exception-safe manner.

Definition at line 86 of file Array_Map.cpp.

00088 {
00089   std::swap (this->size_, map.size_);
00090   std::swap (this->capacity_, map.capacity_);
00091   std::swap (this->nodes_, map.nodes_);
00092 }


Member Data Documentation

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
size_type ACE_Array_Map< Key, Value, EqualTo >::capacity_ [private]

Current size of underlying array.

Note:
capacity_ is always greater than or equal to size_;

Definition at line 263 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
value_type* ACE_Array_Map< Key, Value, EqualTo >::nodes_ [private]

Underlying array containing keys and data.

Definition at line 266 of file Array_Map.h.

template<typename Key, typename Value, class EqualTo = std::equal_to<Key>>
size_type ACE_Array_Map< Key, Value, EqualTo >::size_ [private]

Number of elements in the map.

Definition at line 257 of file Array_Map.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sat Nov 21 23:15:50 2009 for ACE by  doxygen 1.6.1