1 | |
---|
2 | // Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard. |
---|
3 | // Copyright (C) 2005-2009 Daniel James. |
---|
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
---|
5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | // See http://www.boost.org/libs/unordered for documentation |
---|
8 | |
---|
9 | #ifndef BOOST_UNORDERED_UNORDERED_MAP_HPP_INCLUDED |
---|
10 | #define BOOST_UNORDERED_UNORDERED_MAP_HPP_INCLUDED |
---|
11 | |
---|
12 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
13 | # pragma once |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <boost/unordered/unordered_map_fwd.hpp> |
---|
17 | #include <boost/functional/hash.hpp> |
---|
18 | #include <boost/unordered/detail/allocator_helpers.hpp> |
---|
19 | #include <boost/unordered/detail/equivalent.hpp> |
---|
20 | #include <boost/unordered/detail/unique.hpp> |
---|
21 | |
---|
22 | #if defined(BOOST_NO_RVALUE_REFERENCES) |
---|
23 | #include <boost/unordered/detail/move.hpp> |
---|
24 | #endif |
---|
25 | |
---|
26 | #if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST) |
---|
27 | #include <initializer_list> |
---|
28 | #endif |
---|
29 | |
---|
30 | #if defined(BOOST_MSVC) |
---|
31 | #pragma warning(push) |
---|
32 | #if BOOST_MSVC >= 1400 |
---|
33 | #pragma warning(disable:4396) //the inline specifier cannot be used when a |
---|
34 | // friend declaration refers to a specialization |
---|
35 | // of a function template |
---|
36 | #endif |
---|
37 | #endif |
---|
38 | |
---|
39 | namespace boost |
---|
40 | { |
---|
41 | template <class K, class T, class H, class P, class A> |
---|
42 | class unordered_map |
---|
43 | { |
---|
44 | public: |
---|
45 | typedef K key_type; |
---|
46 | typedef std::pair<const K, T> value_type; |
---|
47 | typedef T mapped_type; |
---|
48 | typedef H hasher; |
---|
49 | typedef P key_equal; |
---|
50 | typedef A allocator_type; |
---|
51 | |
---|
52 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582) |
---|
53 | private: |
---|
54 | #endif |
---|
55 | |
---|
56 | typedef BOOST_DEDUCED_TYPENAME |
---|
57 | boost::unordered_detail::rebind_wrap< |
---|
58 | allocator_type, value_type>::type |
---|
59 | value_allocator; |
---|
60 | |
---|
61 | typedef boost::unordered_detail::map<K, H, P, |
---|
62 | value_allocator> types; |
---|
63 | typedef BOOST_DEDUCED_TYPENAME types::impl table; |
---|
64 | |
---|
65 | typedef BOOST_DEDUCED_TYPENAME types::iterator_base iterator_base; |
---|
66 | |
---|
67 | public: |
---|
68 | |
---|
69 | typedef BOOST_DEDUCED_TYPENAME |
---|
70 | value_allocator::pointer pointer; |
---|
71 | typedef BOOST_DEDUCED_TYPENAME |
---|
72 | value_allocator::const_pointer const_pointer; |
---|
73 | typedef BOOST_DEDUCED_TYPENAME |
---|
74 | value_allocator::reference reference; |
---|
75 | typedef BOOST_DEDUCED_TYPENAME |
---|
76 | value_allocator::const_reference const_reference; |
---|
77 | |
---|
78 | typedef std::size_t size_type; |
---|
79 | typedef std::ptrdiff_t difference_type; |
---|
80 | |
---|
81 | typedef boost::unordered_detail::hash_const_local_iterator< |
---|
82 | value_allocator, boost::unordered_detail::ungrouped> |
---|
83 | const_local_iterator; |
---|
84 | typedef boost::unordered_detail::hash_local_iterator< |
---|
85 | value_allocator, boost::unordered_detail::ungrouped> |
---|
86 | local_iterator; |
---|
87 | typedef boost::unordered_detail::hash_const_iterator< |
---|
88 | value_allocator, boost::unordered_detail::ungrouped> |
---|
89 | const_iterator; |
---|
90 | typedef boost::unordered_detail::hash_iterator< |
---|
91 | value_allocator, boost::unordered_detail::ungrouped> |
---|
92 | iterator; |
---|
93 | |
---|
94 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582) |
---|
95 | private: |
---|
96 | #endif |
---|
97 | |
---|
98 | table table_; |
---|
99 | |
---|
100 | BOOST_DEDUCED_TYPENAME types::iterator_base const& |
---|
101 | get(const_iterator const& it) |
---|
102 | { |
---|
103 | return boost::unordered_detail::iterator_access::get(it); |
---|
104 | } |
---|
105 | |
---|
106 | public: |
---|
107 | |
---|
108 | // construct/destroy/copy |
---|
109 | |
---|
110 | explicit unordered_map( |
---|
111 | size_type n = boost::unordered_detail::default_bucket_count, |
---|
112 | const hasher &hf = hasher(), |
---|
113 | const key_equal &eql = key_equal(), |
---|
114 | const allocator_type &a = allocator_type()) |
---|
115 | : table_(n, hf, eql, a) |
---|
116 | { |
---|
117 | } |
---|
118 | |
---|
119 | explicit unordered_map(allocator_type const& a) |
---|
120 | : table_(boost::unordered_detail::default_bucket_count, |
---|
121 | hasher(), key_equal(), a) |
---|
122 | { |
---|
123 | } |
---|
124 | |
---|
125 | unordered_map(unordered_map const& other, allocator_type const& a) |
---|
126 | : table_(other.table_, a) |
---|
127 | { |
---|
128 | } |
---|
129 | |
---|
130 | template <class InputIt> |
---|
131 | unordered_map(InputIt f, InputIt l) |
---|
132 | : table_(boost::unordered_detail::initial_size(f, l), |
---|
133 | hasher(), key_equal(), allocator_type()) |
---|
134 | { |
---|
135 | table_.insert_range(f, l); |
---|
136 | } |
---|
137 | |
---|
138 | template <class InputIt> |
---|
139 | unordered_map(InputIt f, InputIt l, |
---|
140 | size_type n, |
---|
141 | const hasher &hf = hasher(), |
---|
142 | const key_equal &eql = key_equal()) |
---|
143 | : table_(boost::unordered_detail::initial_size(f, l, n), |
---|
144 | hf, eql, allocator_type()) |
---|
145 | { |
---|
146 | table_.insert_range(f, l); |
---|
147 | } |
---|
148 | |
---|
149 | template <class InputIt> |
---|
150 | unordered_map(InputIt f, InputIt l, |
---|
151 | size_type n, |
---|
152 | const hasher &hf, |
---|
153 | const key_equal &eql, |
---|
154 | const allocator_type &a) |
---|
155 | : table_(boost::unordered_detail::initial_size(f, l, n), hf, eql, a) |
---|
156 | { |
---|
157 | table_.insert_range(f, l); |
---|
158 | } |
---|
159 | |
---|
160 | ~unordered_map() {} |
---|
161 | |
---|
162 | #if !defined(BOOST_NO_RVALUE_REFERENCES) |
---|
163 | unordered_map(unordered_map&& other) |
---|
164 | : table_(other.table_, boost::unordered_detail::move_tag()) |
---|
165 | { |
---|
166 | } |
---|
167 | |
---|
168 | unordered_map(unordered_map&& other, allocator_type const& a) |
---|
169 | : table_(other.table_, a, boost::unordered_detail::move_tag()) |
---|
170 | { |
---|
171 | } |
---|
172 | |
---|
173 | unordered_map& operator=(unordered_map&& x) |
---|
174 | { |
---|
175 | table_.move(x.table_); |
---|
176 | return *this; |
---|
177 | } |
---|
178 | #else |
---|
179 | unordered_map(boost::unordered_detail::move_from< |
---|
180 | unordered_map<K, T, H, P, A> |
---|
181 | > other) |
---|
182 | : table_(other.source.table_, boost::unordered_detail::move_tag()) |
---|
183 | { |
---|
184 | } |
---|
185 | |
---|
186 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0593) |
---|
187 | unordered_map& operator=(unordered_map x) |
---|
188 | { |
---|
189 | table_.move(x.table_); |
---|
190 | return *this; |
---|
191 | } |
---|
192 | #endif |
---|
193 | #endif |
---|
194 | |
---|
195 | #if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST) |
---|
196 | unordered_map(std::initializer_list<value_type> list, |
---|
197 | size_type n = boost::unordered_detail::default_bucket_count, |
---|
198 | const hasher &hf = hasher(), |
---|
199 | const key_equal &eql = key_equal(), |
---|
200 | const allocator_type &a = allocator_type()) |
---|
201 | : table_(boost::unordered_detail::initial_size( |
---|
202 | list.begin(), list.end(), n), |
---|
203 | hf, eql, a) |
---|
204 | { |
---|
205 | table_.insert_range(list.begin(), list.end()); |
---|
206 | } |
---|
207 | |
---|
208 | unordered_map& operator=(std::initializer_list<value_type> list) |
---|
209 | { |
---|
210 | table_.clear(); |
---|
211 | table_.insert_range(list.begin(), list.end()); |
---|
212 | return *this; |
---|
213 | } |
---|
214 | #endif |
---|
215 | |
---|
216 | allocator_type get_allocator() const |
---|
217 | { |
---|
218 | return table_.node_alloc(); |
---|
219 | } |
---|
220 | |
---|
221 | // size and capacity |
---|
222 | |
---|
223 | bool empty() const |
---|
224 | { |
---|
225 | return table_.size_ == 0; |
---|
226 | } |
---|
227 | |
---|
228 | size_type size() const |
---|
229 | { |
---|
230 | return table_.size_; |
---|
231 | } |
---|
232 | |
---|
233 | size_type max_size() const |
---|
234 | { |
---|
235 | return table_.max_size(); |
---|
236 | } |
---|
237 | |
---|
238 | // iterators |
---|
239 | |
---|
240 | iterator begin() |
---|
241 | { |
---|
242 | return iterator(table_.begin()); |
---|
243 | } |
---|
244 | |
---|
245 | const_iterator begin() const |
---|
246 | { |
---|
247 | return const_iterator(table_.begin()); |
---|
248 | } |
---|
249 | |
---|
250 | iterator end() |
---|
251 | { |
---|
252 | return iterator(table_.end()); |
---|
253 | } |
---|
254 | |
---|
255 | const_iterator end() const |
---|
256 | { |
---|
257 | return const_iterator(table_.end()); |
---|
258 | } |
---|
259 | |
---|
260 | const_iterator cbegin() const |
---|
261 | { |
---|
262 | return const_iterator(table_.begin()); |
---|
263 | } |
---|
264 | |
---|
265 | const_iterator cend() const |
---|
266 | { |
---|
267 | return const_iterator(table_.end()); |
---|
268 | } |
---|
269 | |
---|
270 | // modifiers |
---|
271 | |
---|
272 | #if defined(BOOST_UNORDERED_STD_FORWARD) |
---|
273 | template <class... Args> |
---|
274 | std::pair<iterator, bool> emplace(Args&&... args) |
---|
275 | { |
---|
276 | return boost::unordered_detail::pair_cast<iterator, bool>( |
---|
277 | table_.emplace(std::forward<Args>(args)...)); |
---|
278 | } |
---|
279 | |
---|
280 | template <class... Args> |
---|
281 | iterator emplace_hint(const_iterator, Args&&... args) |
---|
282 | { |
---|
283 | return iterator(table_.emplace(std::forward<Args>(args)...).first); |
---|
284 | } |
---|
285 | #else |
---|
286 | |
---|
287 | #if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) |
---|
288 | std::pair<iterator, bool> emplace(value_type const& v = value_type()) |
---|
289 | { |
---|
290 | return boost::unordered_detail::pair_cast<iterator, bool>( |
---|
291 | table_.emplace(v)); |
---|
292 | } |
---|
293 | |
---|
294 | iterator emplace_hint(const_iterator, |
---|
295 | value_type const& v = value_type()) |
---|
296 | { |
---|
297 | return iterator(table_.emplace(v).first); |
---|
298 | } |
---|
299 | #endif |
---|
300 | |
---|
301 | #define BOOST_UNORDERED_EMPLACE(z, n, _) \ |
---|
302 | template < \ |
---|
303 | BOOST_UNORDERED_TEMPLATE_ARGS(z, n) \ |
---|
304 | > \ |
---|
305 | std::pair<iterator, bool> emplace( \ |
---|
306 | BOOST_UNORDERED_FUNCTION_PARAMS(z, n) \ |
---|
307 | ) \ |
---|
308 | { \ |
---|
309 | return boost::unordered_detail::pair_cast<iterator, bool>( \ |
---|
310 | table_.emplace( \ |
---|
311 | BOOST_UNORDERED_CALL_PARAMS(z, n) \ |
---|
312 | )); \ |
---|
313 | } \ |
---|
314 | \ |
---|
315 | template < \ |
---|
316 | BOOST_UNORDERED_TEMPLATE_ARGS(z, n) \ |
---|
317 | > \ |
---|
318 | iterator emplace_hint(const_iterator, \ |
---|
319 | BOOST_UNORDERED_FUNCTION_PARAMS(z, n) \ |
---|
320 | ) \ |
---|
321 | { \ |
---|
322 | return iterator(table_.emplace( \ |
---|
323 | BOOST_UNORDERED_CALL_PARAMS(z, n)).first); \ |
---|
324 | } |
---|
325 | |
---|
326 | BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, |
---|
327 | BOOST_UNORDERED_EMPLACE, _) |
---|
328 | |
---|
329 | #undef BOOST_UNORDERED_EMPLACE |
---|
330 | |
---|
331 | #endif |
---|
332 | |
---|
333 | std::pair<iterator, bool> insert(const value_type& obj) |
---|
334 | { |
---|
335 | return boost::unordered_detail::pair_cast<iterator, bool>( |
---|
336 | table_.emplace(obj)); |
---|
337 | } |
---|
338 | |
---|
339 | iterator insert(const_iterator, const value_type& obj) |
---|
340 | { |
---|
341 | return iterator(table_.emplace(obj).first); |
---|
342 | } |
---|
343 | |
---|
344 | template <class InputIt> |
---|
345 | void insert(InputIt first, InputIt last) |
---|
346 | { |
---|
347 | table_.insert_range(first, last); |
---|
348 | } |
---|
349 | |
---|
350 | #if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST) |
---|
351 | void insert(std::initializer_list<value_type> list) |
---|
352 | { |
---|
353 | table_.insert_range(list.begin(), list.end()); |
---|
354 | } |
---|
355 | #endif |
---|
356 | |
---|
357 | iterator erase(const_iterator position) |
---|
358 | { |
---|
359 | return iterator(table_.erase_return_iterator(get(position))); |
---|
360 | } |
---|
361 | |
---|
362 | size_type erase(const key_type& k) |
---|
363 | { |
---|
364 | return table_.erase_key(k); |
---|
365 | } |
---|
366 | |
---|
367 | iterator erase(const_iterator first, const_iterator last) |
---|
368 | { |
---|
369 | return iterator(table_.erase_range(get(first), get(last))); |
---|
370 | } |
---|
371 | |
---|
372 | void quick_erase(const_iterator position) |
---|
373 | { |
---|
374 | table_.erase(get(position)); |
---|
375 | } |
---|
376 | |
---|
377 | void erase_return_void(const_iterator position) |
---|
378 | { |
---|
379 | table_.erase(get(position)); |
---|
380 | } |
---|
381 | |
---|
382 | void clear() |
---|
383 | { |
---|
384 | table_.clear(); |
---|
385 | } |
---|
386 | |
---|
387 | void swap(unordered_map& other) |
---|
388 | { |
---|
389 | table_.swap(other.table_); |
---|
390 | } |
---|
391 | |
---|
392 | // observers |
---|
393 | |
---|
394 | hasher hash_function() const |
---|
395 | { |
---|
396 | return table_.hash_function(); |
---|
397 | } |
---|
398 | |
---|
399 | key_equal key_eq() const |
---|
400 | { |
---|
401 | return table_.key_eq(); |
---|
402 | } |
---|
403 | |
---|
404 | mapped_type& operator[](const key_type &k) |
---|
405 | { |
---|
406 | return table_[k].second; |
---|
407 | } |
---|
408 | |
---|
409 | mapped_type& at(const key_type& k) |
---|
410 | { |
---|
411 | return table_.at(k).second; |
---|
412 | } |
---|
413 | |
---|
414 | mapped_type const& at(const key_type& k) const |
---|
415 | { |
---|
416 | return table_.at(k).second; |
---|
417 | } |
---|
418 | |
---|
419 | // lookup |
---|
420 | |
---|
421 | iterator find(const key_type& k) |
---|
422 | { |
---|
423 | return iterator(table_.find(k)); |
---|
424 | } |
---|
425 | |
---|
426 | const_iterator find(const key_type& k) const |
---|
427 | { |
---|
428 | return const_iterator(table_.find(k)); |
---|
429 | } |
---|
430 | |
---|
431 | template <class CompatibleKey, class CompatibleHash, |
---|
432 | class CompatiblePredicate> |
---|
433 | iterator find( |
---|
434 | CompatibleKey const& k, |
---|
435 | CompatibleHash const& hash, |
---|
436 | CompatiblePredicate const& eq) |
---|
437 | { |
---|
438 | return iterator(table_.find(k, hash, eq)); |
---|
439 | } |
---|
440 | |
---|
441 | template <class CompatibleKey, class CompatibleHash, |
---|
442 | class CompatiblePredicate> |
---|
443 | const_iterator find( |
---|
444 | CompatibleKey const& k, |
---|
445 | CompatibleHash const& hash, |
---|
446 | CompatiblePredicate const& eq) const |
---|
447 | { |
---|
448 | return iterator(table_.find(k, hash, eq)); |
---|
449 | } |
---|
450 | |
---|
451 | size_type count(const key_type& k) const |
---|
452 | { |
---|
453 | return table_.count(k); |
---|
454 | } |
---|
455 | |
---|
456 | std::pair<iterator, iterator> |
---|
457 | equal_range(const key_type& k) |
---|
458 | { |
---|
459 | return boost::unordered_detail::pair_cast< |
---|
460 | iterator, iterator>( |
---|
461 | table_.equal_range(k)); |
---|
462 | } |
---|
463 | |
---|
464 | std::pair<const_iterator, const_iterator> |
---|
465 | equal_range(const key_type& k) const |
---|
466 | { |
---|
467 | return boost::unordered_detail::pair_cast< |
---|
468 | const_iterator, const_iterator>( |
---|
469 | table_.equal_range(k)); |
---|
470 | } |
---|
471 | |
---|
472 | // bucket interface |
---|
473 | |
---|
474 | size_type bucket_count() const |
---|
475 | { |
---|
476 | return table_.bucket_count_; |
---|
477 | } |
---|
478 | |
---|
479 | size_type max_bucket_count() const |
---|
480 | { |
---|
481 | return table_.max_bucket_count(); |
---|
482 | } |
---|
483 | |
---|
484 | size_type bucket_size(size_type n) const |
---|
485 | { |
---|
486 | return table_.bucket_size(n); |
---|
487 | } |
---|
488 | |
---|
489 | size_type bucket(const key_type& k) const |
---|
490 | { |
---|
491 | return table_.bucket_index(k); |
---|
492 | } |
---|
493 | |
---|
494 | local_iterator begin(size_type n) |
---|
495 | { |
---|
496 | return local_iterator(table_.bucket_begin(n)); |
---|
497 | } |
---|
498 | |
---|
499 | const_local_iterator begin(size_type n) const |
---|
500 | { |
---|
501 | return const_local_iterator(table_.bucket_begin(n)); |
---|
502 | } |
---|
503 | |
---|
504 | local_iterator end(size_type) |
---|
505 | { |
---|
506 | return local_iterator(); |
---|
507 | } |
---|
508 | |
---|
509 | const_local_iterator end(size_type) const |
---|
510 | { |
---|
511 | return const_local_iterator(); |
---|
512 | } |
---|
513 | |
---|
514 | const_local_iterator cbegin(size_type n) const |
---|
515 | { |
---|
516 | return const_local_iterator(table_.bucket_begin(n)); |
---|
517 | } |
---|
518 | |
---|
519 | const_local_iterator cend(size_type) const |
---|
520 | { |
---|
521 | return const_local_iterator(); |
---|
522 | } |
---|
523 | |
---|
524 | // hash policy |
---|
525 | |
---|
526 | float load_factor() const |
---|
527 | { |
---|
528 | return table_.load_factor(); |
---|
529 | } |
---|
530 | |
---|
531 | float max_load_factor() const |
---|
532 | { |
---|
533 | return table_.mlf_; |
---|
534 | } |
---|
535 | |
---|
536 | void max_load_factor(float m) |
---|
537 | { |
---|
538 | table_.max_load_factor(m); |
---|
539 | } |
---|
540 | |
---|
541 | void rehash(size_type n) |
---|
542 | { |
---|
543 | table_.rehash(n); |
---|
544 | } |
---|
545 | |
---|
546 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582) |
---|
547 | friend bool operator==<K, T, H, P, A>( |
---|
548 | unordered_map const&, unordered_map const&); |
---|
549 | friend bool operator!=<K, T, H, P, A>( |
---|
550 | unordered_map const&, unordered_map const&); |
---|
551 | #endif |
---|
552 | }; // class template unordered_map |
---|
553 | |
---|
554 | template <class K, class T, class H, class P, class A> |
---|
555 | inline bool operator==(unordered_map<K, T, H, P, A> const& m1, |
---|
556 | unordered_map<K, T, H, P, A> const& m2) |
---|
557 | { |
---|
558 | #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613)) |
---|
559 | struct dummy { unordered_map<K,T,H,P,A> x; }; |
---|
560 | #endif |
---|
561 | return m1.table_.equals(m2.table_); |
---|
562 | } |
---|
563 | |
---|
564 | template <class K, class T, class H, class P, class A> |
---|
565 | inline bool operator!=(unordered_map<K, T, H, P, A> const& m1, |
---|
566 | unordered_map<K, T, H, P, A> const& m2) |
---|
567 | { |
---|
568 | #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613)) |
---|
569 | struct dummy { unordered_map<K,T,H,P,A> x; }; |
---|
570 | #endif |
---|
571 | return !m1.table_.equals(m2.table_); |
---|
572 | } |
---|
573 | |
---|
574 | template <class K, class T, class H, class P, class A> |
---|
575 | inline void swap(unordered_map<K, T, H, P, A> &m1, |
---|
576 | unordered_map<K, T, H, P, A> &m2) |
---|
577 | { |
---|
578 | #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613)) |
---|
579 | struct dummy { unordered_map<K,T,H,P,A> x; }; |
---|
580 | #endif |
---|
581 | m1.swap(m2); |
---|
582 | } |
---|
583 | |
---|
584 | template <class K, class T, class H, class P, class A> |
---|
585 | class unordered_multimap |
---|
586 | { |
---|
587 | public: |
---|
588 | |
---|
589 | typedef K key_type; |
---|
590 | typedef std::pair<const K, T> value_type; |
---|
591 | typedef T mapped_type; |
---|
592 | typedef H hasher; |
---|
593 | typedef P key_equal; |
---|
594 | typedef A allocator_type; |
---|
595 | |
---|
596 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582) |
---|
597 | private: |
---|
598 | #endif |
---|
599 | |
---|
600 | typedef BOOST_DEDUCED_TYPENAME |
---|
601 | boost::unordered_detail::rebind_wrap< |
---|
602 | allocator_type, value_type>::type |
---|
603 | value_allocator; |
---|
604 | |
---|
605 | typedef boost::unordered_detail::multimap<K, H, P, |
---|
606 | value_allocator> types; |
---|
607 | typedef BOOST_DEDUCED_TYPENAME types::impl table; |
---|
608 | |
---|
609 | typedef BOOST_DEDUCED_TYPENAME types::iterator_base iterator_base; |
---|
610 | |
---|
611 | public: |
---|
612 | |
---|
613 | typedef BOOST_DEDUCED_TYPENAME |
---|
614 | value_allocator::pointer pointer; |
---|
615 | typedef BOOST_DEDUCED_TYPENAME |
---|
616 | value_allocator::const_pointer const_pointer; |
---|
617 | typedef BOOST_DEDUCED_TYPENAME |
---|
618 | value_allocator::reference reference; |
---|
619 | typedef BOOST_DEDUCED_TYPENAME |
---|
620 | value_allocator::const_reference const_reference; |
---|
621 | |
---|
622 | typedef std::size_t size_type; |
---|
623 | typedef std::ptrdiff_t difference_type; |
---|
624 | |
---|
625 | typedef boost::unordered_detail::hash_const_local_iterator< |
---|
626 | value_allocator, boost::unordered_detail::grouped> |
---|
627 | const_local_iterator; |
---|
628 | typedef boost::unordered_detail::hash_local_iterator< |
---|
629 | value_allocator, boost::unordered_detail::grouped> |
---|
630 | local_iterator; |
---|
631 | typedef boost::unordered_detail::hash_const_iterator< |
---|
632 | value_allocator, boost::unordered_detail::grouped> |
---|
633 | const_iterator; |
---|
634 | typedef boost::unordered_detail::hash_iterator< |
---|
635 | value_allocator, boost::unordered_detail::grouped> |
---|
636 | iterator; |
---|
637 | |
---|
638 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582) |
---|
639 | private: |
---|
640 | #endif |
---|
641 | |
---|
642 | table table_; |
---|
643 | |
---|
644 | BOOST_DEDUCED_TYPENAME types::iterator_base const& |
---|
645 | get(const_iterator const& it) |
---|
646 | { |
---|
647 | return boost::unordered_detail::iterator_access::get(it); |
---|
648 | } |
---|
649 | |
---|
650 | public: |
---|
651 | |
---|
652 | // construct/destroy/copy |
---|
653 | |
---|
654 | explicit unordered_multimap( |
---|
655 | size_type n = boost::unordered_detail::default_bucket_count, |
---|
656 | const hasher &hf = hasher(), |
---|
657 | const key_equal &eql = key_equal(), |
---|
658 | const allocator_type &a = allocator_type()) |
---|
659 | : table_(n, hf, eql, a) |
---|
660 | { |
---|
661 | } |
---|
662 | |
---|
663 | explicit unordered_multimap(allocator_type const& a) |
---|
664 | : table_(boost::unordered_detail::default_bucket_count, |
---|
665 | hasher(), key_equal(), a) |
---|
666 | { |
---|
667 | } |
---|
668 | |
---|
669 | unordered_multimap(unordered_multimap const& other, |
---|
670 | allocator_type const& a) |
---|
671 | : table_(other.table_, a) |
---|
672 | { |
---|
673 | } |
---|
674 | |
---|
675 | template <class InputIt> |
---|
676 | unordered_multimap(InputIt f, InputIt l) |
---|
677 | : table_(boost::unordered_detail::initial_size(f, l), |
---|
678 | hasher(), key_equal(), allocator_type()) |
---|
679 | { |
---|
680 | table_.insert_range(f, l); |
---|
681 | } |
---|
682 | |
---|
683 | template <class InputIt> |
---|
684 | unordered_multimap(InputIt f, InputIt l, |
---|
685 | size_type n, |
---|
686 | const hasher &hf = hasher(), |
---|
687 | const key_equal &eql = key_equal()) |
---|
688 | : table_(boost::unordered_detail::initial_size(f, l, n), |
---|
689 | hf, eql, allocator_type()) |
---|
690 | { |
---|
691 | table_.insert_range(f, l); |
---|
692 | } |
---|
693 | |
---|
694 | template <class InputIt> |
---|
695 | unordered_multimap(InputIt f, InputIt l, |
---|
696 | size_type n, |
---|
697 | const hasher &hf, |
---|
698 | const key_equal &eql, |
---|
699 | const allocator_type &a) |
---|
700 | : table_(boost::unordered_detail::initial_size(f, l, n), hf, eql, a) |
---|
701 | { |
---|
702 | table_.insert_range(f, l); |
---|
703 | } |
---|
704 | |
---|
705 | ~unordered_multimap() {} |
---|
706 | |
---|
707 | #if !defined(BOOST_NO_RVALUE_REFERENCES) |
---|
708 | unordered_multimap(unordered_multimap&& other) |
---|
709 | : table_(other.table_, boost::unordered_detail::move_tag()) |
---|
710 | { |
---|
711 | } |
---|
712 | |
---|
713 | unordered_multimap(unordered_multimap&& other, allocator_type const& a) |
---|
714 | : table_(other.table_, a, boost::unordered_detail::move_tag()) |
---|
715 | { |
---|
716 | } |
---|
717 | |
---|
718 | unordered_multimap& operator=(unordered_multimap&& x) |
---|
719 | { |
---|
720 | table_.move(x.table_); |
---|
721 | return *this; |
---|
722 | } |
---|
723 | #else |
---|
724 | unordered_multimap(boost::unordered_detail::move_from< |
---|
725 | unordered_multimap<K, T, H, P, A> |
---|
726 | > other) |
---|
727 | : table_(other.source.table_, boost::unordered_detail::move_tag()) |
---|
728 | { |
---|
729 | } |
---|
730 | |
---|
731 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0593) |
---|
732 | unordered_multimap& operator=(unordered_multimap x) |
---|
733 | { |
---|
734 | table_.move(x.table_); |
---|
735 | return *this; |
---|
736 | } |
---|
737 | #endif |
---|
738 | #endif |
---|
739 | |
---|
740 | #if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST) |
---|
741 | unordered_multimap(std::initializer_list<value_type> list, |
---|
742 | size_type n = boost::unordered_detail::default_bucket_count, |
---|
743 | const hasher &hf = hasher(), |
---|
744 | const key_equal &eql = key_equal(), |
---|
745 | const allocator_type &a = allocator_type()) |
---|
746 | : table_(boost::unordered_detail::initial_size( |
---|
747 | list.begin(), list.end(), n), |
---|
748 | hf, eql, a) |
---|
749 | { |
---|
750 | table_.insert_range(list.begin(), list.end()); |
---|
751 | } |
---|
752 | |
---|
753 | unordered_multimap& operator=(std::initializer_list<value_type> list) |
---|
754 | { |
---|
755 | table_.clear(); |
---|
756 | table_.insert_range(list.begin(), list.end()); |
---|
757 | return *this; |
---|
758 | } |
---|
759 | #endif |
---|
760 | |
---|
761 | allocator_type get_allocator() const |
---|
762 | { |
---|
763 | return table_.node_alloc(); |
---|
764 | } |
---|
765 | |
---|
766 | // size and capacity |
---|
767 | |
---|
768 | bool empty() const |
---|
769 | { |
---|
770 | return table_.size_ == 0; |
---|
771 | } |
---|
772 | |
---|
773 | size_type size() const |
---|
774 | { |
---|
775 | return table_.size_; |
---|
776 | } |
---|
777 | |
---|
778 | size_type max_size() const |
---|
779 | { |
---|
780 | return table_.max_size(); |
---|
781 | } |
---|
782 | |
---|
783 | // iterators |
---|
784 | |
---|
785 | iterator begin() |
---|
786 | { |
---|
787 | return iterator(table_.begin()); |
---|
788 | } |
---|
789 | |
---|
790 | const_iterator begin() const |
---|
791 | { |
---|
792 | return const_iterator(table_.begin()); |
---|
793 | } |
---|
794 | |
---|
795 | iterator end() |
---|
796 | { |
---|
797 | return iterator(table_.end()); |
---|
798 | } |
---|
799 | |
---|
800 | const_iterator end() const |
---|
801 | { |
---|
802 | return const_iterator(table_.end()); |
---|
803 | } |
---|
804 | |
---|
805 | const_iterator cbegin() const |
---|
806 | { |
---|
807 | return const_iterator(table_.begin()); |
---|
808 | } |
---|
809 | |
---|
810 | const_iterator cend() const |
---|
811 | { |
---|
812 | return const_iterator(table_.end()); |
---|
813 | } |
---|
814 | |
---|
815 | // modifiers |
---|
816 | |
---|
817 | #if defined(BOOST_UNORDERED_STD_FORWARD) |
---|
818 | template <class... Args> |
---|
819 | iterator emplace(Args&&... args) |
---|
820 | { |
---|
821 | return iterator(table_.emplace(std::forward<Args>(args)...)); |
---|
822 | } |
---|
823 | |
---|
824 | template <class... Args> |
---|
825 | iterator emplace_hint(const_iterator, Args&&... args) |
---|
826 | { |
---|
827 | return iterator(table_.emplace(std::forward<Args>(args)...)); |
---|
828 | } |
---|
829 | #else |
---|
830 | |
---|
831 | #if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100)) |
---|
832 | iterator emplace(value_type const& v = value_type()) |
---|
833 | { |
---|
834 | return iterator(table_.emplace(v)); |
---|
835 | } |
---|
836 | |
---|
837 | iterator emplace_hint(const_iterator, |
---|
838 | value_type const& v = value_type()) |
---|
839 | { |
---|
840 | return iterator(table_.emplace(v)); |
---|
841 | } |
---|
842 | #endif |
---|
843 | |
---|
844 | #define BOOST_UNORDERED_EMPLACE(z, n, _) \ |
---|
845 | template < \ |
---|
846 | BOOST_UNORDERED_TEMPLATE_ARGS(z, n) \ |
---|
847 | > \ |
---|
848 | iterator emplace( \ |
---|
849 | BOOST_UNORDERED_FUNCTION_PARAMS(z, n) \ |
---|
850 | ) \ |
---|
851 | { \ |
---|
852 | return iterator( \ |
---|
853 | table_.emplace( \ |
---|
854 | BOOST_UNORDERED_CALL_PARAMS(z, n) \ |
---|
855 | )); \ |
---|
856 | } \ |
---|
857 | \ |
---|
858 | template < \ |
---|
859 | BOOST_UNORDERED_TEMPLATE_ARGS(z, n) \ |
---|
860 | > \ |
---|
861 | iterator emplace_hint(const_iterator, \ |
---|
862 | BOOST_UNORDERED_FUNCTION_PARAMS(z, n) \ |
---|
863 | ) \ |
---|
864 | { \ |
---|
865 | return iterator(table_.emplace( \ |
---|
866 | BOOST_UNORDERED_CALL_PARAMS(z, n) \ |
---|
867 | )); \ |
---|
868 | } |
---|
869 | |
---|
870 | BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, |
---|
871 | BOOST_UNORDERED_EMPLACE, _) |
---|
872 | |
---|
873 | #undef BOOST_UNORDERED_EMPLACE |
---|
874 | |
---|
875 | #endif |
---|
876 | |
---|
877 | iterator insert(const value_type& obj) |
---|
878 | { |
---|
879 | return iterator(table_.emplace(obj)); |
---|
880 | } |
---|
881 | |
---|
882 | iterator insert(const_iterator, const value_type& obj) |
---|
883 | { |
---|
884 | return iterator(table_.emplace(obj)); |
---|
885 | } |
---|
886 | |
---|
887 | template <class InputIt> |
---|
888 | void insert(InputIt first, InputIt last) |
---|
889 | { |
---|
890 | table_.insert_range(first, last); |
---|
891 | } |
---|
892 | |
---|
893 | #if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST) |
---|
894 | void insert(std::initializer_list<value_type> list) |
---|
895 | { |
---|
896 | table_.insert_range(list.begin(), list.end()); |
---|
897 | } |
---|
898 | #endif |
---|
899 | |
---|
900 | iterator erase(const_iterator position) |
---|
901 | { |
---|
902 | return iterator(table_.erase_return_iterator(get(position))); |
---|
903 | } |
---|
904 | |
---|
905 | size_type erase(const key_type& k) |
---|
906 | { |
---|
907 | return table_.erase_key(k); |
---|
908 | } |
---|
909 | |
---|
910 | iterator erase(const_iterator first, const_iterator last) |
---|
911 | { |
---|
912 | return iterator(table_.erase_range(get(first), get(last))); |
---|
913 | } |
---|
914 | |
---|
915 | void quick_erase(const_iterator position) |
---|
916 | { |
---|
917 | table_.erase(get(position)); |
---|
918 | } |
---|
919 | |
---|
920 | void erase_return_void(const_iterator position) |
---|
921 | { |
---|
922 | table_.erase(get(position)); |
---|
923 | } |
---|
924 | |
---|
925 | void clear() |
---|
926 | { |
---|
927 | table_.clear(); |
---|
928 | } |
---|
929 | |
---|
930 | void swap(unordered_multimap& other) |
---|
931 | { |
---|
932 | table_.swap(other.table_); |
---|
933 | } |
---|
934 | |
---|
935 | // observers |
---|
936 | |
---|
937 | hasher hash_function() const |
---|
938 | { |
---|
939 | return table_.hash_function(); |
---|
940 | } |
---|
941 | |
---|
942 | key_equal key_eq() const |
---|
943 | { |
---|
944 | return table_.key_eq(); |
---|
945 | } |
---|
946 | |
---|
947 | // lookup |
---|
948 | |
---|
949 | iterator find(const key_type& k) |
---|
950 | { |
---|
951 | return iterator(table_.find(k)); |
---|
952 | } |
---|
953 | |
---|
954 | const_iterator find(const key_type& k) const |
---|
955 | { |
---|
956 | return const_iterator(table_.find(k)); |
---|
957 | } |
---|
958 | |
---|
959 | template <class CompatibleKey, class CompatibleHash, |
---|
960 | class CompatiblePredicate> |
---|
961 | iterator find( |
---|
962 | CompatibleKey const& k, |
---|
963 | CompatibleHash const& hash, |
---|
964 | CompatiblePredicate const& eq) |
---|
965 | { |
---|
966 | return iterator(table_.find(k, hash, eq)); |
---|
967 | } |
---|
968 | |
---|
969 | template <class CompatibleKey, class CompatibleHash, |
---|
970 | class CompatiblePredicate> |
---|
971 | const_iterator find( |
---|
972 | CompatibleKey const& k, |
---|
973 | CompatibleHash const& hash, |
---|
974 | CompatiblePredicate const& eq) const |
---|
975 | { |
---|
976 | return iterator(table_.find(k, hash, eq)); |
---|
977 | } |
---|
978 | |
---|
979 | size_type count(const key_type& k) const |
---|
980 | { |
---|
981 | return table_.count(k); |
---|
982 | } |
---|
983 | |
---|
984 | std::pair<iterator, iterator> |
---|
985 | equal_range(const key_type& k) |
---|
986 | { |
---|
987 | return boost::unordered_detail::pair_cast< |
---|
988 | iterator, iterator>( |
---|
989 | table_.equal_range(k)); |
---|
990 | } |
---|
991 | |
---|
992 | std::pair<const_iterator, const_iterator> |
---|
993 | equal_range(const key_type& k) const |
---|
994 | { |
---|
995 | return boost::unordered_detail::pair_cast< |
---|
996 | const_iterator, const_iterator>( |
---|
997 | table_.equal_range(k)); |
---|
998 | } |
---|
999 | |
---|
1000 | // bucket interface |
---|
1001 | |
---|
1002 | size_type bucket_count() const |
---|
1003 | { |
---|
1004 | return table_.bucket_count_; |
---|
1005 | } |
---|
1006 | |
---|
1007 | size_type max_bucket_count() const |
---|
1008 | { |
---|
1009 | return table_.max_bucket_count(); |
---|
1010 | } |
---|
1011 | |
---|
1012 | size_type bucket_size(size_type n) const |
---|
1013 | { |
---|
1014 | return table_.bucket_size(n); |
---|
1015 | } |
---|
1016 | |
---|
1017 | size_type bucket(const key_type& k) const |
---|
1018 | { |
---|
1019 | return table_.bucket_index(k); |
---|
1020 | } |
---|
1021 | |
---|
1022 | local_iterator begin(size_type n) |
---|
1023 | { |
---|
1024 | return local_iterator(table_.bucket_begin(n)); |
---|
1025 | } |
---|
1026 | |
---|
1027 | const_local_iterator begin(size_type n) const |
---|
1028 | { |
---|
1029 | return const_local_iterator(table_.bucket_begin(n)); |
---|
1030 | } |
---|
1031 | |
---|
1032 | local_iterator end(size_type) |
---|
1033 | { |
---|
1034 | return local_iterator(); |
---|
1035 | } |
---|
1036 | |
---|
1037 | const_local_iterator end(size_type) const |
---|
1038 | { |
---|
1039 | return const_local_iterator(); |
---|
1040 | } |
---|
1041 | |
---|
1042 | const_local_iterator cbegin(size_type n) const |
---|
1043 | { |
---|
1044 | return const_local_iterator(table_.bucket_begin(n)); |
---|
1045 | } |
---|
1046 | |
---|
1047 | const_local_iterator cend(size_type) const |
---|
1048 | { |
---|
1049 | return const_local_iterator(); |
---|
1050 | } |
---|
1051 | |
---|
1052 | // hash policy |
---|
1053 | |
---|
1054 | float load_factor() const |
---|
1055 | { |
---|
1056 | return table_.load_factor(); |
---|
1057 | } |
---|
1058 | |
---|
1059 | float max_load_factor() const |
---|
1060 | { |
---|
1061 | return table_.mlf_; |
---|
1062 | } |
---|
1063 | |
---|
1064 | void max_load_factor(float m) |
---|
1065 | { |
---|
1066 | table_.max_load_factor(m); |
---|
1067 | } |
---|
1068 | |
---|
1069 | void rehash(size_type n) |
---|
1070 | { |
---|
1071 | table_.rehash(n); |
---|
1072 | } |
---|
1073 | |
---|
1074 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x0582) |
---|
1075 | friend bool operator==<K, T, H, P, A>( |
---|
1076 | unordered_multimap const&, unordered_multimap const&); |
---|
1077 | friend bool operator!=<K, T, H, P, A>( |
---|
1078 | unordered_multimap const&, unordered_multimap const&); |
---|
1079 | #endif |
---|
1080 | }; // class template unordered_multimap |
---|
1081 | |
---|
1082 | template <class K, class T, class H, class P, class A> |
---|
1083 | inline bool operator==(unordered_multimap<K, T, H, P, A> const& m1, |
---|
1084 | unordered_multimap<K, T, H, P, A> const& m2) |
---|
1085 | { |
---|
1086 | #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613)) |
---|
1087 | struct dummy { unordered_multimap<K,T,H,P,A> x; }; |
---|
1088 | #endif |
---|
1089 | return m1.table_.equals(m2.table_); |
---|
1090 | } |
---|
1091 | |
---|
1092 | template <class K, class T, class H, class P, class A> |
---|
1093 | inline bool operator!=(unordered_multimap<K, T, H, P, A> const& m1, |
---|
1094 | unordered_multimap<K, T, H, P, A> const& m2) |
---|
1095 | { |
---|
1096 | #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613)) |
---|
1097 | struct dummy { unordered_multimap<K,T,H,P,A> x; }; |
---|
1098 | #endif |
---|
1099 | return !m1.table_.equals(m2.table_); |
---|
1100 | } |
---|
1101 | |
---|
1102 | template <class K, class T, class H, class P, class A> |
---|
1103 | inline void swap(unordered_multimap<K, T, H, P, A> &m1, |
---|
1104 | unordered_multimap<K, T, H, P, A> &m2) |
---|
1105 | { |
---|
1106 | #if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x0613)) |
---|
1107 | struct dummy { unordered_multimap<K,T,H,P,A> x; }; |
---|
1108 | #endif |
---|
1109 | m1.swap(m2); |
---|
1110 | } |
---|
1111 | |
---|
1112 | } // namespace boost |
---|
1113 | |
---|
1114 | #if defined(BOOST_MSVC) |
---|
1115 | #pragma warning(pop) |
---|
1116 | #endif |
---|
1117 | |
---|
1118 | #endif // BOOST_UNORDERED_UNORDERED_MAP_HPP_INCLUDED |
---|