Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / Array_Map.h
blob67aa8d94b23a5bbea7cbad49b7a7d760a087b8f4
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Array_Map.h
7 * $Id: Array_Map.h 80826 2008-03-04 14:51:23Z wotte $
9 * Light weight array-based map with fast iteration but linear
10 * (i.e. O(n)) search times. STL-style interface is exposed.
12 * @note This class requires the STL generic algorithms and
13 * reverse_iterator adapter.
15 * @author Ossama Othman
17 //=============================================================================
20 #ifndef ACE_ARRAY_MAP_H
21 #define ACE_ARRAY_MAP_H
23 #include /**/ "ace/pre.h"
25 #include "ace/config-lite.h"
27 #if !defined (ACE_LACKS_PRAGMA_ONCE)
28 # pragma once
29 #endif /* ACE_LACKS_PRAGMA_ONCE */
31 #include <utility>
32 #include <iterator>
33 #include <functional>
35 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
37 /**
38 * @class ACE_Array_Map
40 * @brief Light weight array-based map with fast iteration, but linear
41 * (i.e. O(n)) search times.
43 * Map implementation that focuses on small footprint and fast
44 * iteration. Search times are, however, linear (O(n)) meaning that
45 * this map isn't suitable for large data sets that will be searched
46 * in performance critical areas of code. Iteration over large data
47 * sets, however, is faster than linked list-based maps, for example,
48 * since spatial locality is maximized through the use of contiguous
49 * arrays as the underlying storage.
50 * @par
51 * An @c ACE_Array_Map is a unique associative container, meaning that
52 * duplicate values may not be added to the map. It is also pair
53 * associative (value_type is a std::pair<>). It is not a sorted
54 * container.
55 * @par
56 * An STL @c std::map -like interface is exposed by this class
57 * portability. Furthermore, this map's iterators are compatible with
58 * STL algorithms.
59 * @par
60 * <b> Requirements and Performance Characteristics</b>
61 * - Internal Structure
62 * Array
63 * - Duplicates allowed?
64 * No
65 * - Random access allowed?
66 * Yes
67 * - Search speed
68 * O(n)
69 * - Insert/replace speed
70 * O(n), can be longer if the map has to resize
71 * - Iterator still valid after change to container?
72 * No
73 * - Frees memory for removed elements?
74 * Yes
75 * - Items inserted by
76 * Value
77 * - Requirements for key type
78 * -# Default constructor
79 * -# Copy constructor
80 * -# operator=
81 * -# operator==
82 * - Requirements for object type
83 * -# Default constructor
84 * -# Copy constructor
85 * -# operator=
87 template<typename Key, typename Value, class EqualTo = std::equal_to<Key> >
88 class ACE_Array_Map
90 public:
92 // STL-style typedefs/traits.
93 typedef Key key_type;
94 typedef Value data_type;
95 typedef std::pair<key_type, data_type> value_type;
96 typedef value_type * iterator;
97 typedef value_type const * const_iterator;
98 typedef value_type & reference;
99 typedef value_type const & const_reference;
100 typedef value_type * pointer;
101 typedef value_type const * const_pointer;
102 typedef ptrdiff_t difference_type;
103 typedef size_t size_type;
105 ACE_DECLARE_STL_REVERSE_ITERATORS
107 /// Default Constructor.
109 * Create an empty map with a preallocated buffer of size @a s.
111 ACE_Array_Map (size_type s = 0);
113 #ifndef ACE_LACKS_MEMBER_TEMPLATES
114 template<typename InputIterator>
115 ACE_Array_Map (InputIterator f, InputIterator l);
116 #else
117 ACE_Array_Map (const_iterator f, const_iterator l);
118 #endif /* !ACE_LACKS_MEMBER_TEMPLATES */
120 ACE_Array_Map (ACE_Array_Map const & map);
121 ACE_Array_Map & operator= (ACE_Array_Map const & map);
123 /// Destructor.
124 ~ACE_Array_Map (void);
127 * @name Forward Iterator Accessors
129 * Forward iterator accessors.
131 //@{
132 iterator begin (void);
133 iterator end (void);
134 const_iterator begin (void) const;
135 const_iterator end (void) const;
136 //@}
139 * @name Reverse Iterator Accessors
141 * Reverse iterator accessors.
143 //@{
144 reverse_iterator rbegin (void);
145 reverse_iterator rend (void);
146 const_reverse_iterator rbegin (void) const;
147 const_reverse_iterator rend (void) const;
148 //@}
150 /// Return current size of map.
152 * @return The number of elements in the map.
154 size_type size (void) const;
156 /// Maximum number of elements the map can hold.
157 size_type max_size (void) const;
159 /// Return @c true if the map is empty, else @c false.
160 bool is_empty (void) const; // ACE style
162 /**
163 * Return @c true if the map is empty, else @c false. We recommend
164 * using @c is_empty() instead since it's more consistent with the
165 * ACE container naming conventions.
167 bool empty (void) const; // STL style
169 /// Swap the contents of this map with the given @a map in an
170 /// exception-safe manner.
171 void swap (ACE_Array_Map & map);
173 /// Insert the value @a x into the map.
175 * STL-style map insertion method.
177 * @param x @c std::pair containing key and datum.
179 * @return @c std::pair::second will be @c false if the map already
180 * contains a value with the same key as @a x.
182 std::pair<iterator, bool> insert (value_type const & x);
184 #ifndef ACE_LACKS_MEMBER_TEMPLATES
185 /// Insert range of elements into map.
186 template<typename InputIterator>
187 void insert (InputIterator f, InputIterator l);
188 #else
189 /// Insert range of elements into map.
190 void insert (const_iterator f, const_iterator l);
191 #endif /* ACE_LACKS_MEMBER_TEMPLATES */
193 /// Remove element at position @a pos from the map.
194 void erase (iterator pos);
196 /// Remove element corresponding to key @a k from the map.
198 * @return Number of elements that were erased.
200 size_type erase (key_type const & k);
202 /// Remove range of elements [@a first, @a last) from the map.
204 * @note [@a first, @a last) must be valid range within the map.
206 void erase (iterator first, iterator last);
208 /// Clear contents of map.
210 * @note This a constant time (O(1)) operation.
212 void clear (void);
215 * @name Search Operations
217 * Search the map for data corresponding to key @a k.
219 //@{
221 * @return @c end() if data corresponding to key @a k is not in the
222 * map.
224 iterator find (key_type const & k);
227 * @return @c end() if data corresponding to key @a k is not in the
228 * map.
230 const_iterator find (key_type const & k) const;
231 //@}
233 /// Count the number of elements corresponding to key @a k.
235 * @return In the case of this map, the count will always be one if
236 * such exists in the map.
238 size_type count (key_type const & k);
240 /// Convenience array index operator.
242 * Array index operator that allows insertion and retrieval of
243 * elements using an array index syntax, such as:
244 * @par
245 * map["Foo"] = 12;
247 data_type & operator[] (key_type const & k);
249 private:
251 /// Increase size of underlying buffer by @a s.
252 void grow (size_type s);
254 private:
256 /// Number of elements in the map.
257 size_type size_;
259 /// Current size of underlying array.
261 * @note @c capacity_ is always greater than or equal to @c size_;
263 size_type capacity_;
265 /// Underlying array containing keys and data.
266 value_type * nodes_;
270 // --------------------------------------------------------------
272 /// @c ACE_Array_Map equality operator.
273 template <typename Key, typename Value, class EqualTo>
274 bool operator== (ACE_Array_Map<Key, Value, EqualTo> const & lhs,
275 ACE_Array_Map<Key, Value, EqualTo> const & rhs);
277 /// @c ACE_Array_Map lexicographical comparison operator.
278 template <typename Key, typename Value, class EqualTo>
279 bool operator< (ACE_Array_Map<Key, Value, EqualTo> const & lhs,
280 ACE_Array_Map<Key, Value, EqualTo> const & rhs);
282 // --------------------------------------------------------------
284 ACE_END_VERSIONED_NAMESPACE_DECL
286 #ifdef __ACE_INLINE__
287 # include "ace/Array_Map.inl"
288 #endif /* __ACE_INLINE__ */
290 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
291 # include "ace/Array_Map.cpp"
292 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
294 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
295 #pragma implementation ("Array_Map.cpp")
296 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
298 #include /**/ "ace/post.h"
300 #endif /* ACE_ARRAY_MAP_H */