@@ -88,8 +88,9 @@ class graph final {
8888 requires(not type_traits::is_default_properties_type_v<vertex_properties_type>)
8989 {
9090 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};
91+ | std::views::transform ([](const auto & vertex_data) {
92+ const auto & [id, properties_ptr] = vertex_data;
93+ return vertex_descriptor{static_cast <types::id_type>(id), *properties_ptr};
9394 });
9495 }
9596
@@ -115,14 +116,18 @@ class graph final {
115116 return vertex_id < this ->_n_vertices ;
116117 }
117118
119+ [[nodiscard]] gl_attr_force_inline bool has_vertex (const vertex_type& vertex) const {
120+ return this ->has_vertex (vertex.id ());
121+ }
122+
118123 vertex_type add_vertex () {
119124 this ->_impl .add_vertex ();
120125 const auto new_vertex_id = this ->_n_vertices ++;
121126
122127 if constexpr (type_traits::is_default_properties_type_v<vertex_properties_type>)
123- return vertex_descriptor{new_vertex_id, *this ->_vertex_properties .emplace_back ()};
124- else
125128 return vertex_descriptor{new_vertex_id};
129+ else
130+ return vertex_descriptor{new_vertex_id, *this ->_vertex_properties .emplace_back ()};
126131 }
127132
128133 vertex_type add_vertex (vertex_properties_type properties)
@@ -140,7 +145,7 @@ class graph final {
140145 void add_vertices (const types::size_type n) {
141146 this ->_impl .add_vertices (n);
142147 this ->_n_vertices += n;
143- if constexpr (type_traits::is_default_properties_type_v<vertex_properties_type>)
148+ if constexpr (not type_traits::is_default_properties_type_v<vertex_properties_type>)
144149 this ->_vertex_properties .resize (this ->_n_vertices );
145150 }
146151
@@ -153,17 +158,23 @@ class graph final {
153158 this ->_impl .add_vertices (n);
154159 this ->_n_vertices += n;
155160
156- if constexpr (type_traits::is_default_properties_type_v<vertex_properties_type>)
157- this ->_vertex_properties .append_range (properties_range);
161+ if constexpr (not type_traits::is_default_properties_type_v<vertex_properties_type>) {
162+ for (auto & properties : properties_range) {
163+ this ->_vertex_properties .emplace_back (
164+ std::make_unique<vertex_properties_type>(properties)
165+ );
166+ }
167+ }
158168 }
159169
160170 gl_attr_force_inline void remove_vertex (const types::size_type vertex_id) {
171+ this ->_verify_vertex_id (vertex_id);
161172 this ->_remove_vertex_impl (vertex_id);
162173 }
163174
164175 inline void remove_vertex (const vertex_type& vertex) {
165176 this ->_verify_vertex (vertex);
166- this ->_remove_vertex_impl (vertex);
177+ this ->_remove_vertex_impl (vertex. id () );
167178 }
168179
169180 template <type_traits::c_sized_range_of<types::id_type> IdRange>
@@ -197,7 +208,7 @@ class graph final {
197208
198209 // TODO: optimize
199210 for (const auto & vertex_ref : vertex_ref_set)
200- this ->_remove_vertex_impl (vertex_ref.get ());
211+ this ->_remove_vertex_impl (vertex_ref.get (). id () );
201212 }
202213
203214 [[nodiscard]] gl_attr_force_inline types::size_type in_degree (const vertex_type& vertex) const {
@@ -358,6 +369,9 @@ class graph final {
358369 ) const {
359370 using edge_ref_set = std::vector<types::const_ref_wrap<edge_type>>;
360371
372+ this ->_verify_vertex_id (first_id);
373+ this ->_verify_vertex_id (second_id);
374+
361375 if constexpr (std::same_as<implementation_tag, impl::list_t >) {
362376 return this ->_impl .get_edges (first_id, second_id);
363377 }
@@ -370,8 +384,6 @@ class graph final {
370384 [[nodiscard]] std::vector<types::const_ref_wrap<edge_type>> get_edges (
371385 const vertex_type& first, const vertex_type& second
372386 ) const {
373- this ->_verify_vertex (first);
374- this ->_verify_vertex (second);
375387 return this ->get_edges (first.id (), second.id ());
376388 }
377389
@@ -497,20 +509,21 @@ class graph final {
497509
498510 void _remove_vertex_impl (const types::id_type vertex_id) {
499511 this ->_impl .remove_vertex (vertex_id);
500- if constexpr (type_traits::is_default_properties_type_v<vertex_properties_type>)
501- this ->_vertex_properties .erase (
502- std::next (std::begin (this ->_vertex_properties ), vertex_id)
503- );
504512 this ->_n_vertices --;
505513
506514 // update vertex ids in edges
507515 // TODO: add tests
508516 for (auto id : this ->vertex_ids ()) {
509517 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);
518+ edge. _vertices .first ._id -= (edge. _vertices .first ._id > vertex_id);
519+ edge. _vertices .second ._id -= (edge. _vertices .second ._id > vertex_id);
512520 }
513521 }
522+
523+ if constexpr (not type_traits::is_default_properties_type_v<vertex_properties_type>)
524+ this ->_vertex_properties .erase (
525+ std::next (std::begin (this ->_vertex_properties ), vertex_id)
526+ );
514527 }
515528
516529 // --- io methods ---
0 commit comments