-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathdynamic_graph.hpp
More file actions
1899 lines (1723 loc) · 101 KB
/
dynamic_graph.hpp
File metadata and controls
1899 lines (1723 loc) · 101 KB
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
#pragma once
#include <concepts>
#include <vector>
#include <forward_list>
#include <list>
#include <algorithm>
#include "graph/graph.hpp"
#include "container_utility.hpp"
// load_vertices(vrng, vvalue_fnc) -> [uid,vval]
//
// load_edges(erng, eproj) -> [uid,vid]
// load_edges(erng, eproj) -> [uid,vid, eval]
//
// load_edges(erng, eproj) -> [uid,vid]
// load_edges(erng, eproj) -> [uid,vid, eval]
//
// load_edges(erng, eproj, vrng, vproj) -> [uid,vid], [uid,vval]
// load_edges(erng, eproj, vrng, vproj) -> [uid,vid, eval], [uid,vval]
//
// load_edges(initializer_list<[uid,vid]>
// load_edges(initializer_list<[uid,vid,eval]>
//
// [uid,vval] <-- copyable_vertex<VId,VV>
// [uid,vid] <-- copyable_edge<VId,void>
// [uid,vid,eval] <-- copyable_edge<VId,EV>
//
namespace graph::container {
//--------------------------------------------------------------------------------------------------
// dynamic_graph traits forward references
//
template <class EV = void, class VV = void, class GV = void, class VId = uint32_t, bool Sourced = false>
struct vofl_graph_traits;
template <class EV = void, class VV = void, class GV = void, class VId = uint32_t, bool Sourced = false>
struct vol_graph_traits;
template <class EV = void, class VV = void, class GV = void, class VId = uint32_t, bool Sourced = false>
struct vov_graph_traits;
//--------------------------------------------------------------------------------------------------
// dynamic_graph forward references
//
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_edge;
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_vertex;
template <class EV = void,
class VV = void,
class GV = void,
class VId = uint32_t,
bool Sourced = false,
class Traits = vofl_graph_traits<EV, VV, GV, VId, Sourced>>
class dynamic_graph;
//--------------------------------------------------------------------------------------------------
// dynamic_graph traits declarations
//
/**
* @ingroup graph_containers
* @brief A dynamic graph traits definition for vector of forward-lists.
*
* Vertices are stored in a @c vector<V>. Edges are stored in a @c forward_list<E>.
*
* @tparam EV @showinitializer =void The edge value type. If "void" is used no user value is stored on the edge
* and calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV @showinitializer =void The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error. VV must be default-constructible.
* @tparam GV @showinitializer =void The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced @showinitializer =false Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId @showinitializer =uint32_t Vertex id type
*/
template <class EV, class VV, class GV, class VId, bool Sourced>
struct vofl_graph_traits {
using edge_value_type = EV;
using vertex_value_type = VV;
using graph_value_type = GV;
using vertex_id_type = VId;
constexpr inline const static bool sourced = Sourced;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, vofl_graph_traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, vofl_graph_traits>;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, vofl_graph_traits>;
using vertices_type = std::vector<vertex_type>;
using edges_type = std::forward_list<edge_type>;
};
/**
* @ingroup graph_containers
* @brief A dynamic graph traits definition for vector of lists.
*
* Vertices are stored in a @c vector<V>. Edges are stored in a @c list<E>.
*
* @tparam EV @showinitializer =void The edge value type. If "void" is used no user value is stored on the edge
* and calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV @showinitializer =void The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error. VV must be default-constructible.
* @tparam GV @showinitializer =void The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced @showinitializer =false Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId @showinitializer =uint32_t Vertex id type
*/
template <class EV, class VV, class GV, class VId, bool Sourced>
struct vol_graph_traits {
using edge_value_type = EV;
using vertex_value_type = VV;
using graph_value_type = GV;
using vertex_id_type = VId;
constexpr inline const static bool sourced = Sourced;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, vol_graph_traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, vol_graph_traits>;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, vol_graph_traits>;
using vertices_type = std::vector<vertex_type>;
using edges_type = std::list<edge_type>;
};
/**
* @ingroup graph_containers
* @brief A dynamic graph traits definition for vector of vectors.
*
* Vertices are stored in a @c vector<V>. Edges are stored in a @c vector<E>.
*
* @tparam EV @showinitializer =void The edge value type. If "void" is used no user value is stored on the edge
* and calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV @showinitializer =void The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error. VV must be default-constructible.
* @tparam GV @showinitializer =void The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced @showinitializer =false Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId @showinitializer =uint32_t Vertex id type
*/
template <class EV, class VV, class GV, class VId, bool Sourced>
struct vov_graph_traits {
using edge_value_type = EV;
using vertex_value_type = VV;
using graph_value_type = GV;
using vertex_id_type = VId;
constexpr inline const static bool sourced = Sourced;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, vov_graph_traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, vov_graph_traits>;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, vov_graph_traits>;
using vertices_type = std::vector<vertex_type>;
using edges_type = std::vector<edge_type>;
};
/**
* @ingroup graph_containers
* @brief A templated type alias to simplify definition of a dynamic_graph.
*
* The @c Traits type has all the types and values required for dynamic_graph
* template arguments, allowing a simpler definition that only takes the @c Traits
* struct.
*
* @tparam Traits The traits struct/class. (See examples above.)
*/
template <class Traits>
using dynamic_adjacency_graph = dynamic_graph<typename Traits::edge_value_type,
typename Traits::vertex_value_type,
typename Traits::graph_value_type,
typename Traits::vertex_id_type,
Traits::sourced,
Traits>;
//--------------------------------------------------------------------------------------------------
// dynamic_edge
//
/**
* @ingroup graph_containers
* @brief Implementation of the @c target_id(g,uv) property of a @c dynamic_edge in a @c dynamic_graph.
*
* This is one of three composable classes used to define properties for a @c dynamic_edge, the
* others being dynamic_edge_source for the source id and dynamic_edge_value for an edge value.
*
* Unlike the other composable edge property classes, this class doesn't have an option for not
* existing. The target id always exists. It could easily be merged into the dynamic_edge class,
* but was kept separate for design symmetry with the other property classes.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_edge_target {
public:
using vertex_id_type = VId;
using value_type = EV;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, Traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, Traits>;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, Traits>;
public:
constexpr dynamic_edge_target(vertex_id_type targ_id) : target_id_(targ_id) {}
constexpr dynamic_edge_target() = default;
constexpr dynamic_edge_target(const dynamic_edge_target&) = default;
constexpr dynamic_edge_target(dynamic_edge_target&&) = default;
constexpr ~dynamic_edge_target() = default;
constexpr dynamic_edge_target& operator=(const dynamic_edge_target&) = default;
constexpr dynamic_edge_target& operator=(dynamic_edge_target&&) = default;
public:
//constexpr vertex_id_type target_id() const { return target_id_; }
//constexpr vertex_id_type source_id() const { return source_id_; }
private:
vertex_id_type target_id_ = vertex_id_type();
private:
// target_id(g,uv), target(g,uv)
friend constexpr vertex_id_type target_id(const graph_type& g, const edge_type& uv) noexcept { return uv.target_id_; }
friend constexpr vertex_type& target(graph_type& g, edge_type& uv) noexcept {
return begin(vertices(g))[uv.target_id_];
}
friend constexpr const vertex_type& target(const graph_type& g, const edge_type& uv) noexcept {
return begin(vertices(g))[uv.target_id_];
}
};
/**
* @ingroup graph_containers
* @brief Implementation of the @c source_id(g,uv) property of a @c dynamic_edge in a @c dynamic_graph.
*
* This is one of three composable classes used to define properties for a @c dynamic_edge, the
* others being dynamic_edge_target for the target id and dynamic_edge_value for an edge value.
*
* A specialization for @c Sourced=false exists as an empty class so any call to @c source_id(g,uv) will
* generate a compile error.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_edge_source {
public:
using vertex_id_type = VId;
using value_type = EV;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, Traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, Traits>;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, Traits>;
public:
constexpr dynamic_edge_source(vertex_id_type source_id) : source_id_(source_id) {}
constexpr dynamic_edge_source() = default;
constexpr dynamic_edge_source(const dynamic_edge_source&) = default;
constexpr dynamic_edge_source(dynamic_edge_source&&) = default;
constexpr ~dynamic_edge_source() = default;
constexpr dynamic_edge_source& operator=(const dynamic_edge_source&) = default;
constexpr dynamic_edge_source& operator=(dynamic_edge_source&&) = default;
public:
//constexpr vertex_id_type source_id() const { return source_id_; }
//constexpr vertex_id_type source_id() const { return source_id_; }
private:
vertex_id_type source_id_ = vertex_id_type();
private:
// source_id(g,uv), source(g)
friend constexpr vertex_id_type source_id(const graph_type& g, const edge_type& uv) noexcept { return uv.source_id_; }
friend constexpr vertex_type& source(graph_type& g, edge_type& uv) noexcept {
return begin(vertices(g))[uv.source_id_];
}
friend constexpr const vertex_type& source(const graph_type& g, const edge_type& uv) noexcept {
return begin(vertices(g))[uv.source_id_];
}
};
/**
* @ingroup graph_containers
* @brief Implementation of the @c source_id(g,uv) property of a @c dynamic_edge in a @c dynamic_graph.
*
* This is one of three composable classes used to define properties for a @c dynamic_edge, the
* others being dynamic_edge_target for the target id and dynamic_edge_value for an edge value.
*
* This specialization for @c Sourced=false is a simple placeholder that doesn't define anything.
* If the user attempts to call to @c source_id(g,uv) or @c source(g,uv) will generate a compile
* error so they can resolve the incorrect usage.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced [false] Source id is not stored on the edge. Use of @c source_id(g,uv) or
* source(g,uv) will generate an error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, class Traits>
class dynamic_edge_source<EV, VV, GV, VId, false, Traits> {};
/**
* @ingroup graph_containers
* @brief Implementation of the @c edge_value(g,uv) property of a @c dynamic_edge in a @c dynamic_graph.
*
* This is one of three composable classes used to define properties for a @c dynamic_edge, the
* others being dynamic_edge_target for the target id and dynamic_edge_source for source id.
*
* A specialization for @c EV=void exists as an empty class so any call to @c edge_value(g,uv) will
* generate a compile error.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_edge_value {
public:
using value_type = EV;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, Traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, Traits>;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, Traits>;
public:
constexpr dynamic_edge_value(const value_type& value) : value_(value) {}
constexpr dynamic_edge_value(value_type&& value) : value_(std::move(value)) {}
constexpr dynamic_edge_value() = default;
constexpr dynamic_edge_value(const dynamic_edge_value&) = default;
constexpr dynamic_edge_value(dynamic_edge_value&&) = default;
constexpr ~dynamic_edge_value() = default;
constexpr dynamic_edge_value& operator=(const dynamic_edge_value&) = default;
constexpr dynamic_edge_value& operator=(dynamic_edge_value&&) = default;
public:
constexpr value_type& value() noexcept { return value_; }
constexpr const value_type& value() const noexcept { return value_; }
private:
value_type value_ = value_type();
private: // CPO properties
friend constexpr value_type& edge_value(graph_type& g, edge_type& uv) noexcept { return uv.value_; }
friend constexpr const value_type& edge_value(const graph_type& g, const edge_type& uv) noexcept { return uv.value_; }
};
/**
* @ingroup graph_containers
* @brief Implementation of the @c edge_value(g,uv) property of a @c dynamic_edge in a @c dynamic_graph.
*
* This is one of three composable classes used to define properties for a @c dynamic_edge, the
* others being dynamic_edge_target for the target id and dynamic_edge_source for source id.
*
* This specialization for @c EV=void is a simple placeholder that doesn't define anything.
* Any call to @c edge_value(g,uv) will generate a compile error so the user can resolve the
* incorrect usage.
*
* @tparam EV [void] A value type is not defined for the edge. Calling @c edge_value(g,uv)
* will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_edge_value<void, VV, GV, VId, Sourced, Traits> {};
/**
* @ingroup graph_containers
* @brief The edge class for a @c dynamic_graph.
*
* The edge is a composition of a target id, optional source id (@c Sourced) and optional edge value.
* This implementation supports a source id and edge value, where additional specializations exist
* for different combinations. The real functionality for properties is implemented in the
* @c dynamic_edge_target, @c dynamic_edge_source and @c dynamic_edge_value base classes.
*
* The following combinations of EV and Sourced are supported in @c dynamic_edge specializations.
* The only difference between them are the values taken by the constructors to match the
* inclusion/exclusion of the source Id and/or value properties.
* * < @c EV not void, @c Sourced=true > (this implementation)
* * < @c EV not void, @c Sourced=false >
* * < @c EV is void, @c Sourced=true >
* * < @c EV is void, @c Sourced=false >
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_edge
: public dynamic_edge_target<EV, VV, GV, VId, Sourced, Traits>
, public dynamic_edge_source<EV, VV, GV, VId, Sourced, Traits>
, public dynamic_edge_value<EV, VV, GV, VId, Sourced, Traits> {
public:
using base_target_type = dynamic_edge_target<EV, VV, GV, VId, Sourced, Traits>;
using base_source_type = dynamic_edge_source<EV, VV, GV, VId, Sourced, Traits>;
using base_value_type = dynamic_edge_value<EV, VV, GV, VId, Sourced, Traits>;
using vertex_id_type = VId;
using value_type = EV;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, Traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, Traits>;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, Traits>;
public:
constexpr dynamic_edge(vertex_id_type source_id, vertex_id_type target_id)
: base_target_type(target_id), base_source_type(source_id) {}
constexpr dynamic_edge(vertex_id_type source_id, vertex_id_type target_id, const value_type& val)
: base_target_type(target_id), base_source_type(source_id), base_value_type(val) {}
constexpr dynamic_edge(vertex_id_type source_id, vertex_id_type target_id, value_type&& val)
: base_target_type(target_id), base_source_type(source_id), base_value_type(move(val)) {}
constexpr dynamic_edge() = default;
constexpr dynamic_edge(const dynamic_edge&) = default;
constexpr dynamic_edge(dynamic_edge&&) = default;
constexpr ~dynamic_edge() = default;
constexpr dynamic_edge& operator=(const dynamic_edge&) = default;
constexpr dynamic_edge& operator=(dynamic_edge&&) = default;
};
/**
* @ingroup graph_containers
* @brief The edge class for a @c dynamic_graph.
*
* The edge is a composition of a target id, optional source id (@c Sourced) and optional edge value.
* This implementation supports a source id and edge value, where additional specializations exist
* for different combinations. The real functionality for properties is implemented in the
* @c dynamic_edge_target, @c dynamic_edge_source and @c dynamic_edge_value base classes.
*
* This is a specialization definition for @c EV=void and @c Sourced=true.
*
* @tparam EV [void] A value type is not defined for the edge. Calling @c edge_value(g,uv)
* will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced [true] Source id is stored on the edge. Use of @c source_id(g,uv) and
* @c source(g,uv) will return a value without error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class VV, class GV, class VId, class Traits>
class dynamic_edge<void, VV, GV, VId, true, Traits>
: public dynamic_edge_target<void, VV, GV, VId, true, Traits>
, public dynamic_edge_source<void, VV, GV, VId, true, Traits>
, public dynamic_edge_value<void, VV, GV, VId, true, Traits> {
public:
using base_target_type = dynamic_edge_target<void, VV, GV, VId, true, Traits>;
using base_source_type = dynamic_edge_source<void, VV, GV, VId, true, Traits>;
using base_value_type = dynamic_edge_value<void, VV, GV, VId, true, Traits>;
using vertex_id_type = VId;
using value_type = void;
using graph_type = dynamic_graph<void, VV, GV, VId, true, Traits>;
using vertex_type = dynamic_vertex<void, VV, GV, VId, true, Traits>;
using edge_type = dynamic_edge<void, VV, GV, VId, true, Traits>;
public:
constexpr dynamic_edge(vertex_id_type source_id, vertex_id_type target_id)
: base_target_type(target_id), base_source_type(source_id) {}
constexpr dynamic_edge() = default;
constexpr dynamic_edge(const dynamic_edge&) = default;
constexpr dynamic_edge(dynamic_edge&&) = default;
constexpr ~dynamic_edge() = default;
constexpr dynamic_edge& operator=(const dynamic_edge&) = default;
constexpr dynamic_edge& operator=(dynamic_edge&&) = default;
};
/**
* @ingroup graph_containers
* @brief The edge class for a @c dynamic_graph.
*
* The edge is a composition of a target id, optional source id (@c Sourced) and optional edge value.
* This implementation supports a source id and edge value, where additional specializations exist
* for different combinations. The real functionality for properties is implemented in the
* @c dynamic_edge_target, @c dynamic_edge_source and @c dynamic_edge_value base classes.
*
* This is a specialization definition for @c EV!=void and @c Sourced=false.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced [false] Source id is not stored on the edge. Use of @c source_id(g,uv) or
* @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, class Traits>
class dynamic_edge<EV, VV, GV, VId, false, Traits>
: public dynamic_edge_target<EV, VV, GV, VId, false, Traits>
, public dynamic_edge_source<EV, VV, GV, VId, false, Traits>
, public dynamic_edge_value<EV, VV, GV, VId, false, Traits> {
public:
using base_target_type = dynamic_edge_target<EV, VV, GV, VId, false, Traits>;
using base_source_type = dynamic_edge_source<EV, VV, GV, VId, false, Traits>;
using base_value_type = dynamic_edge_value<EV, VV, GV, VId, false, Traits>;
using vertex_id_type = VId;
using value_type = EV;
using graph_type = dynamic_graph<EV, VV, GV, VId, false, Traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, false, Traits>;
using edge_type = dynamic_edge<EV, VV, GV, VId, false, Traits>;
public:
constexpr dynamic_edge(vertex_id_type targ_id) : base_target_type(targ_id) {}
constexpr dynamic_edge(vertex_id_type targ_id, const value_type& val)
: base_target_type(targ_id), base_value_type(val) {}
constexpr dynamic_edge(vertex_id_type targ_id, value_type&& val)
: base_target_type(targ_id), base_value_type(std::move(val)) {}
constexpr dynamic_edge() = default;
constexpr dynamic_edge(const dynamic_edge&) = default;
constexpr dynamic_edge(dynamic_edge&&) = default;
constexpr ~dynamic_edge() = default;
constexpr dynamic_edge& operator=(const dynamic_edge&) = default;
constexpr dynamic_edge& operator=(dynamic_edge&&) = default;
};
/**
* @ingroup graph_containers
* @brief The edge class for a @c dynamic_graph.
*
* The edge is a composition of a target id, optional source id (@c Sourced) and optional edge value.
* This implementation supports a source id and edge value, where additional specializations exist
* for different combinations. The real functionality for properties is implemented in the
* @c dynamic_edge_target, @c dynamic_edge_source and @c dynamic_edge_value base classes.
*
* This is a specialization definition for @c EV=void and @c Sourced=false.
*
* @tparam EV [void] A value type is not defined for the edge. Calling @c edge_value(g,uv)
* will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced [false] Source id is not stored on the edge. Use of @c source_id(g,uv) or
* @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class VV, class GV, class VId, class Traits>
class dynamic_edge<void, VV, GV, VId, false, Traits>
: public dynamic_edge_target<void, VV, GV, VId, false, Traits>
, public dynamic_edge_source<void, VV, GV, VId, false, Traits>
, public dynamic_edge_value<void, VV, GV, VId, false, Traits> {
public:
using base_target_type = dynamic_edge_target<void, VV, GV, VId, false, Traits>;
using vertex_id_type = VId;
using value_type = void;
using graph_type = dynamic_graph<void, VV, GV, VId, false, Traits>;
using vertex_type = dynamic_vertex<void, VV, GV, VId, false, Traits>;
using edge_type = dynamic_edge<void, VV, GV, VId, false, Traits>;
public:
constexpr dynamic_edge(vertex_id_type target_id) : base_target_type(target_id) {}
constexpr dynamic_edge() = default;
constexpr dynamic_edge(const dynamic_edge&) = default;
constexpr dynamic_edge(dynamic_edge&&) = default;
constexpr ~dynamic_edge() = default;
constexpr dynamic_edge& operator=(const dynamic_edge&) = default;
constexpr dynamic_edge& operator=(dynamic_edge&&) = default;
};
//--------------------------------------------------------------------------------------------------
// dynamic_vertex
//
/**
* @ingroup graph_containers
* @brief Base implementation of a vertex that provides access to outgoing edges on the vertex.
*
* Edges are stored in a container on the vertex.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_vertex_base {
public:
using vertex_id_type = VId;
using value_type = VV;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, Traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, Traits>;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, Traits>;
using edges_type = typename Traits::edges_type;
using allocator_type = typename edges_type::allocator_type;
public:
constexpr dynamic_vertex_base() = default;
constexpr dynamic_vertex_base(const dynamic_vertex_base&) = default;
constexpr dynamic_vertex_base(dynamic_vertex_base&&) = default;
constexpr ~dynamic_vertex_base() = default;
constexpr dynamic_vertex_base& operator=(const dynamic_vertex_base&) = default;
constexpr dynamic_vertex_base& operator=(dynamic_vertex_base&&) = default;
constexpr dynamic_vertex_base(allocator_type alloc) : edges_(alloc) {}
public:
constexpr edges_type& edges() noexcept { return edges_; }
constexpr const edges_type& edges() const noexcept { return edges_; }
constexpr auto begin() noexcept { return edges_.begin(); }
constexpr auto begin() const noexcept { return edges_.begin(); }
constexpr auto cbegin() const noexcept { return edges_.begin(); }
constexpr auto end() noexcept { return edges_.end(); }
constexpr auto end() const noexcept { return edges_.end(); }
constexpr auto cend() const noexcept { return edges_.end(); }
private:
edges_type edges_;
private: // CPO properties
friend constexpr edges_type& edges(graph_type& g, vertex_type& u) { return u.edges_; }
friend constexpr const edges_type& edges(const graph_type& g, const vertex_type& u) { return u.edges_; }
friend constexpr typename edges_type::iterator
find_vertex_edge(graph_type& g, vertex_id_type uid, vertex_id_type vid) {
return std::ranges::find(g[uid].edges_,
[&g, &vid](const edge_type& uv) -> bool { return target_id(g, uv) == vid; });
}
friend constexpr typename edges_type::const_iterator
find_vertex_edge(const graph_type& g, vertex_id_type uid, vertex_id_type vid) {
return std::ranges::find(g[uid].edges_,
[&g, &vid](const edge_type& uv) -> bool { return target_id(g, uv) == vid; });
}
};
/**
* @ingroup graph_containers
* @brief Implementation of a vertex class of dynamic_graph that provides access to outgoing edges
* and the vertex value.
*
* A specialization of this class exists for VV=void that excludes the vertex value. When that is used,
* Any attempt to use @c vertex_value(g,u) will generate a compile error.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_vertex : public dynamic_vertex_base<EV, VV, GV, VId, Sourced, Traits> {
public:
using base_type = dynamic_vertex_base<EV, VV, GV, VId, Sourced, Traits>;
using vertex_id_type = VId;
using value_type = remove_cvref_t<VV>;
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, Traits>;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, Traits>;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, Traits>;
using edges_type = typename Traits::edges_type;
using allocator_type = typename edges_type::allocator_type;
public:
constexpr dynamic_vertex(const value_type& value, allocator_type alloc = allocator_type())
: base_type(alloc), value_(value) {}
constexpr dynamic_vertex(value_type&& value, allocator_type alloc = allocator_type())
: base_type(alloc), value_(move(value)) {}
constexpr dynamic_vertex(allocator_type alloc) : base_type(alloc) {}
constexpr dynamic_vertex() = default;
constexpr dynamic_vertex(const dynamic_vertex&) = default;
constexpr dynamic_vertex(dynamic_vertex&&) = default;
constexpr ~dynamic_vertex() = default;
constexpr dynamic_vertex& operator=(const dynamic_vertex&) = default;
constexpr dynamic_vertex& operator=(dynamic_vertex&&) = default;
public:
using base_type::edges;
constexpr value_type& value() noexcept { return value_; }
constexpr const value_type& value() const noexcept { return value_; }
private:
value_type value_ = value_type();
private: // CPO properties
friend constexpr value_type& vertex_value(graph_type& g, vertex_type& u) { return u.value_; }
friend constexpr const value_type& vertex_value(const graph_type& g, const vertex_type& u) { return u.value_; }
};
/**
* @ingroup graph_containers
* @brief Implementation of a vertex class of dynamic_graph that provides access to outgoing edges.
*
* This is a specialization for @c VV=void that excludes the @c vertex_value(g,u) definition. When it is used,
* a compile error will be generated so the user can resolve the incorrect usage.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV [void] No user value is stored on the vertex and calling @c vertex_value(g,u)
* will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId Vertex id type
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class GV, class VId, bool Sourced, class Traits>
class dynamic_vertex<EV, void, GV, VId, Sourced, Traits>
: public dynamic_vertex_base<EV, void, GV, VId, Sourced, Traits> {
public:
using base_type = dynamic_vertex_base<EV, void, GV, VId, Sourced, Traits>;
using vertex_id_type = VId;
using value_type = void;
using graph_type = dynamic_graph<EV, void, GV, VId, Sourced, Traits>;
using vertex_type = dynamic_vertex<EV, void, GV, VId, Sourced, Traits>;
using edge_type = dynamic_edge<EV, void, GV, VId, Sourced, Traits>;
using edges_type = typename Traits::edges_type;
using allocator_type = typename edges_type::allocator_type;
public:
constexpr dynamic_vertex() = default;
constexpr dynamic_vertex(const dynamic_vertex&) = default;
constexpr dynamic_vertex(dynamic_vertex&&) = default;
constexpr ~dynamic_vertex() = default;
constexpr dynamic_vertex& operator=(const dynamic_vertex&) = default;
constexpr dynamic_vertex& operator=(dynamic_vertex&&) = default;
constexpr dynamic_vertex(allocator_type alloc) : base_type(alloc) {}
};
/**-------------------------------------------------------------------------------------------------
* @ingroup graph_containers
* @brief dynamic_graph_base defines the core implementation for a graph with a variety
* characteristics including edge, vertex and graph value types, whether edges are sourced or not,
* the vertex id type, and selection of the containers used for vertices and edges.
*
* This class includes the vertices and functions to access them, and the constructors and
* functions to load the vertices and edges into the graph.
*
* dynamic_graph provides the interface that includes or excludes (GV=void) a graph value.
* dynamic_graph_base has the core implementation for the graph.
*
* No additional space is used if the edge value type (EV) or vertex value type (VV) is void.
*
* The partition function is intended to determine the partition id for a vertex id on constructors.
* It has been added to assure the same interface as the compressed_graph, but is not implemented
* at this time.
*
* @tparam EV The edge value type. If "void" is used no user value is stored on the edge and
* calls to @c edge_value(g,uv) will generate a compile error.
* @tparam VV The vertex value type. If "void" is used no user value is stored on the vertex
* and calls to @c vertex_value(g,u) will generate a compile error.
* @tparam GV The graph value type. If "void" is used no user value is stored on the graph
* and calls to @c graph_value(g) will generate a compile error.
* @tparam Sourced Is a source vertex id stored on the edge? If false, calls to @c source_id(g,uv)
* and @c source(g,uv) will generate a compile error.
* @tparam VId The type used for the vertex id.
* @tparam Traits Defines the types for vertex and edge containers.
*/
template <class EV, class VV, class GV, class VId, bool Sourced, class Traits>
class dynamic_graph_base {
public: // types
using graph_type = dynamic_graph<EV, VV, GV, VId, Sourced, Traits>;
using graph_traits = Traits;
using partition_id_type = VId;
using partition_vector = std::vector<VId>;
using vertex_id_type = VId;
using vertex_type = dynamic_vertex<EV, VV, GV, VId, Sourced, Traits>;
using vertices_type = typename Traits::vertices_type;
using vertex_allocator_type = typename vertices_type::allocator_type;
using size_type = typename vertices_type::size_type;
using edges_type = typename Traits::edges_type;
using edge_allocator_type = typename edges_type::allocator_type;
using edge_type = dynamic_edge<EV, VV, GV, VId, Sourced, Traits>;
public: // Construction/Destruction/Assignment
constexpr dynamic_graph_base() = default;
constexpr dynamic_graph_base(const dynamic_graph_base&) = default;
constexpr dynamic_graph_base(dynamic_graph_base&&) = default;
constexpr ~dynamic_graph_base() = default;
constexpr dynamic_graph_base& operator=(const dynamic_graph_base&) = default;
constexpr dynamic_graph_base& operator=(dynamic_graph_base&&) = default;
/**
* @brief Construct an empty graph using the allocator passed.
*
* @param alloc Used to allocate vertices and edges.
*/
dynamic_graph_base(vertex_allocator_type alloc) : vertices_(alloc), partition_(alloc) { terminate_partitions(); }
/**
* @brief Construct the graph using edge and vertex ranges.
*
* The value_type of @c erng must be converted to @c copyable_edge_t<G> before it can be
* added to the graph, which is done using the @c eproj function. If the value_type of
* @c erng is already copyable_edge_t<G>, @c std::identity can be used instead. @c copyable_edge_t<G>
* will have a edge value member if an edge value type has been defined for the graph (e.g.
* @c EV is not @c void).
*
* The value_type of @c vrng must be converted to @c copyable_vertex_t<G> before it can be
* added to the graph, which is done using the @c vproj function. If the value_type of
* @c vrng is already copyable_vertex_t<G>, @c std::identity can be used instead. @c copyable_vertex_t<G>
* will have a vertex value member if a vertex value type has been defined for the graph (e.g.
* @c VV is not @c void).
*
* @tparam ERng The edge data range.
* @tparam VRng The vertex data range.
* @tparam EProj A function type to convert the ERng value_type to copyable_edge_t<G>.
* If ERng value_type is already copyable_vertex_t<G>, identity can be used.
* @tparam VProj A projection function type to convert the VRng value_type to copyable_vertex_t<G>
* If VRng value_type is already copyable_vertex_t<G>, identify can be used.
* @tparam PartRng Range of starting vertex Ids for each partition
*
* @param erng The edge values.
* @param vrng The vertex values.
* @param eproj The projection function that converts the ERng value_type to copyable_edge_t<G>,
* or identity() if ERng value_type is already copyable_edge_t<G>.
* @param vproj The projection function that converts the ERng value_type to copyable_vertex_t<G>, or
* identity() if VRng value_type is already copyable_vertex_t<G>.
* @param partition_start_ids Range of starting vertex ids for each partition. If empty, all vertices are in partition 0.
* @param alloc The allocator used for vertices and edges containers.
*/
template <class ERng, class VRng, forward_range PartRng, class EProj = identity, class VProj = identity>
requires convertible_to<range_value_t<PartRng>, VId>
dynamic_graph_base(ERng&& erng,
VRng&& vrng,
EProj eproj,
VProj vproj,
const PartRng& partition_start_ids = std::vector<VId>(),
vertex_allocator_type alloc = vertex_allocator_type())
: vertices_(alloc), partition_(partition_start_ids, alloc) {
load_vertices(vrng, vproj);
// TODO: not all partitions may be created properly when vertex_ids in edges don't include vertices in all partitions
load_edges(vertices_.size(), 0, erng, eproj);
terminate_partitions();
}
/**
* @brief Construct the graph using an edge range.
*
* The value_type of @c erng must be converted to @c copyable_edge_t<G> before it can be
* added to the graph, which is done using the @c eproj function. If the value_type of
* @c erng is already copyable_edge_t<G>, @c std::identity can be used instead. @c copyable_edge_t<G>
* will have a edge value member if an edge value type has been defined for the graph (e.g.
* @c EV is not @c void).
*
* Edges are scanned to determine the largest vertex id needed.
*
* If vertices have a user-defined value (e.g. VV not void), the value must be default-constructable.
*
* @tparam ERng The edge data range.
* @tparam EProj A projection function type to convert the ERng value_type to copyable_edge_t<G>.
* If ERng value_type is already copyable_vertex_t<G>, identity can be used.
* @tparam PartRng Range of starting vertex Ids for each partition
*
* @param erng The edge values.
* @param eproj The projection function that converts the ERng value_type to copyable_edge_t<G>,
* or identity() if ERng value_type is already copyable_edge_t<G>.
* @param partition_start_ids Range of starting vertex ids for each partition. If empty, all vertices are in partition 0.
* @param alloc The allocator used for vertices and edges containers.
*/
template <class ERng, forward_range PartRng, class EProj = identity>
requires convertible_to<range_value_t<PartRng>, VId>
dynamic_graph_base(ERng&& erng,
EProj eproj,
const PartRng& partition_start_ids = std::vector<VId>(),
vertex_allocator_type alloc = vertex_allocator_type())
: vertices_(alloc), partition_(partition_start_ids, alloc) {
load_edges(move(erng), eproj);
terminate_partitions();
}
/**
* @brief Construct the graph using a vertex count and an edge range.
*
* The value_type of @c erng must be converted to @c copyable_edge_t<G> before it can be
* added to the graph, which is done using the @c eproj function. If the value_type of
* @c erng is already copyable_edge_t<G>, @c std::identity can be used instead. @c copyable_edge_t<G>
* will have a edge value member if an edge value type has been defined for the graph (e.g.
* @c EV is not @c void).
*
* Edges are NOT scanned to determine the largest vertex id needed.
*
* If vertices have a user-defined value (e.g. VV not void), the value must be default-constructable.
*
* @tparam ERng The edge data range.
* @tparam EProj A function type to convert the ERng value_type to copyable_edge_t<G>.
* If ERng value_type is already copyable_vertex_t<G>, identity can be used.
* @tparam PartRng Range of starting vertex Ids for each partition
*
* @param vertex_count The number of vertices to create.
* @param erng The edge values.
* @param eproj A function that converts the ERng value_type to copyable_edge_t<G>,
* or identity() if ERng value_type is already copyable_edge_t<G>.
* @param partition_start_ids Range of starting vertex ids for each partition. If empty, all vertices are in partition 0.
* @param alloc The allocator used for vertices and edges containers.
*/
template <class ERng, forward_range PartRng, class EProj = identity>
requires convertible_to<range_value_t<PartRng>, VId>
dynamic_graph_base(size_type vertex_count,
ERng&& erng,
EProj eproj,
const PartRng& partition_start_ids = std::vector<VId>(),
vertex_allocator_type alloc = vertex_allocator_type())
: vertices_(alloc), partition_(partition_start_ids, alloc) {
load_edges(vertex_count, 0, move(erng), eproj);
terminate_partitions();
}
/**
* @brief Construct the graph using a intializer list of copyable edges.
*
* If vertices have a user-defined value (e.g. VV not void), the value must be default-constructable.
*
* @param il The initializer list of copyable edge values.
* @param alloc The allocator to use for the vertices and edges containers.
*/
dynamic_graph_base(const std::initializer_list<copyable_edge_t<VId, EV>>& il,
edge_allocator_type alloc = edge_allocator_type())
: vertices_(alloc), partition_(alloc) {
size_t last_id = 0;
for (auto&& e : il)
last_id = max(last_id, static_cast<size_t>(max(e.source_id, e.target_id)));
resize_vertices(last_id + 1);