-
Notifications
You must be signed in to change notification settings - Fork 47
/
concurrent_unordered_map.h
executable file
·1400 lines (1298 loc) · 64.8 KB
/
concurrent_unordered_map.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***
* ==++==
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* ==--==
* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*
* concurrent_unordered_map.h
*
* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
****/
#pragma once
#include <utility>
#include "internal_concurrent_hash.h"
#define _PPL_CONTAINER
#if !(defined (_M_X64) || defined (_M_IX86) || defined (_M_ARM) || defined (_M_ARM64))
#error ERROR: Concurrency Runtime is supported only on X64, X86, ARM, and ARM64 architectures.
#endif /* !(defined (_M_X64) || defined (_M_IX86) || defined (_M_ARM) || defined (_M_ARM64)) */
#if defined (_M_CEE)
#error ERROR: Concurrency Runtime is not supported when compiling /clr.
#endif /* defined (_M_CEE) */
#pragma pack(push,_CRT_PACKING)
#pragma warning(push)
#pragma warning(disable: 4100) // Unreferenced formal parameter - needed for document generation
namespace Concurrency
{
namespace details
{
// Template class for hash map traits
template<typename _Key_type, typename _Element_type, typename _Key_comparator, typename _Allocator_type, bool _Allow_multimapping>
class _Concurrent_unordered_map_traits : public ::std::_Container_base
{
public:
typedef ::std::pair<const _Key_type, _Element_type> value_type;
typedef _Key_type key_type;
typedef _Key_comparator _Key_compare;
typedef typename ::std::allocator_traits<_Allocator_type>::template rebind_alloc<value_type> allocator_type;
enum
{
_M_allow_multimapping = _Allow_multimapping
};
_Concurrent_unordered_map_traits() : _M_comparator()
{
}
_Concurrent_unordered_map_traits(const _Key_compare& _Traits) : _M_comparator(_Traits)
{
}
class _Value_compare
{
friend class _Concurrent_unordered_map_traits<_Key_type, _Element_type, _Key_comparator, _Allocator_type, _Allow_multimapping>;
public:
typedef value_type first_argument_type;
typedef value_type second_argument_type;
typedef bool result_type;
bool operator()(const value_type& _Left, const value_type& _Right) const
{
return (_M_comparator(_Left.first, _Right.first));
}
_Value_compare(const _Key_compare& _Traits) : _M_comparator(_Traits)
{
}
protected:
_Key_compare _M_comparator; // the comparator predicate for keys
};
template<class _Type1, class _Type2>
static const _Type1& _Key_function(const ::std::pair<_Type1, _Type2>& _Value)
{
return (_Value.first);
}
_Key_compare _M_comparator; // the comparator predicate for keys
};
} // namespace details;
/// <summary>
/// The <c>concurrent_unordered_map</c> class is a concurrency-safe container that controls a varying-length sequence of
/// elements of type <c>std::pair<const _Key_type, _Element_type></c>. The sequence is represented in a way that enables concurrency-safe
/// append, element access, iterator access, and iterator traversal operations.
/// </summary>
/// <typeparam name="_Key_type">
/// The key type.
/// </typeparam>
/// <typeparam name="_Element_type">
/// The mapped type.
/// </typeparam>
/// <typeparam name="_Hasher">
/// The hash function object type. This argument is optional and the default value is
/// <c>std::hash<</c><typeparamref name="_Key_type"/><c>></c>.
/// </typeparam>
/// <typeparam name="_Key_equality">
/// The equality comparison function object type. This argument is optional and the default value is
/// <c>std::equal_to<</c><typeparamref name="_Key_type"/><c>></c>.
/// </typeparam>
/// <typeparam name="_Allocator_type">
/// The type that represents the stored allocator object that encapsulates details about the allocation and
/// deallocation of memory for the concurrent unordered map. This argument is optional and the default value is
/// <c>std::allocator<std::pair<</c><typeparamref name="_Key_type"/>, <typeparamref name="_Element_type"/><c>>></c>.
/// </typeparam>
/// <remarks>
/// For detailed information on the <c>concurrent_unordered_map</c> class, see <see cref="Parallel Containers and Objects"/>.
/// </remarks>
/// <seealso cref="Parallel Containers and Objects"/>
/**/
template <typename _Key_type, typename _Element_type, typename _Hasher = ::std::hash<_Key_type>, typename _Key_equality = ::std::equal_to<_Key_type>, typename _Allocator_type = ::std::allocator<::std::pair<const _Key_type, _Element_type>>>
class concurrent_unordered_map : public details::_Concurrent_hash< details::_Concurrent_unordered_map_traits<_Key_type, _Element_type, details::_Hash_compare<_Key_type, _Hasher, _Key_equality>, _Allocator_type, false>>
{
public:
// Base type definitions
typedef concurrent_unordered_map<_Key_type, _Element_type, _Hasher, _Key_equality, _Allocator_type> _Mytype;
typedef details::_Hash_compare<_Key_type, _Hasher, _Key_equality> _Key_compare;
typedef details::_Concurrent_hash< details::_Concurrent_unordered_map_traits<_Key_type, _Element_type, _Key_compare, _Allocator_type, false>> _Mybase;
/// <summary>
/// The type of an ordering key.
/// </summary>
/**/
typedef _Key_type key_type;
/// <summary>
/// The type of an element.
/// </summary>
/**/
typedef typename _Mybase::value_type value_type;
/// <summary>
/// The type of a mapped value associated with each key.
/// </summary>
/**/
typedef _Element_type mapped_type;
/// <summary>
/// The type of the hash function.
/// </summary>
/**/
typedef _Hasher hasher;
/// <summary>
/// The type of the comparison function.
/// </summary>
/**/
typedef _Key_equality key_equal;
/// <summary>
/// The type of an allocator for managing storage.
/// </summary>
/**/
typedef typename _Mybase::allocator_type allocator_type;
/// <summary>
/// The type of a pointer to an element.
/// </summary>
/**/
typedef typename _Mybase::pointer pointer;
/// <summary>
/// The type of a constant pointer to an element.
/// </summary>
/**/
typedef typename _Mybase::const_pointer const_pointer;
/// <summary>
/// The type of a reference to an element.
/// </summary>
/**/
typedef typename _Mybase::reference reference;
/// <summary>
/// The type of a constant reference to an element.
/// </summary>
/**/
typedef typename _Mybase::const_reference const_reference;
/// <summary>
/// The type of an unsigned distance between two elements.
/// </summary>
/**/
typedef typename _Mybase::size_type size_type;
/// <summary>
/// The type of a signed distance between two elements.
/// </summary>
/**/
typedef typename _Mybase::difference_type difference_type;
/// <summary>
/// The type of an iterator for the controlled sequence.
/// </summary>
/**/
typedef typename _Mybase::iterator iterator;
/// <summary>
/// The type of a constant iterator for the controlled sequence.
/// </summary>
/**/
typedef typename _Mybase::const_iterator const_iterator;
/// <summary>
/// The type of a bucket iterator for the controlled sequence.
/// </summary>
/**/
typedef typename _Mybase::iterator local_iterator;
/// <summary>
/// The type of a constant bucket iterator for the controlled sequence.
/// </summary>
/**/
typedef typename _Mybase::const_iterator const_local_iterator;
/// <summary>
/// Constructs a concurrent unordered map.
/// </summary>
/// <param name="_Number_of_buckets">
/// The initial number of buckets for this unordered map.
/// </param>
/// <param name="_Hasharg">
/// The hash function for this unordered map.
/// </param>
/// <param name="_Keyeqarg">
/// The equality comparison function for this unordered map.
/// </param>
/// <param name="_Allocator">
/// The allocator for this unordered map.
/// </param>
/// <remarks>
/// All constructors store an allocator object <paramref name="_Allocator"/> and initialize the unordered map.
/// <para>The first constructor specifies an empty initial map and explicitly specifies the number of buckets,
/// hash function, equality function and allocator type to be used.</para>
/// <para>The second constructor specifies an allocator for the unordered map.</para>
/// <para>The third constructor specifies values supplied by the iterator range [<paramref name="_Begin"/>, <paramref name="_End"/>).</para>
/// <para>The fourth and fifth constructors specify a copy of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// <para>The last constructor specifies a move of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// </remarks>
/**/
explicit concurrent_unordered_map(size_type _Number_of_buckets = 8, const hasher& _Hasharg = hasher(), const key_equal& _Keyeqarg = key_equal(),
const allocator_type& _Allocator = allocator_type())
: _Mybase(_Number_of_buckets, _Key_compare(_Hasharg, _Keyeqarg), _Allocator)
{
this->rehash(_Number_of_buckets);
}
/// <summary>
/// Constructs a concurrent unordered map.
/// </summary>
/// <param name="_Allocator">
/// The allocator for this unordered map.
/// </param>
/// <remarks>
/// All constructors store an allocator object <paramref name="_Allocator"/> and initialize the unordered map.
/// <para>The first constructor specifies an empty initial map and explicitly specifies the number of buckets,
/// hash function, equality function and allocator type to be used.</para>
/// <para>The second constructor specifies an allocator for the unordered map.</para>
/// <para>The third constructor specifies values supplied by the iterator range [<paramref name="_Begin"/>, <paramref name="_End"/>).</para>
/// <para>The fourth and fifth constructors specify a copy of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// <para>The last constructor specifies a move of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// </remarks>
/**/
concurrent_unordered_map(const allocator_type& _Allocator) : _Mybase(8, _Key_compare(), _Allocator)
{
}
/// <summary>
/// Constructs a concurrent unordered map.
/// </summary>
/// <typeparam name="_Iterator">
/// The type of the input iterator.
/// </typeparam>
/// <param name="_Begin">
/// The position of the first element in the range of elements to be copied.
/// </param>
/// <param name="_End">
/// The position of the first element beyond the range of elements to be copied.
/// </param>
/// <param name="_Number_of_buckets">
/// The initial number of buckets for this unordered map.
/// </param>
/// <param name="_Hasharg">
/// The hash function for this unordered map.
/// </param>
/// <param name="_Keyeqarg">
/// The equality comparison function for this unordered map.
/// </param>
/// <param name="_Allocator">
/// The allocator for this unordered map.
/// </param>
/// <remarks>
/// All constructors store an allocator object <paramref name="_Allocator"/> and initialize the unordered map.
/// <para>The first constructor specifies an empty initial map and explicitly specifies the number of buckets,
/// hash function, equality function and allocator type to be used.</para>
/// <para>The second constructor specifies an allocator for the unordered map.</para>
/// <para>The third constructor specifies values supplied by the iterator range [<paramref name="_Begin"/>, <paramref name="_End"/>).</para>
/// <para>The fourth and fifth constructors specify a copy of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// <para>The last constructor specifies a move of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// </remarks>
/**/
template <typename _Iterator>
concurrent_unordered_map(_Iterator _Begin, _Iterator _End, size_type _Number_of_buckets = 8, const hasher& _Hasharg = hasher(),
const key_equal& _Keyeqarg = key_equal(), const allocator_type& _Allocator = allocator_type())
: _Mybase(_Number_of_buckets, _Key_compare(_Hasharg, _Keyeqarg), _Allocator)
{
this->rehash(_Number_of_buckets);
for (; _Begin != _End; ++_Begin)
{
this->_Insert(*_Begin);
}
}
/// <summary>
/// Constructs a concurrent unordered map.
/// </summary>
/// <param name="_Umap">
/// The source <c>concurrent_unordered_map</c> object to copy or move elements from.
/// </param>
/// <remarks>
/// All constructors store an allocator object <paramref name="_Allocator"/> and initialize the unordered map.
/// <para>The first constructor specifies an empty initial map and explicitly specifies the number of buckets,
/// hash function, equality function and allocator type to be used.</para>
/// <para>The second constructor specifies an allocator for the unordered map.</para>
/// <para>The third constructor specifies values supplied by the iterator range [<paramref name="_Begin"/>, <paramref name="_End"/>).</para>
/// <para>The fourth and fifth constructors specify a copy of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// <para>The last constructor specifies a move of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// </remarks>
/**/
concurrent_unordered_map(const concurrent_unordered_map& _Umap) : _Mybase(_Umap)
{
}
/// <summary>
/// Constructs a concurrent unordered map.
/// </summary>
/// <param name="_Umap">
/// The source <c>concurrent_unordered_map</c> object to copy or move elements from.
/// </param>
/// <param name="_Allocator">
/// The allocator for this unordered map.
/// </param>
/// <remarks>
/// All constructors store an allocator object <paramref name="_Allocator"/> and initialize the unordered map.
/// <para>The first constructor specifies an empty initial map and explicitly specifies the number of buckets,
/// hash function, equality function and allocator type to be used.</para>
/// <para>The second constructor specifies an allocator for the unordered map.</para>
/// <para>The third constructor specifies values supplied by the iterator range [<paramref name="_Begin"/>, <paramref name="_End"/>).</para>
/// <para>The fourth and fifth constructors specify a copy of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// <para>The last constructor specifies a move of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// </remarks>
/**/
concurrent_unordered_map(const concurrent_unordered_map& _Umap, const allocator_type& _Allocator) : _Mybase(_Umap, _Allocator)
{
}
/// <summary>
/// Constructs a concurrent unordered map.
/// </summary>
/// <param name="_Umap">
/// The source <c>concurrent_unordered_map</c> object to copy or move elements from.
/// </param>
/// <remarks>
/// All constructors store an allocator object <paramref name="_Allocator"/> and initialize the unordered map.
/// <para>The first constructor specifies an empty initial map and explicitly specifies the number of buckets,
/// hash function, equality function and allocator type to be used.</para>
/// <para>The second constructor specifies an allocator for the unordered map.</para>
/// <para>The third constructor specifies values supplied by the iterator range [<paramref name="_Begin"/>, <paramref name="_End"/>).</para>
/// <para>The fourth and fifth constructors specify a copy of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// <para>The last constructor specifies a move of the concurrent unordered map <paramref name="_Umap"/>.</para>
/// </remarks>
/**/
concurrent_unordered_map(concurrent_unordered_map&& _Umap) : _Mybase(::std::move(_Umap))
{
}
/// <summary>
/// Assigns the contents of another <c>concurrent_unordered_map</c> object to this one. This method is not concurrency-safe.
/// </summary>
/// <param name="_Umap">
/// The source <c>concurrent_unordered_map</c> object.
/// </param>
/// <returns>
/// A reference to this <c>concurrent_unordered_map</c> object.
/// </returns>
/// <remarks>
/// After erasing any existing elements a concurrent vector, <c>operator=</c> either copies or moves the contents of <paramref name="_Umap"/> into
/// the concurrent vector.
/// </remarks>
/**/
concurrent_unordered_map& operator=(const concurrent_unordered_map& _Umap)
{
_Mybase::operator=(_Umap);
return (*this);
}
/// <summary>
/// Assigns the contents of another <c>concurrent_unordered_map</c> object to this one. This method is not concurrency-safe.
/// </summary>
/// <param name="_Umap">
/// The source <c>concurrent_unordered_map</c> object.
/// </param>
/// <returns>
/// A reference to this <c>concurrent_unordered_map</c> object.
/// </returns>
/// <remarks>
/// After erasing any existing elements in a concurrent vector, <c>operator=</c> either copies or moves the contents of <paramref name="_Umap"/> into
/// the concurrent vector.
/// </remarks>
/**/
concurrent_unordered_map& operator=(concurrent_unordered_map&& _Umap)
{
_Mybase::operator=(::std::move(_Umap));
return (*this);
}
/// <summary>
/// Adds elements to the <c>concurrent_unordered_map</c> object.
/// </summary>
/// <param name="_Value">
/// The value to be inserted.
/// </param>
/// <returns>
/// A pair that contains an iterator and a boolean value. See the Remarks section for more details.
/// </returns>
/// <remarks>
/// The first member function determines whether an element X exists in the sequence whose key has equivalent ordering to
/// that of <paramref name="_Value"/>. If not, it creates such an element X and initializes it with <paramref name="_Value"/>.
/// The function then determines the iterator <c>where</c> that designates X. If an insertion occurred, the function returns
/// <c>std::pair(where, true)</c>. Otherwise, it returns <c>std::pair(where, false)</c>.
/// <para>The second member function returns insert(<paramref name="_Value"/>), using <paramref name="_Where"/> as a starting
/// place within the controlled sequence to search for the insertion point.</para>
/// <para>The third member function inserts the sequence of element values from the range [<paramref name="_First"/>,
/// <paramref name="_Last"/>).</para>
/// <para>The last two member functions behave the same as the first two, except that <paramref name="_Value"/> is used to
/// construct the inserted value.</para>
/// </remarks>
/**/
::std::pair<iterator, bool> insert(const value_type& _Value)
{
return this->_Insert(_Value);
}
/// <summary>
/// Adds elements to the <c>concurrent_unordered_map</c> object.
/// </summary>
/// <param name="_Where">
/// The starting location to search for an insertion point.
/// </param>
/// <param name="_Value">
/// The value to be inserted.
/// </param>
/// <returns>
/// An iterator pointing to the insertion location of the object. If the key already exists in the container
/// an iterator pointing to the duplicate key location in the map is returned.
/// </returns>
/// <remarks>
/// The first member function determines whether an element X exists in the sequence whose key has equivalent ordering to
/// that of <paramref name="_Value"/>. If not, it creates such an element X and initializes it with <paramref name="_Value"/>.
/// The function then determines the iterator <c>where</c> that designates X. If an insertion occurred, the function returns
/// <c>std::pair(where, true)</c>. Otherwise, it returns <c>std::pair(where, false)</c>.
/// <para>The second member function returns insert(<paramref name="_Value"/>), using <paramref name="_Where"/> as a starting
/// place within the controlled sequence to search for the insertion point.</para>
/// <para>The third member function inserts the sequence of element values from the range [<paramref name="_First"/>,
/// <paramref name="_Last"/>).</para>
/// <para>The last two member functions behave the same as the first two, except that <paramref name="_Value"/> is used to
/// construct the inserted value.</para>
/// </remarks>
/**/
iterator insert(const_iterator _Where, const value_type& _Value)
{
// Current implementation ignores the hint. The method is provided for compatibility with unordered_map.
return this->_Insert(_Value).first;
}
/// <summary>
/// Adds elements to the <c>concurrent_unordered_map</c> object.
/// </summary>
/// <typeparam name="_Iterator">
/// The iterator type used for insertion.
/// </typeparam>
/// <param name="_First">
/// The beginning of the range to insert.
/// </param>
/// <param name="_Last">
/// The end of the range to insert.
/// </param>
/// <remarks>
/// The first member function determines whether an element X exists in the sequence whose key has equivalent ordering to
/// that of <paramref name="_Value"/>. If not, it creates such an element X and initializes it with <paramref name="_Value"/>.
/// The function then determines the iterator <c>where</c> that designates X. If an insertion occurred, the function returns
/// <c>std::pair(where, true)</c>. Otherwise, it returns <c>std::pair(where, false)</c>.
/// <para>The second member function returns insert(<paramref name="_Value"/>), using <paramref name="_Where"/> as a starting
/// place within the controlled sequence to search for the insertion point.</para>
/// <para>The third member function inserts the sequence of element values from the range [<paramref name="_First"/>,
/// <paramref name="_Last"/>).</para>
/// <para>The last two member functions behave the same as the first two, except that <paramref name="_Value"/> is used to
/// construct the inserted value.</para>
/// </remarks>
/**/
template<class _Iterator>
void insert(_Iterator _First, _Iterator _Last)
{
this->_Insert(_First, _Last);
}
/// <summary>
/// Adds elements to the <c>concurrent_unordered_map</c> object.
/// </summary>
/// <typeparam name="_Valty">
/// The type of the value inserted into the map.
/// </typeparam>
/// <param name="_Value">
/// The value to be inserted.
/// </param>
/// <returns>
/// A pair that contains an iterator and a boolean value. See the Remarks section for more details.
/// </returns>
/// <remarks>
/// The first member function determines whether an element X exists in the sequence whose key has equivalent ordering to
/// that of <paramref name="_Value"/>. If not, it creates such an element X and initializes it with <paramref name="_Value"/>.
/// The function then determines the iterator <c>where</c> that designates X. If an insertion occurred, the function returns
/// <c>std::pair(where, true)</c>. Otherwise, it returns <c>std::pair(where, false)</c>.
/// <para>The second member function returns insert(<paramref name="_Value"/>), using <paramref name="_Where"/> as a starting
/// place within the controlled sequence to search for the insertion point.</para>
/// <para>The third member function inserts the sequence of element values from the range [<paramref name="_First"/>,
/// <paramref name="_Last"/>).</para>
/// <para>The last two member functions behave the same as the first two, except that <paramref name="_Value"/> is used to
/// construct the inserted value.</para>
/// </remarks>
/**/
template<class _Valty>
::std::pair<iterator, bool> insert(_Valty&& _Value)
{
return this->_Insert(::std::forward<_Valty>(_Value));
}
/// <summary>
/// Adds elements to the <c>concurrent_unordered_map</c> object.
/// </summary>
/// <typeparam name="_Valty">
/// The type of the value inserted into the map.
/// </typeparam>
/// <param name="_Where">
/// The starting location to search for an insertion point.
/// </param>
/// <param name="_Value">
/// The value to be inserted.
/// </param>
/// <returns>
/// An iterator pointing to the insertion location of the object. If the key already exists in the container
/// an iterator pointing to the duplicate key location in the map is returned.
/// </returns>
/// <remarks>
/// The first member function determines whether an element X exists in the sequence whose key has equivalent ordering to
/// that of <paramref name="_Value"/>. If not, it creates such an element X and initializes it with <paramref name="_Value"/>.
/// The function then determines the iterator <c>where</c> that designates X. If an insertion occurred, the function returns
/// <c>std::pair(where, true)</c>. Otherwise, it returns <c>std::pair(where, false)</c>.
/// <para>The second member function returns insert(<paramref name="_Value"/>), using <paramref name="_Where"/> as a starting
/// place within the controlled sequence to search for the insertion point.</para>
/// <para>The third member function inserts the sequence of element values from the range [<paramref name="_First"/>,
/// <paramref name="_Last"/>).</para>
/// <para>The last two member functions behave the same as the first two, except that <paramref name="_Value"/> is used to
/// construct the inserted value.</para>
/// </remarks>
/**/
template<class _Valty>
::std::enable_if_t<!::std::is_same_v<const_iterator,
::std::remove_reference_t<_Valty>>, iterator>
insert(const_iterator _Where, _Valty&& _Value)
{
// Current implementation ignores the hint. The method is provided for compatibility with unordered_map.
return this->_Insert(::std::forward<_Valty>(_Value)).first;
}
/// <summary>
/// Removes elements from the <c>concurrent_unordered_map</c> at specified positions. This method is not concurrency-safe.
/// </summary>
/// <param name="_Where">
/// The iterator position to erase from.
/// </param>
/// <remarks>
/// The first member function removes the element of the controlled sequence pointed to by <paramref name="_Where"/>. The second
/// member function removes the elements in the range [<paramref name="_Begin"/>, <paramref name="_End"/>).
/// <para>The third member function removes the elements in the range delimited by <see cref="concurrent_unordered_map::equal_range Method">
/// concurrent_unordered_map::equal_range</see>(_Keyval). </para>
/// </remarks>
/// <returns>
/// The first two member functions return an iterator that designates the first element remaining beyond any elements removed,
/// or <see cref="concurrent_unordered_map::end Method"> concurrent_unordered_map::end</see>() if no such element exists. The third
/// member function returns the number of elements it removes.
/// </returns>
/**/
iterator unsafe_erase(const_iterator _Where)
{
return _Mybase::unsafe_erase(_Where);
}
/// <summary>
/// Removes elements from the <c>concurrent_unordered_map</c> at specified positions. This method is not concurrency-safe.
/// </summary>
/// <param name="_Begin">
/// The position of the first element in the range of elements to be erased.
/// </param>
/// <param name="_End">
/// The position of the first element beyond the range of elements to be erased.
/// </param>
/// <remarks>
/// The first member function removes the element of the controlled sequence pointed to by <paramref name="_Where"/>. The second
/// member function removes the elements in the range [<paramref name="_Begin"/>, <paramref name="_End"/>).
/// <para>The third member function removes the elements in the range delimited by <see cref="concurrent_unordered_map::equal_range Method">
/// concurrent_unordered_map::equal_range</see>(_Keyval). </para>
/// </remarks>
/// <returns>
/// The first two member functions return an iterator that designates the first element remaining beyond any elements removed,
/// or <see cref="concurrent_unordered_map::end Method"> concurrent_unordered_map::end</see>() if no such element exists. The third
/// member function returns the number of elements it removes.
/// </returns>
/**/
iterator unsafe_erase(const_iterator _Begin, const_iterator _End)
{
return _Mybase::unsafe_erase(_Begin, _End);
}
/// <summary>
/// Removes elements from the <c>concurrent_unordered_map</c> at specified positions. This method is not concurrency-safe.
/// </summary>
/// <param name="_Keyval">
/// The key value to erase.
/// </param>
/// <remarks>
/// The first member function removes the element of the controlled sequence pointed to by <paramref name="_Where"/>. The second
/// member function removes the elements in the range [<paramref name="_Begin"/>, <paramref name="_End"/>).
/// <para>The third member function removes the elements in the range delimited by <see cref="concurrent_unordered_map::equal_range Method">
/// concurrent_unordered_map::equal_range</see>(_Keyval). </para>
/// </remarks>
/// <returns>
/// The first two member functions return an iterator that designates the first element remaining beyond any elements removed,
/// or <see cref="concurrent_unordered_map::end Method"> concurrent_unordered_map::end</see>() if no such element exists. The third
/// member function returns the number of elements it removes.
/// </returns>
/**/
size_type unsafe_erase(const key_type& _Keyval)
{
return _Mybase::unsafe_erase(_Keyval);
}
/// <summary>
/// Swaps the contents of two <c>concurrent_unordered_map</c> objects. This method is not concurrency-safe.
/// </summary>
/// <param name="_Umap">
/// The <c>concurrent_unordered_map</c> object to swap with.
/// </param>
/**/
void swap(concurrent_unordered_map& _Umap)
{
_Mybase::swap(_Umap);
}
/// <summary>
/// Gets the stored hash function object.
/// </summary>
/// <returns>
/// The stored hash function object.
/// </returns>
/**/
hasher hash_function() const
{
return this->_M_comparator._M_hash_object;
}
/// <summary>
/// Gets the stored equality comparison function object.
/// </summary>
/// <returns>
/// The stored equality comparison function object.
/// </returns>
/**/
key_equal key_eq() const
{
return this->_M_comparator._M_key_compare_object;
}
/// <summary>
/// Finds or inserts an element with the specified key. This method is concurrency-safe.
/// </summary>
/// <param name="_Keyval">
/// The key value to find or insert.
/// </param>
/// <returns>
/// A reference to the data value of the found or inserted element.
/// </returns>
/// <remarks>
/// If the argument key value is not found, then it is inserted along with the default value of the data type.
/// <para> <c>operator[]</c> may be used to insert elements into a map <c>m</c> using <c>m[_Key] = DataValue;</c>, where
/// <c>DataValue</c> is the value of the <c>mapped_type</c> of the element with a key value of <c>_Key</c>.</para>
/// <para> When using <c>operator[]</c> to insert elements, the returned reference does not indicate whether an insertion
/// is changing a pre-existing element or creating a new one. The member functions <see cref="concurrent_unordered_map::find Method">
/// find</see> and <see cref="concurrent_unordered_map::insert Method">insert</see> can be used to determine whether an element
/// with a specified key is already present before an insertion.</para>
/// </remarks>
/**/
mapped_type& operator[](const key_type& _Keyval)
{
iterator _Where = this->find(_Keyval);
if (_Where == this->end())
{
_Where = this->_Insert(::std::make_pair(_Keyval, mapped_type())).first;
}
return ((*_Where).second);
}
/// <summary>
/// Finds or inserts an element with the specified key. This method is concurrency-safe.
/// </summary>
/// <param name="_Keyval">
/// The key value to find or insert.
/// </param>
/// <returns>
/// A reference to the data value of the found or inserted element.
/// </returns>
/// <remarks>
/// If the argument key value is not found, then it is inserted along with the default value of the data type.
/// <para> <c>operator[]</c> may be used to insert elements into a map <c>m</c> using <c>m[_Key] = DataValue;</c>, where
/// <c>DataValue</c> is the value of the <c>mapped_type</c> of the element with a key value of <c>_Key</c>.</para>
/// <para> When using <c>operator[]</c> to insert elements, the returned reference does not indicate whether an insertion
/// is changing a pre-existing element or creating a new one. The member functions <see cref="concurrent_unordered_map::find Method">
/// find</see> and <see cref="concurrent_unordered_map::insert Method">insert</see> can be used to determine whether an element
/// with a specified key is already present before an insertion.</para>
/// </remarks>
/**/
mapped_type& operator[](key_type && _Keyval)
{
iterator _Where = this->find(_Keyval);
if (_Where == this->end())
{
_Where = this->_Insert(::std::make_pair(::std::forward<key_type>(_Keyval), mapped_type())).first;
}
return ((*_Where).second);
}
/// <summary>
/// Finds an element in a <c>concurrent_unordered_map</c> with a specified key value.. This method is concurrency-safe.
/// </summary>
/// <param name="_Keyval">
/// The key value to find.
/// </param>
/// <returns>
/// A reference to the data value of the element found.
/// </returns>
/// <remarks>
/// If the argument key value is not found, the function throws an object of class <c>out_of_range</c>.
/// </remarks>
/**/
mapped_type& at(const key_type& _Keyval)
{
iterator _Where = this->find(_Keyval);
if (_Where == this->end())
{
_STD _Xout_of_range("invalid concurrent_unordered_map<K, T> key");
}
return ((*_Where).second);
}
/// <summary>
/// Finds an element in a <c>concurrent_unordered_map</c> with a specified key value.. This method is concurrency-safe.
/// </summary>
/// <param name="_Keyval">
/// The key value to find.
/// </param>
/// <returns>
/// A reference to the data value of the element found.
/// </returns>
/// <remarks>
/// If the argument key value is not found, the function throws an object of class <c>out_of_range</c>.
/// </remarks>
/**/
const mapped_type& at(const key_type& _Keyval) const
{
const_iterator _Where = this->find(_Keyval);
if (_Where == this->end())
{
_STD _Xout_of_range("invalid concurrent_unordered_map<K, T> key");
}
return ((*_Where).second);
}
};
/// <summary>
/// The <c>concurrent_unordered_multimap</c> class is an concurrency-safe container that controls a varying-length sequence of
/// elements of type <c>std::pair<const _Key_type, _Element_type></c>. The sequence is represented in a way that enables
/// concurrency-safe append, element access, iterator access and iterator traversal operations.
/// </summary>
/// <typeparam name="_Key_type">
/// The key type.
/// </typeparam>
/// <typeparam name="_Element_type">
/// The mapped type.
/// </typeparam>
/// <typeparam name="_Hasher">
/// The hash function object type. This argument is optional and the default value is
/// <c>std::hash<</c><typeparamref name="_Key_type"/><c>></c>.
/// </typeparam>
/// <typeparam name="_Key_equality">
/// The equality comparison function object type. This argument is optional and the default value is
/// <c>std::equal_to<</c><typeparamref name="_Key_type"/><c>></c>.
/// </typeparam>
/// <typeparam name="_Allocator_type">
/// The type that represents the stored allocator object that encapsulates details about the allocation and
/// deallocation of memory for the concurrent vector. This argument is optional and the default value is
/// <c>std::allocator<std::pair<</c><typeparamref name="_Key_type"/>, <typeparamref name="_Element_type"/><c>>></c>.
/// </typeparam>
/// <remarks>
/// For detailed information on the <c>concurrent_unordered_multimap</c> class, see <see cref="Parallel Containers and Objects"/>.
/// </remarks>
/// <seealso cref="Parallel Containers and Objects"/>
/**/
template <typename _Key_type, typename _Element_type, typename _Hasher = ::std::hash<_Key_type>, typename _Key_equality = ::std::equal_to<_Key_type>, typename _Allocator_type = ::std::allocator<::std::pair<const _Key_type, _Element_type>>>
class concurrent_unordered_multimap : public details::_Concurrent_hash< details::_Concurrent_unordered_map_traits<_Key_type, _Element_type, details::_Hash_compare<_Key_type, _Hasher, _Key_equality>, _Allocator_type, true>>
{
public:
// Base type definitions
typedef concurrent_unordered_multimap<_Key_type, _Element_type, _Hasher, _Key_equality, _Allocator_type> _Mytype;
typedef details::_Hash_compare<_Key_type, _Hasher, _Key_equality> _Key_compare;
typedef details::_Concurrent_hash< details::_Concurrent_unordered_map_traits<_Key_type, _Element_type, _Key_compare, _Allocator_type, true>> _Mybase;
/// <summary>
/// The type of an ordering key.
/// </summary>
/**/
typedef _Key_type key_type;
/// <summary>
/// The type of an element.
/// </summary>
/**/
typedef typename _Mybase::value_type value_type;
/// <summary>
/// The type of a mapped value associated with each key.
/// </summary>
/**/
typedef _Element_type mapped_type;
/// <summary>
/// The type of the hash function.
/// </summary>
/**/
typedef _Hasher hasher;
/// <summary>
/// The type of the comparison function.
/// </summary>
/**/
typedef _Key_equality key_equal;
/// <summary>
/// The type of an allocator for managing storage.
/// </summary>
/**/
typedef typename _Mybase::allocator_type allocator_type;
/// <summary>
/// The type of a pointer to an element.
/// </summary>
/**/
typedef typename _Mybase::pointer pointer;
/// <summary>
/// The type of a constant pointer to an element.
/// </summary>
/**/
typedef typename _Mybase::const_pointer const_pointer;
/// <summary>
/// The type of a reference to an element.
/// </summary>
/**/
typedef typename _Mybase::reference reference;
/// <summary>
/// The type of a constant reference to an element.
/// </summary>
/**/
typedef typename _Mybase::const_reference const_reference;
/// <summary>
/// The type of an unsigned distance between two elements.
/// </summary>
/**/
typedef typename _Mybase::size_type size_type;
/// <summary>
/// The type of a signed distance between two elements.
/// </summary>
/**/
typedef typename _Mybase::difference_type difference_type;
/// <summary>
/// The type of an iterator for the controlled sequence.
/// </summary>
/**/
typedef typename _Mybase::iterator iterator;
/// <summary>
/// The type of a constant iterator for the controlled sequence.
/// </summary>
/**/
typedef typename _Mybase::const_iterator const_iterator;
/// <summary>
/// The type of a bucket iterator for the controlled sequence.
/// </summary>
/**/
typedef typename _Mybase::iterator local_iterator;
/// <summary>
/// The type of a constant bucket iterator for the controlled sequence.
/// </summary>
/**/
typedef typename _Mybase::const_iterator const_local_iterator;
/// <summary>
/// Constructs a concurrent unordered multimap.
/// </summary>
/// <param name="_Number_of_buckets">
/// The initial number of buckets for this unordered multimap.
/// </param>
/// <param name="_Hasharg">
/// The hash function for this unordered multimap.
/// </param>
/// <param name="_Keyeqarg">
/// The equality comparison function for this unordered multimap.
/// </param>
/// <param name="_Allocator">
/// The allocator for this unordered multimap.
/// </param>
/// <remarks>
/// All constructors store an allocator object <paramref name="_Allocator"/> and initialize the unordered multimap.
/// <para>The first constructor specifies an empty initial multimap and explicitly specifies the number of buckets,
/// hash function, equality function and allocator type to be used.</para>
/// <para>The second constructor specifies an allocator for the unordered multimap.</para>
/// <para>The third constructor specifies values supplied by the iterator range [<paramref name="_Begin"/>, <paramref name="_End"/>).</para>
/// <para>The fourth and fifth constructors specify a copy of the concurrent unordered multimap <paramref name="_Umap"/>.</para>
/// <para>The last constructor specifies a move of the concurrent unordered multimap <paramref name="_Umap"/>.</para>
/// </remarks>
/**/
explicit concurrent_unordered_multimap(size_type _Number_of_buckets = 8, const hasher& _Hasharg = hasher(), const key_equal& _Keyeqarg = key_equal(),
const allocator_type& _Allocator = allocator_type())
: _Mybase(_Number_of_buckets, _Key_compare(_Hasharg, _Keyeqarg), _Allocator)
{
this->rehash(_Number_of_buckets);
}
/// <summary>
/// Constructs a concurrent unordered multimap.
/// </summary>
/// <param name="_Allocator">
/// The allocator for this unordered multimap.
/// </param>
/// <remarks>
/// All constructors store an allocator object <paramref name="_Allocator"/> and initialize the unordered multimap.
/// <para>The first constructor specifies an empty initial multimap and explicitly specifies the number of buckets,
/// hash function, equality function and allocator type to be used.</para>
/// <para>The second constructor specifies an allocator for the unordered multimap.</para>
/// <para>The third constructor specifies values supplied by the iterator range [<paramref name="_Begin"/>, <paramref name="_End"/>).</para>
/// <para>The fourth and fifth constructors specify a copy of the concurrent unordered multimap <paramref name="_Umap"/>.</para>
/// <para>The last constructor specifies a move of the concurrent unordered multimap <paramref name="_Umap"/>.</para>
/// </remarks>
/**/
concurrent_unordered_multimap(const allocator_type& _Allocator) : _Mybase(8, _Key_compare(), _Allocator)
{
}
/// <summary>
/// Constructs a concurrent unordered multimap.
/// </summary>
/// <typeparam name="_Iterator">
/// The type of the input iterator.
/// </typeparam>
/// <param name="_Begin">
/// The position of the first element in the range of elements to be copied.
/// </param>