@@ -50,22 +50,14 @@ class graph final {
5050
5151 graph (const types::size_type n_vertices)
5252 requires (type_traits::is_default_properties_type_v<vertex_properties_type>)
53- : _vertex_properties(), _impl(n_vertices) {
54- this ->_vertices .reserve (n_vertices);
55- for (auto id : std::views::iota (constants::initial_id, n_vertices))
56- this ->_vertices .emplace_back (id, this ->_vertex_properties );
57- }
53+ : _n_vertices(n_vertices), _impl(n_vertices) {}
5854
5955 graph (const types::size_type n_vertices)
6056 requires (not type_traits::is_default_properties_type_v<vertex_properties_type>)
6157 : _impl(n_vertices) {
62- this ->_vertices .reserve (n_vertices);
6358 this ->_vertex_properties .reserve (n_vertices);
64- for (auto [id, properties] : std::views::enumerate (this ->_vertex_properties ))
65- this ->_vertices .emplace_back (
66- id,
67- *this ->_vertex_properties .emplace_back (std::make_unique<vertex_properties_type>())
68- );
59+ for (auto id : this ->vertex_ids ())
60+ this ->_vertex_properties .emplace_back ();
6961 }
7062
7163 graph (graph&&) = default ;
@@ -85,26 +77,20 @@ class graph final {
8577
8678 // --- vertex methods ---
8779
88- // TODO: return a view
89- // [[nodiscard]] gl_attr_force_inline types::iterator_range<vertex_iterator_type> vertices(
90- // ) const {
91- // return make_iterator_range(deref_cbegin(this->_vertices), deref_cend(this->_vertices));
92- // }
93-
9480 [[nodiscard]] gl_attr_force_inline auto vertices () const
9581 requires(type_traits::is_default_properties_type_v<vertex_properties_type>)
9682 {
97- return std::views::enumerate (this ->_vertex_properties )
98- | std::views::transform ([](types::id_type id, const auto & properties_ptr) {
99- return vertex_descriptor{id, *properties_ptr};
100- });
83+ return this ->vertex_ids ()
84+ | std::views::transform ([](const types::id_type id) { return vertex_descriptor{id}; });
10185 }
10286
10387 [[nodiscard]] gl_attr_force_inline auto vertices () const
10488 requires(not type_traits::is_default_properties_type_v<vertex_properties_type>)
10589 {
106- return this ->vertex_ids ()
107- | std::views::transform ([](const types::id_type id) { return vertex_descriptor{id}; });
90+ return std::views::enumerate (this ->_vertex_properties )
91+ | std::views::transform ([](types::id_type id, const auto & properties_ptr) {
92+ return vertex_descriptor{id, *properties_ptr};
93+ });
10894 }
10995
11096 [[nodiscard]] gl_attr_force_inline std::ranges::iota_view<types::id_type, types::id_type>
@@ -501,8 +487,8 @@ class graph final {
501487 if (not this ->has_edge (edge))
502488 throw std::invalid_argument (std::format (
503489 " Got invalid edge [vertices = ({}, {}) | addr = {}]" ,
504- edge.first_id (),
505- edge.second_id (),
490+ edge.first (). id (),
491+ edge.second (). id (),
506492 io::format (&edge)
507493 ));
508494 }
@@ -516,6 +502,15 @@ class graph final {
516502 std::next (std::begin (this ->_vertex_properties ), vertex_id)
517503 );
518504 this ->_n_vertices --;
505+
506+ // update vertex ids in edges
507+ // TODO: add tests
508+ for (auto id : this ->vertex_ids ()) {
509+ for (auto & edge : this ->_impl .adjacent_edges (id)) {
510+ edge->_vertices .first ._id -= (edge->_vertices .first ._id >= vertex_id);
511+ edge->_vertices .second ._id -= (edge->_vertices .second ._id >= vertex_id);
512+ }
513+ }
519514 }
520515
521516 // --- io methods ---
@@ -577,10 +572,10 @@ class graph final {
577572 if (with_edge_properties) {
578573 const auto print_incident_edges = [this , &os](const types::id_type vertex_id) {
579574 for (const auto & edge : this ->_impl .adjacent_edges (vertex_id)) {
580- if (edge.first_id () != vertex_id)
575+ if (edge.first (). id () != vertex_id)
581576 continue ; // vertex is not the source
582- os << edge.first_id () << ' ' << edge.second_id () << ' ' << edge. properties
583- << ' \n ' ;
577+ os << edge.first (). id () << ' ' << edge.second (). id () << ' '
578+ << edge. properties << ' \n ' ;
584579 }
585580 };
586581
@@ -593,9 +588,9 @@ class graph final {
593588
594589 const auto print_incident_edges = [this , &os](const types::id_type vertex_id) {
595590 for (const auto & edge : this ->_impl .adjacent_edges (vertex_id)) {
596- if (edge.first_id () != vertex_id)
591+ if (edge.first (). id () != vertex_id)
597592 continue ; // vertex is not the source
598- os << edge.first_id () << ' ' << edge.second_id () << ' \n ' ;
593+ os << edge.first (). id () << ' ' << edge.second (). id () << ' \n ' ;
599594 }
600595 };
601596
@@ -670,7 +665,7 @@ class graph final {
670665 }
671666
672667 types::size_type _n_vertices = 0uz;
673- [[no_unique_address]] vertex_properties_map_type _vertex_properties;
668+ [[no_unique_address]] vertex_properties_map_type _vertex_properties{} ;
674669 // TODO: edge properties map
675670
676671 implementation_type _impl{};
0 commit comments