-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path0001-modify.patch
2906 lines (2859 loc) · 111 KB
/
0001-modify.patch
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
From 4d38e89b11daa7f7ee186d1208043f081bcfdd10 Mon Sep 17 00:00:00 2001
From: sakria9 <[email protected]>
Date: Sun, 6 Nov 2022 05:44:31 +0800
Subject: [PATCH] modify
---
dspl.hpp | 124 ++-
indybuild.sh | 2 +
robin_hood.h | 2544 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 2604 insertions(+), 66 deletions(-)
create mode 100755 indybuild.sh
create mode 100644 robin_hood.h
diff --git a/dspl.hpp b/dspl.hpp
index 7673524..9ba2235 100644
--- a/dspl.hpp
+++ b/dspl.hpp
@@ -58,6 +58,8 @@
#include "graph.hpp"
#include "utils.hpp"
+#include "robin_hood.h"
+
struct Comm {
GraphElem size;
GraphWeight degree;
@@ -65,6 +67,11 @@ struct Comm {
Comm() : size(0), degree(0.0) {};
};
+using CLMAP_T = robin_hood::unordered_flat_map<GraphElem, GraphWeight>;
+using REMOTE_COMM_T = robin_hood::unordered_flat_map<GraphElem, GraphElem>;
+using REMOTE_C_INFO_T = robin_hood::unordered_flat_map<GraphElem,Comm>;
+using REMOTE_C_UPDATE_T = robin_hood::unordered_flat_map<GraphElem,Comm>;
+
struct CommInfo {
GraphElem community;
GraphElem size;
@@ -171,16 +178,15 @@ void distInitLouvain(const Graph &dg, std::vector<GraphElem> &pastComm,
distInitComm(pastComm, currComm, base);
} // distInitLouvain
-GraphElem distGetMaxIndex(const std::unordered_map<GraphElem, GraphElem> &clmap, const std::vector<GraphWeight> &counter,
+GraphElem distGetMaxIndex(const CLMAP_T &clmap,
const GraphWeight selfLoop, const std::vector<Comm> &localCinfo,
- const std::map<GraphElem,Comm> &remoteCinfo, const GraphWeight vDegree,
+ const REMOTE_C_INFO_T &remoteCinfo, const GraphWeight vDegree,
const GraphElem currSize, const GraphWeight currDegree, const GraphElem currComm,
const GraphElem base, const GraphElem bound, const GraphWeight constant)
{
- std::unordered_map<GraphElem, GraphElem>::const_iterator storedAlready;
GraphElem maxIndex = currComm;
GraphWeight curGain = 0.0, maxGain = 0.0;
- GraphWeight eix = static_cast<GraphWeight>(counter[0]) - static_cast<GraphWeight>(selfLoop);
+ GraphWeight eix = static_cast<GraphWeight>(clmap.at(currComm)) - static_cast<GraphWeight>(selfLoop);
GraphWeight ax = currDegree - vDegree;
GraphWeight eiy = 0.0, ay = 0.0;
@@ -188,7 +194,7 @@ GraphElem distGetMaxIndex(const std::unordered_map<GraphElem, GraphElem> &clmap,
GraphElem maxSize = currSize;
GraphElem size = 0;
- storedAlready = clmap.begin();
+ auto storedAlready = clmap.begin();
#ifdef DEBUG_PRINTF
assert(storedAlready != clmap.end());
#endif
@@ -202,12 +208,12 @@ GraphElem distGetMaxIndex(const std::unordered_map<GraphElem, GraphElem> &clmap,
}
else {
// is_remote, lookup map
- std::map<GraphElem,Comm>::const_iterator citer = remoteCinfo.find(storedAlready->first);
+ auto citer = remoteCinfo.find(storedAlready->first);
ay = citer->second.degree;
size = citer->second.size;
}
- eiy = counter[storedAlready->second];
+ eiy = storedAlready->second;
curGain = 2.0 * (eiy - eix) - 2.0 * vDegree * (ay - ax) * constant;
@@ -227,16 +233,12 @@ GraphElem distGetMaxIndex(const std::unordered_map<GraphElem, GraphElem> &clmap,
return maxIndex;
} // distGetMaxIndex
-GraphWeight distBuildLocalMapCounter(const GraphElem e0, const GraphElem e1, std::unordered_map<GraphElem, GraphElem> &clmap,
- std::vector<GraphWeight> &counter, const Graph &g,
+GraphWeight distBuildLocalMapCounter(const GraphElem e0, const GraphElem e1, CLMAP_T &clmap,
+ const Graph &g,
const std::vector<GraphElem> &currComm,
- const std::unordered_map<GraphElem, GraphElem> &remoteComm,
+ const REMOTE_COMM_T &remoteComm,
const GraphElem vertex, const GraphElem base, const GraphElem bound)
{
- GraphElem numUniqueClusters = 1L;
- GraphWeight selfLoop = 0;
- std::unordered_map<GraphElem, GraphElem>::const_iterator storedAlready;
-
for (GraphElem j = e0; j < e1; j++) {
const Edge &edge = g.get_edge(j);
@@ -244,14 +246,11 @@ GraphWeight distBuildLocalMapCounter(const GraphElem e0, const GraphElem e1, std
const GraphWeight &weight = edge.weight_;
GraphElem tcomm;
- if (tail_ == vertex + base)
- selfLoop += weight;
-
// is_local, direct access local std::vector<GraphElem>
if ((tail_ >= base) && (tail_ < bound))
tcomm = currComm[tail_ - base];
else { // is_remote, lookup map
- std::unordered_map<GraphElem, GraphElem>::const_iterator iter = remoteComm.find(tail_);
+ auto iter = remoteComm.find(tail_);
#ifdef DEBUG_PRINTF
assert(iter != remoteComm.end());
@@ -259,32 +258,23 @@ GraphWeight distBuildLocalMapCounter(const GraphElem e0, const GraphElem e1, std
tcomm = iter->second;
}
- storedAlready = clmap.find(tcomm);
-
- if (storedAlready != clmap.end())
- counter[storedAlready->second] += weight;
- else {
- clmap.insert(std::unordered_map<GraphElem, GraphElem>::value_type(tcomm, numUniqueClusters));
- counter.push_back(weight);
- numUniqueClusters++;
- }
+ clmap[tcomm] += weight;
}
- return selfLoop;
+ return 0;
} // distBuildLocalMapCounter
void distExecuteLouvainIteration(const GraphElem i, const Graph &dg, const std::vector<GraphElem> &currComm,
std::vector<GraphElem> &targetComm, const std::vector<GraphWeight> &vDegree,
std::vector<Comm> &localCinfo, std::vector<Comm> &localCupdate,
- const std::unordered_map<GraphElem, GraphElem> &remoteComm,
- const std::map<GraphElem,Comm> &remoteCinfo,
- std::map<GraphElem,Comm> &remoteCupdate, const GraphWeight constantForSecondTerm,
+ const REMOTE_COMM_T &remoteComm,
+ const REMOTE_C_INFO_T &remoteCinfo,
+ REMOTE_C_UPDATE_T &remoteCupdate, const GraphWeight constantForSecondTerm,
std::vector<GraphWeight> &clusterWeight, const int me)
{
GraphElem localTarget = -1;
- GraphElem e0, e1, selfLoop = 0;
- std::unordered_map<GraphElem, GraphElem> clmap;
- std::vector<GraphWeight> counter;
+ GraphElem e0, e1;
+ GraphWeight selfLoop = 0;
const GraphElem base = dg.get_base(me), bound = dg.get_bound(me);
const GraphElem cc = currComm[i];
@@ -295,29 +285,30 @@ void distExecuteLouvainIteration(const GraphElem i, const Graph &dg, const std::
// Current Community is local
if (cc >= base && cc < bound) {
- ccDegree=localCinfo[cc-base].degree;
- ccSize=localCinfo[cc-base].size;
- currCommIsLocal=true;
+ ccDegree=localCinfo[cc-base].degree;
+ ccSize=localCinfo[cc-base].size;
+ currCommIsLocal=true;
} else {
- // is remote
- std::map<GraphElem,Comm>::const_iterator citer = remoteCinfo.find(cc);
- ccDegree = citer->second.degree;
- ccSize = citer->second.size;
- currCommIsLocal=false;
+ // is remote
+ auto citer = remoteCinfo.find(cc);
+ ccDegree = citer->second.degree;
+ ccSize = citer->second.size;
+ currCommIsLocal=false;
}
dg.edge_range(i, e0, e1);
if (e0 != e1) {
- clmap.insert(std::unordered_map<GraphElem, GraphElem>::value_type(cc, 0));
- counter.push_back(0.0);
+ CLMAP_T clmap;
+ clmap.reserve(3 * (e1 - e0));
+ clmap.insert({cc, 0.0});
- selfLoop = distBuildLocalMapCounter(e0, e1, clmap, counter, dg,
+ selfLoop = distBuildLocalMapCounter(e0, e1, clmap, dg,
currComm, remoteComm, i, base, bound);
- clusterWeight[i] += counter[0];
+ clusterWeight[i] += clmap.at(cc);
- localTarget = distGetMaxIndex(clmap, counter, selfLoop, localCinfo, remoteCinfo,
+ localTarget = distGetMaxIndex(clmap, selfLoop, localCinfo, remoteCinfo,
vDegree[i], ccSize, ccDegree, cc, base, bound, constantForSecondTerm);
}
else
@@ -354,7 +345,7 @@ void distExecuteLouvainIteration(const GraphElem i, const Graph &dg, const std::
localCupdate[cc-base].size--;
// search target!
- std::map<GraphElem,Comm>::iterator iter=remoteCupdate.find(localTarget);
+ auto iter=remoteCupdate.find(localTarget);
#pragma omp atomic update
iter->second.degree += vDegree[i];
@@ -370,7 +361,7 @@ void distExecuteLouvainIteration(const GraphElem i, const Graph &dg, const std::
localCupdate[localTarget-base].size++;
// search current
- std::map<GraphElem,Comm>::iterator iter=remoteCupdate.find(cc);
+ auto iter=remoteCupdate.find(cc);
#pragma omp atomic update
iter->second.degree -= vDegree[i];
@@ -382,7 +373,7 @@ void distExecuteLouvainIteration(const GraphElem i, const Graph &dg, const std::
if ((localTarget != cc) && (localTarget != -1) && !currCommIsLocal && !targetCommIsLocal) {
// search current
- std::map<GraphElem,Comm>::iterator iter = remoteCupdate.find(cc);
+ auto iter = remoteCupdate.find(cc);
#pragma omp atomic update
iter->second.degree -= vDegree[i];
@@ -490,16 +481,16 @@ void fillRemoteCommunities(const Graph &dg, const int me, const int nprocs,
const size_t &ssz, const size_t &rsz, const std::vector<GraphElem> &ssizes,
const std::vector<GraphElem> &rsizes, const std::vector<GraphElem> &svdata,
const std::vector<GraphElem> &rvdata, const std::vector<GraphElem> &currComm,
- const std::vector<Comm> &localCinfo, std::map<GraphElem,Comm> &remoteCinfo,
- std::unordered_map<GraphElem, GraphElem> &remoteComm, std::map<GraphElem,Comm> &remoteCupdate,
+ const std::vector<Comm> &localCinfo, REMOTE_C_INFO_T &remoteCinfo,
+ REMOTE_COMM_T &remoteComm, REMOTE_C_UPDATE_T &remoteCupdate,
const MPI_Win &commwin, const std::vector<GraphElem> &disp)
#else
void fillRemoteCommunities(const Graph &dg, const int me, const int nprocs,
const size_t &ssz, const size_t &rsz, const std::vector<GraphElem> &ssizes,
const std::vector<GraphElem> &rsizes, const std::vector<GraphElem> &svdata,
const std::vector<GraphElem> &rvdata, const std::vector<GraphElem> &currComm,
- const std::vector<Comm> &localCinfo, std::map<GraphElem,Comm> &remoteCinfo,
- std::unordered_map<GraphElem, GraphElem> &remoteComm, std::map<GraphElem,Comm> &remoteCupdate)
+ const std::vector<Comm> &localCinfo, REMOTE_C_INFO_T &remoteCinfo,
+ REMOTE_COMM_T &remoteComm, REMOTE_C_UPDATE_T &remoteCupdate)
#endif
{
#if defined(USE_MPI_RMA)
@@ -511,7 +502,7 @@ void fillRemoteCommunities(const Graph &dg, const int me, const int nprocs,
#if defined(REPLACE_STL_UOSET_WITH_VECTOR)
std::vector< std::vector< GraphElem > > rcinfo(nprocs);
#else
- std::vector<std::unordered_set<GraphElem> > rcinfo(nprocs);
+ std::vector<robin_hood::unordered_set<GraphElem> > rcinfo(nprocs);
#endif
#if defined(USE_MPI_SENDRECV)
@@ -676,7 +667,7 @@ void fillRemoteCommunities(const Graph &dg, const int me, const int nprocs,
const GraphElem comm = rcdata[i];
#endif
- remoteComm.insert(std::unordered_map<GraphElem, GraphElem>::value_type(rvdata[i], comm));
+ remoteComm.insert({rvdata[i], comm});
const int tproc = dg.get_owner(comm);
if (tproc != me)
@@ -946,8 +937,8 @@ void fillRemoteCommunities(const Graph &dg, const int me, const int nprocs,
comm.size = rinfo[i].size;
comm.degree = rinfo[i].degree;
- remoteCinfo.insert(std::map<GraphElem,Comm>::value_type(ccomm, comm));
- remoteCupdate.insert(std::map<GraphElem,Comm>::value_type(ccomm, Comm()));
+ remoteCinfo.insert({ccomm, comm});
+ remoteCupdate.insert({ccomm, Comm()});
}
} // end fillRemoteCommunities
@@ -976,7 +967,7 @@ void destroyCommunityMPIType()
} // destroyCommunityMPIType
void updateRemoteCommunities(const Graph &dg, std::vector<Comm> &localCinfo,
- const std::map<GraphElem,Comm> &remoteCupdate,
+ const REMOTE_C_UPDATE_T&remoteCupdate,
const int me, const int nprocs)
{
const GraphElem base = dg.get_base(me), bound = dg.get_bound(me);
@@ -985,7 +976,7 @@ void updateRemoteCommunities(const Graph &dg, std::vector<Comm> &localCinfo,
// FIXME TODO can we use TBB::concurrent_vector instead,
// to make this parallel; first we have to get rid of maps
- for (std::map<GraphElem,Comm>::const_iterator iter = remoteCupdate.begin(); iter != remoteCupdate.end(); iter++) {
+ for (auto iter = remoteCupdate.begin(); iter != remoteCupdate.end(); iter++) {
const GraphElem i = iter->first;
const Comm &curr = iter->second;
@@ -1124,7 +1115,7 @@ void exchangeVertexReqs(const Graph &dg, size_t &ssz, size_t &rsz,
for (int i = 0; i < nprocs; i++)
omp_init_lock(&locks[i]);
#endif
- std::vector<std::unordered_set<GraphElem>> parray(nprocs);
+ std::vector<robin_hood::unordered_set<GraphElem>> parray(nprocs);
#ifdef USE_OPENMP_LOCK
#pragma omp parallel default(shared), shared(dg, locks, parray), firstprivate(me)
@@ -1175,7 +1166,7 @@ void exchangeVertexReqs(const Graph &dg, size_t &ssz, size_t &rsz,
int pproc = 0;
// TODO FIXME parallelize this loop
- for (std::vector<std::unordered_set<GraphElem>>::const_iterator iter = parray.begin(); iter != parray.end(); iter++) {
+ for (std::vector<robin_hood::unordered_set<GraphElem>>::const_iterator iter = parray.begin(); iter != parray.end(); iter++) {
ssz += iter->size();
ssizes[pproc] = iter->size();
pproc++;
@@ -1205,7 +1196,7 @@ void exchangeVertexReqs(const Graph &dg, size_t &ssz, size_t &rsz,
#if defined(USE_MPI_COLLECTIVES)
std::vector<int> scnts(nprocs), rcnts(nprocs), sdispls(nprocs), rdispls(nprocs);
- for (std::vector<std::unordered_set<GraphElem>>::const_iterator iter = parray.begin(); iter != parray.end(); iter++) {
+ for (std::vector<robin_hood::unordered_set<GraphElem>>::const_iterator iter = parray.begin(); iter != parray.end(); iter++) {
std::copy(iter->begin(), iter->end(), svdata.begin() + cpos);
scnts[pproc] = iter->size();
@@ -1235,7 +1226,7 @@ void exchangeVertexReqs(const Graph &dg, size_t &ssz, size_t &rsz,
rpos += rsizes[i];
}
- for (std::vector<std::unordered_set<GraphElem>>::const_iterator iter = parray.begin(); iter != parray.end(); iter++) {
+ for (std::vector<robin_hood::unordered_set<GraphElem>>::const_iterator iter = parray.begin(); iter != parray.end(); iter++) {
std::copy(iter->begin(), iter->end(), svdata.begin() + cpos);
if ((me != pproc) && (iter->size() > 0))
@@ -1288,8 +1279,9 @@ GraphWeight distLouvainMethod(const int me, const int nprocs, const Graph &dg,
std::vector<GraphWeight> clusterWeight;
std::vector<Comm> localCinfo, localCupdate;
- std::unordered_map<GraphElem, GraphElem> remoteComm;
- std::map<GraphElem,Comm> remoteCinfo, remoteCupdate;
+ REMOTE_COMM_T remoteComm;
+ REMOTE_C_INFO_T remoteCinfo;
+ REMOTE_C_UPDATE_T remoteCupdate;
const GraphElem nv = dg.get_lnv();
MPI_Comm gcomm = dg.get_comm();
diff --git a/indybuild.sh b/indybuild.sh
new file mode 100755
index 0000000..b1c25e3
--- /dev/null
+++ b/indybuild.sh
@@ -0,0 +1,2 @@
+/share/spack/opt/spack/linux-centos8-haswell/gcc-12.2.0/openmpi-4.1.4-237ltryogtpjqstl2lwa7l36wp3lt3fv/bin/mpic++ -std=c++17 -g -DCHECK_NUM_EDGES -DPRINT_EXTRA_NEDGES -march=native -ffast-math -mprefer-vector-width=256 -fopenmp -Ofast -c -o main.o main.cpp
+/share/spack/opt/spack/linux-centos8-haswell/gcc-12.2.0/openmpi-4.1.4-237ltryogtpjqstl2lwa7l36wp3lt3fv/bin/mpic++ main.o -fopenmp -o miniVite
diff --git a/robin_hood.h b/robin_hood.h
new file mode 100644
index 0000000..0af031f
--- /dev/null
+++ b/robin_hood.h
@@ -0,0 +1,2544 @@
+// ______ _____ ______ _________
+// ______________ ___ /_ ___(_)_______ ___ /_ ______ ______ ______ /
+// __ ___/_ __ \__ __ \__ / __ __ \ __ __ \_ __ \_ __ \_ __ /
+// _ / / /_/ /_ /_/ /_ / _ / / / _ / / // /_/ // /_/ // /_/ /
+// /_/ \____/ /_.___/ /_/ /_/ /_/ ________/_/ /_/ \____/ \____/ \__,_/
+// _/_____/
+//
+// Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20
+// https://github.com/martinus/robin-hood-hashing
+//
+// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2018-2021 Martin Ankerl <http://martin.ankerl.com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+// SOFTWARE.
+
+#ifndef ROBIN_HOOD_H_INCLUDED
+#define ROBIN_HOOD_H_INCLUDED
+
+// see https://semver.org/
+#define ROBIN_HOOD_VERSION_MAJOR 3 // for incompatible API changes
+#define ROBIN_HOOD_VERSION_MINOR 11 // for adding functionality in a backwards-compatible manner
+#define ROBIN_HOOD_VERSION_PATCH 5 // for backwards-compatible bug fixes
+
+#include <algorithm>
+#include <cstdlib>
+#include <cstring>
+#include <functional>
+#include <limits>
+#include <memory> // only to support hash of smart pointers
+#include <stdexcept>
+#include <string>
+#include <type_traits>
+#include <utility>
+#if __cplusplus >= 201703L
+# include <string_view>
+#endif
+
+// #define ROBIN_HOOD_LOG_ENABLED
+#ifdef ROBIN_HOOD_LOG_ENABLED
+# include <iostream>
+# define ROBIN_HOOD_LOG(...) \
+ std::cout << __FUNCTION__ << "@" << __LINE__ << ": " << __VA_ARGS__ << std::endl;
+#else
+# define ROBIN_HOOD_LOG(x)
+#endif
+
+// #define ROBIN_HOOD_TRACE_ENABLED
+#ifdef ROBIN_HOOD_TRACE_ENABLED
+# include <iostream>
+# define ROBIN_HOOD_TRACE(...) \
+ std::cout << __FUNCTION__ << "@" << __LINE__ << ": " << __VA_ARGS__ << std::endl;
+#else
+# define ROBIN_HOOD_TRACE(x)
+#endif
+
+// #define ROBIN_HOOD_COUNT_ENABLED
+#ifdef ROBIN_HOOD_COUNT_ENABLED
+# include <iostream>
+# define ROBIN_HOOD_COUNT(x) ++counts().x;
+namespace robin_hood {
+struct Counts {
+ uint64_t shiftUp{};
+ uint64_t shiftDown{};
+};
+inline std::ostream& operator<<(std::ostream& os, Counts const& c) {
+ return os << c.shiftUp << " shiftUp" << std::endl << c.shiftDown << " shiftDown" << std::endl;
+}
+
+static Counts& counts() {
+ static Counts counts{};
+ return counts;
+}
+} // namespace robin_hood
+#else
+# define ROBIN_HOOD_COUNT(x)
+#endif
+
+// all non-argument macros should use this facility. See
+// https://www.fluentcpp.com/2019/05/28/better-macros-better-flags/
+#define ROBIN_HOOD(x) ROBIN_HOOD_PRIVATE_DEFINITION_##x()
+
+// mark unused members with this macro
+#define ROBIN_HOOD_UNUSED(identifier)
+
+// bitness
+#if SIZE_MAX == UINT32_MAX
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BITNESS() 32
+#elif SIZE_MAX == UINT64_MAX
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BITNESS() 64
+#else
+# error Unsupported bitness
+#endif
+
+// endianess
+#ifdef _MSC_VER
+# define ROBIN_HOOD_PRIVATE_DEFINITION_LITTLE_ENDIAN() 1
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BIG_ENDIAN() 0
+#else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_LITTLE_ENDIAN() \
+ (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BIG_ENDIAN() (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#endif
+
+// inline
+#ifdef _MSC_VER
+# define ROBIN_HOOD_PRIVATE_DEFINITION_NOINLINE() __declspec(noinline)
+#else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_NOINLINE() __attribute__((noinline))
+#endif
+
+// exceptions
+#if !defined(__cpp_exceptions) && !defined(__EXCEPTIONS) && !defined(_CPPUNWIND)
+# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_EXCEPTIONS() 0
+#else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_EXCEPTIONS() 1
+#endif
+
+// count leading/trailing bits
+#if !defined(ROBIN_HOOD_DISABLE_INTRINSICS)
+# ifdef _MSC_VER
+# if ROBIN_HOOD(BITNESS) == 32
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BITSCANFORWARD() _BitScanForward
+# else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BITSCANFORWARD() _BitScanForward64
+# endif
+# include <intrin.h>
+# pragma intrinsic(ROBIN_HOOD(BITSCANFORWARD))
+# define ROBIN_HOOD_COUNT_TRAILING_ZEROES(x) \
+ [](size_t mask) noexcept -> int { \
+ unsigned long index; \
+ return ROBIN_HOOD(BITSCANFORWARD)(&index, mask) ? static_cast<int>(index) \
+ : ROBIN_HOOD(BITNESS); \
+ }(x)
+# else
+# if ROBIN_HOOD(BITNESS) == 32
+# define ROBIN_HOOD_PRIVATE_DEFINITION_CTZ() __builtin_ctzl
+# define ROBIN_HOOD_PRIVATE_DEFINITION_CLZ() __builtin_clzl
+# else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_CTZ() __builtin_ctzll
+# define ROBIN_HOOD_PRIVATE_DEFINITION_CLZ() __builtin_clzll
+# endif
+# define ROBIN_HOOD_COUNT_LEADING_ZEROES(x) ((x) ? ROBIN_HOOD(CLZ)(x) : ROBIN_HOOD(BITNESS))
+# define ROBIN_HOOD_COUNT_TRAILING_ZEROES(x) ((x) ? ROBIN_HOOD(CTZ)(x) : ROBIN_HOOD(BITNESS))
+# endif
+#endif
+
+// fallthrough
+#ifndef __has_cpp_attribute // For backwards compatibility
+# define __has_cpp_attribute(x) 0
+#endif
+#if __has_cpp_attribute(clang::fallthrough)
+# define ROBIN_HOOD_PRIVATE_DEFINITION_FALLTHROUGH() [[clang::fallthrough]]
+#elif __has_cpp_attribute(gnu::fallthrough)
+# define ROBIN_HOOD_PRIVATE_DEFINITION_FALLTHROUGH() [[gnu::fallthrough]]
+#else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_FALLTHROUGH()
+#endif
+
+// likely/unlikely
+#ifdef _MSC_VER
+# define ROBIN_HOOD_LIKELY(condition) condition
+# define ROBIN_HOOD_UNLIKELY(condition) condition
+#else
+# define ROBIN_HOOD_LIKELY(condition) __builtin_expect(condition, 1)
+# define ROBIN_HOOD_UNLIKELY(condition) __builtin_expect(condition, 0)
+#endif
+
+// detect if native wchar_t type is availiable in MSVC
+#ifdef _MSC_VER
+# ifdef _NATIVE_WCHAR_T_DEFINED
+# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 1
+# else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 0
+# endif
+#else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_HAS_NATIVE_WCHART() 1
+#endif
+
+// detect if MSVC supports the pair(std::piecewise_construct_t,...) consructor being constexpr
+#ifdef _MSC_VER
+# if _MSC_VER <= 1900
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BROKEN_CONSTEXPR() 1
+# else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BROKEN_CONSTEXPR() 0
+# endif
+#else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_BROKEN_CONSTEXPR() 0
+#endif
+
+// workaround missing "is_trivially_copyable" in g++ < 5.0
+// See https://stackoverflow.com/a/31798726/48181
+#if defined(__GNUC__) && __GNUC__ < 5
+# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__)
+#else
+# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value
+#endif
+
+// helpers for C++ versions, see https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
+#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX() __cplusplus
+#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX98() 199711L
+#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX11() 201103L
+#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX14() 201402L
+#define ROBIN_HOOD_PRIVATE_DEFINITION_CXX17() 201703L
+
+#if ROBIN_HOOD(CXX) >= ROBIN_HOOD(CXX17)
+# define ROBIN_HOOD_PRIVATE_DEFINITION_NODISCARD() [[nodiscard]]
+#else
+# define ROBIN_HOOD_PRIVATE_DEFINITION_NODISCARD()
+#endif
+
+namespace robin_hood {
+
+#if ROBIN_HOOD(CXX) >= ROBIN_HOOD(CXX14)
+# define ROBIN_HOOD_STD std
+#else
+
+// c++11 compatibility layer
+namespace ROBIN_HOOD_STD {
+template <class T>
+struct alignment_of
+ : std::integral_constant<std::size_t, alignof(typename std::remove_all_extents<T>::type)> {};
+
+template <class T, T... Ints>
+class integer_sequence {
+public:
+ using value_type = T;
+ static_assert(std::is_integral<value_type>::value, "not integral type");
+ static constexpr std::size_t size() noexcept {
+ return sizeof...(Ints);
+ }
+};
+template <std::size_t... Inds>
+using index_sequence = integer_sequence<std::size_t, Inds...>;
+
+namespace detail_ {
+template <class T, T Begin, T End, bool>
+struct IntSeqImpl {
+ using TValue = T;
+ static_assert(std::is_integral<TValue>::value, "not integral type");
+ static_assert(Begin >= 0 && Begin < End, "unexpected argument (Begin<0 || Begin<=End)");
+
+ template <class, class>
+ struct IntSeqCombiner;
+
+ template <TValue... Inds0, TValue... Inds1>
+ struct IntSeqCombiner<integer_sequence<TValue, Inds0...>, integer_sequence<TValue, Inds1...>> {
+ using TResult = integer_sequence<TValue, Inds0..., Inds1...>;
+ };
+
+ using TResult =
+ typename IntSeqCombiner<typename IntSeqImpl<TValue, Begin, Begin + (End - Begin) / 2,
+ (End - Begin) / 2 == 1>::TResult,
+ typename IntSeqImpl<TValue, Begin + (End - Begin) / 2, End,
+ (End - Begin + 1) / 2 == 1>::TResult>::TResult;
+};
+
+template <class T, T Begin>
+struct IntSeqImpl<T, Begin, Begin, false> {
+ using TValue = T;
+ static_assert(std::is_integral<TValue>::value, "not integral type");
+ static_assert(Begin >= 0, "unexpected argument (Begin<0)");
+ using TResult = integer_sequence<TValue>;
+};
+
+template <class T, T Begin, T End>
+struct IntSeqImpl<T, Begin, End, true> {
+ using TValue = T;
+ static_assert(std::is_integral<TValue>::value, "not integral type");
+ static_assert(Begin >= 0, "unexpected argument (Begin<0)");
+ using TResult = integer_sequence<TValue, Begin>;
+};
+} // namespace detail_
+
+template <class T, T N>
+using make_integer_sequence = typename detail_::IntSeqImpl<T, 0, N, (N - 0) == 1>::TResult;
+
+template <std::size_t N>
+using make_index_sequence = make_integer_sequence<std::size_t, N>;
+
+template <class... T>
+using index_sequence_for = make_index_sequence<sizeof...(T)>;
+
+} // namespace ROBIN_HOOD_STD
+
+#endif
+
+namespace detail {
+
+// make sure we static_cast to the correct type for hash_int
+#if ROBIN_HOOD(BITNESS) == 64
+using SizeT = uint64_t;
+#else
+using SizeT = uint32_t;
+#endif
+
+template <typename T>
+T rotr(T x, unsigned k) {
+ return (x >> k) | (x << (8U * sizeof(T) - k));
+}
+
+// This cast gets rid of warnings like "cast from 'uint8_t*' {aka 'unsigned char*'} to
+// 'uint64_t*' {aka 'long unsigned int*'} increases required alignment of target type". Use with
+// care!
+template <typename T>
+inline T reinterpret_cast_no_cast_align_warning(void* ptr) noexcept {
+ return reinterpret_cast<T>(ptr);
+}
+
+template <typename T>
+inline T reinterpret_cast_no_cast_align_warning(void const* ptr) noexcept {
+ return reinterpret_cast<T>(ptr);
+}
+
+// make sure this is not inlined as it is slow and dramatically enlarges code, thus making other
+// inlinings more difficult. Throws are also generally the slow path.
+template <typename E, typename... Args>
+[[noreturn]] ROBIN_HOOD(NOINLINE)
+#if ROBIN_HOOD(HAS_EXCEPTIONS)
+ void doThrow(Args&&... args) {
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
+ throw E(std::forward<Args>(args)...);
+}
+#else
+ void doThrow(Args&&... ROBIN_HOOD_UNUSED(args) /*unused*/) {
+ abort();
+}
+#endif
+
+template <typename E, typename T, typename... Args>
+T* assertNotNull(T* t, Args&&... args) {
+ if (ROBIN_HOOD_UNLIKELY(nullptr == t)) {
+ doThrow<E>(std::forward<Args>(args)...);
+ }
+ return t;
+}
+
+template <typename T>
+inline T unaligned_load(void const* ptr) noexcept {
+ // using memcpy so we don't get into unaligned load problems.
+ // compiler should optimize this very well anyways.
+ T t;
+ std::memcpy(&t, ptr, sizeof(T));
+ return t;
+}
+
+// Allocates bulks of memory for objects of type T. This deallocates the memory in the destructor,
+// and keeps a linked list of the allocated memory around. Overhead per allocation is the size of a
+// pointer.
+template <typename T, size_t MinNumAllocs = 4, size_t MaxNumAllocs = 256>
+class BulkPoolAllocator {
+public:
+ BulkPoolAllocator() noexcept = default;
+
+ // does not copy anything, just creates a new allocator.
+ BulkPoolAllocator(const BulkPoolAllocator& ROBIN_HOOD_UNUSED(o) /*unused*/) noexcept
+ : mHead(nullptr)
+ , mListForFree(nullptr) {}
+
+ BulkPoolAllocator(BulkPoolAllocator&& o) noexcept
+ : mHead(o.mHead)
+ , mListForFree(o.mListForFree) {
+ o.mListForFree = nullptr;
+ o.mHead = nullptr;
+ }
+
+ BulkPoolAllocator& operator=(BulkPoolAllocator&& o) noexcept {
+ reset();
+ mHead = o.mHead;
+ mListForFree = o.mListForFree;
+ o.mListForFree = nullptr;
+ o.mHead = nullptr;
+ return *this;
+ }
+
+ BulkPoolAllocator&
+ // NOLINTNEXTLINE(bugprone-unhandled-self-assignment,cert-oop54-cpp)
+ operator=(const BulkPoolAllocator& ROBIN_HOOD_UNUSED(o) /*unused*/) noexcept {
+ // does not do anything
+ return *this;
+ }
+
+ ~BulkPoolAllocator() noexcept {
+ reset();
+ }
+
+ // Deallocates all allocated memory.
+ void reset() noexcept {
+ while (mListForFree) {
+ T* tmp = *mListForFree;
+ ROBIN_HOOD_LOG("std::free")
+ std::free(mListForFree);
+ mListForFree = reinterpret_cast_no_cast_align_warning<T**>(tmp);
+ }
+ mHead = nullptr;
+ }
+
+ // allocates, but does NOT initialize. Use in-place new constructor, e.g.
+ // T* obj = pool.allocate();
+ // ::new (static_cast<void*>(obj)) T();
+ T* allocate() {
+ T* tmp = mHead;
+ if (!tmp) {
+ tmp = performAllocation();
+ }
+
+ mHead = *reinterpret_cast_no_cast_align_warning<T**>(tmp);
+ return tmp;
+ }
+
+ // does not actually deallocate but puts it in store.
+ // make sure you have already called the destructor! e.g. with
+ // obj->~T();
+ // pool.deallocate(obj);
+ void deallocate(T* obj) noexcept {
+ *reinterpret_cast_no_cast_align_warning<T**>(obj) = mHead;
+ mHead = obj;
+ }
+
+ // Adds an already allocated block of memory to the allocator. This allocator is from now on
+ // responsible for freeing the data (with free()). If the provided data is not large enough to
+ // make use of, it is immediately freed. Otherwise it is reused and freed in the destructor.
+ void addOrFree(void* ptr, const size_t numBytes) noexcept {
+ // calculate number of available elements in ptr
+ if (numBytes < ALIGNMENT + ALIGNED_SIZE) {
+ // not enough data for at least one element. Free and return.
+ ROBIN_HOOD_LOG("std::free")
+ std::free(ptr);
+ } else {
+ ROBIN_HOOD_LOG("add to buffer")
+ add(ptr, numBytes);
+ }
+ }
+
+ void swap(BulkPoolAllocator<T, MinNumAllocs, MaxNumAllocs>& other) noexcept {
+ using std::swap;
+ swap(mHead, other.mHead);
+ swap(mListForFree, other.mListForFree);
+ }
+
+private:
+ // iterates the list of allocated memory to calculate how many to alloc next.
+ // Recalculating this each time saves us a size_t member.
+ // This ignores the fact that memory blocks might have been added manually with addOrFree. In
+ // practice, this should not matter much.
+ ROBIN_HOOD(NODISCARD) size_t calcNumElementsToAlloc() const noexcept {
+ auto tmp = mListForFree;
+ size_t numAllocs = MinNumAllocs;
+
+ while (numAllocs * 2 <= MaxNumAllocs && tmp) {
+ auto x = reinterpret_cast<T***>(tmp);
+ tmp = *x;
+ numAllocs *= 2;
+ }
+
+ return numAllocs;
+ }
+
+ // WARNING: Underflow if numBytes < ALIGNMENT! This is guarded in addOrFree().
+ void add(void* ptr, const size_t numBytes) noexcept {
+ const size_t numElements = (numBytes - ALIGNMENT) / ALIGNED_SIZE;
+
+ auto data = reinterpret_cast<T**>(ptr);
+
+ // link free list
+ auto x = reinterpret_cast<T***>(data);
+ *x = mListForFree;
+ mListForFree = data;
+
+ // create linked list for newly allocated data
+ auto* const headT =
+ reinterpret_cast_no_cast_align_warning<T*>(reinterpret_cast<char*>(ptr) + ALIGNMENT);
+
+ auto* const head = reinterpret_cast<char*>(headT);
+
+ // Visual Studio compiler automatically unrolls this loop, which is pretty cool
+ for (size_t i = 0; i < numElements; ++i) {
+ *reinterpret_cast_no_cast_align_warning<char**>(head + i * ALIGNED_SIZE) =
+ head + (i + 1) * ALIGNED_SIZE;
+ }
+
+ // last one points to 0
+ *reinterpret_cast_no_cast_align_warning<T**>(head + (numElements - 1) * ALIGNED_SIZE) =
+ mHead;
+ mHead = headT;
+ }
+
+ // Called when no memory is available (mHead == 0).
+ // Don't inline this slow path.
+ ROBIN_HOOD(NOINLINE) T* performAllocation() {
+ size_t const numElementsToAlloc = calcNumElementsToAlloc();
+
+ // alloc new memory: [prev |T, T, ... T]
+ size_t const bytes = ALIGNMENT + ALIGNED_SIZE * numElementsToAlloc;
+ ROBIN_HOOD_LOG("std::malloc " << bytes << " = " << ALIGNMENT << " + " << ALIGNED_SIZE
+ << " * " << numElementsToAlloc)
+ add(assertNotNull<std::bad_alloc>(std::malloc(bytes)), bytes);
+ return mHead;
+ }
+
+ // enforce byte alignment of the T's
+#if ROBIN_HOOD(CXX) >= ROBIN_HOOD(CXX14)
+ static constexpr size_t ALIGNMENT =
+ (std::max)(std::alignment_of<T>::value, std::alignment_of<T*>::value);
+#else
+ static const size_t ALIGNMENT =
+ (ROBIN_HOOD_STD::alignment_of<T>::value > ROBIN_HOOD_STD::alignment_of<T*>::value)
+ ? ROBIN_HOOD_STD::alignment_of<T>::value
+ : +ROBIN_HOOD_STD::alignment_of<T*>::value; // the + is for walkarround
+#endif
+
+ static constexpr size_t ALIGNED_SIZE = ((sizeof(T) - 1) / ALIGNMENT + 1) * ALIGNMENT;
+
+ static_assert(MinNumAllocs >= 1, "MinNumAllocs");
+ static_assert(MaxNumAllocs >= MinNumAllocs, "MaxNumAllocs");
+ static_assert(ALIGNED_SIZE >= sizeof(T*), "ALIGNED_SIZE");
+ static_assert(0 == (ALIGNED_SIZE % sizeof(T*)), "ALIGNED_SIZE mod");
+ static_assert(ALIGNMENT >= sizeof(T*), "ALIGNMENT");
+
+ T* mHead{nullptr};
+ T** mListForFree{nullptr};
+};
+
+template <typename T, size_t MinSize, size_t MaxSize, bool IsFlat>
+struct NodeAllocator;
+
+// dummy allocator that does nothing
+template <typename T, size_t MinSize, size_t MaxSize>
+struct NodeAllocator<T, MinSize, MaxSize, true> {
+
+ // we are not using the data, so just free it.
+ void addOrFree(void* ptr, size_t ROBIN_HOOD_UNUSED(numBytes) /*unused*/) noexcept {
+ ROBIN_HOOD_LOG("std::free")
+ std::free(ptr);
+ }
+};
+
+template <typename T, size_t MinSize, size_t MaxSize>
+struct NodeAllocator<T, MinSize, MaxSize, false> : public BulkPoolAllocator<T, MinSize, MaxSize> {};
+
+// c++14 doesn't have is_nothrow_swappable, and clang++ 6.0.1 doesn't like it either, so I'm making
+// my own here.
+namespace swappable {
+#if ROBIN_HOOD(CXX) < ROBIN_HOOD(CXX17)
+using std::swap;
+template <typename T>
+struct nothrow {
+ static const bool value = noexcept(swap(std::declval<T&>(), std::declval<T&>()));
+};
+#else
+template <typename T>
+struct nothrow {
+ static const bool value = std::is_nothrow_swappable<T>::value;
+};
+#endif
+} // namespace swappable
+
+} // namespace detail
+
+struct is_transparent_tag {};
+
+// A custom pair implementation is used in the map because std::pair is not is_trivially_copyable,
+// which means it would not be allowed to be used in std::memcpy. This struct is copyable, which is
+// also tested.
+template <typename T1, typename T2>
+struct pair {
+ using first_type = T1;
+ using second_type = T2;
+
+ template <typename U1 = T1, typename U2 = T2,
+ typename = typename std::enable_if<std::is_default_constructible<U1>::value &&
+ std::is_default_constructible<U2>::value>::type>
+ constexpr pair() noexcept(noexcept(U1()) && noexcept(U2()))
+ : first()
+ , second() {}
+
+ // pair constructors are explicit so we don't accidentally call this ctor when we don't have to.
+ explicit constexpr pair(std::pair<T1, T2> const& o) noexcept(
+ noexcept(T1(std::declval<T1 const&>())) && noexcept(T2(std::declval<T2 const&>())))
+ : first(o.first)
+ , second(o.second) {}
+
+ // pair constructors are explicit so we don't accidentally call this ctor when we don't have to.
+ explicit constexpr pair(std::pair<T1, T2>&& o) noexcept(noexcept(
+ T1(std::move(std::declval<T1&&>()))) && noexcept(T2(std::move(std::declval<T2&&>()))))
+ : first(std::move(o.first))
+ , second(std::move(o.second)) {}
+
+ constexpr pair(T1&& a, T2&& b) noexcept(noexcept(
+ T1(std::move(std::declval<T1&&>()))) && noexcept(T2(std::move(std::declval<T2&&>()))))
+ : first(std::move(a))
+ , second(std::move(b)) {}
+
+ template <typename U1, typename U2>
+ constexpr pair(U1&& a, U2&& b) noexcept(noexcept(T1(std::forward<U1>(
+ std::declval<U1&&>()))) && noexcept(T2(std::forward<U2>(std::declval<U2&&>()))))
+ : first(std::forward<U1>(a))
+ , second(std::forward<U2>(b)) {}
+
+ template <typename... U1, typename... U2>
+ // MSVC 2015 produces error "C2476: ‘constexpr’ constructor does not initialize all members"
+ // if this constructor is constexpr
+#if !ROBIN_HOOD(BROKEN_CONSTEXPR)
+ constexpr
+#endif
+ pair(std::piecewise_construct_t /*unused*/, std::tuple<U1...> a,
+ std::tuple<U2...>
+ b) noexcept(noexcept(pair(std::declval<std::tuple<U1...>&>(),
+ std::declval<std::tuple<U2...>&>(),
+ ROBIN_HOOD_STD::index_sequence_for<U1...>(),
+ ROBIN_HOOD_STD::index_sequence_for<U2...>())))
+ : pair(a, b, ROBIN_HOOD_STD::index_sequence_for<U1...>(),
+ ROBIN_HOOD_STD::index_sequence_for<U2...>()) {
+ }
+
+ // constructor called from the std::piecewise_construct_t ctor
+ template <typename... U1, size_t... I1, typename... U2, size_t... I2>
+ pair(std::tuple<U1...>& a, std::tuple<U2...>& b, ROBIN_HOOD_STD::index_sequence<I1...> /*unused*/, ROBIN_HOOD_STD::index_sequence<I2...> /*unused*/) noexcept(
+ noexcept(T1(std::forward<U1>(std::get<I1>(
+ std::declval<std::tuple<
+ U1...>&>()))...)) && noexcept(T2(std::
+ forward<U2>(std::get<I2>(
+ std::declval<std::tuple<U2...>&>()))...)))
+ : first(std::forward<U1>(std::get<I1>(a))...)
+ , second(std::forward<U2>(std::get<I2>(b))...) {