7#ifndef GRAPHDOM_FULL_LABELED_SET_UGRAPH_IMPL_H
8#define GRAPHDOM_FULL_LABELED_SET_UGRAPH_IMPL_H
10#include "../full_labeled_set_ugraph.h"
12template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
15labeled_vertex_set_graph<VertexType,VertexLabelType,VertexLabellerType>(v_lab),
16labeled_edge_non_mixed_graph<VertexType,EdgeLabelType,EdgeLabellerType>(e_lab),
17vertices( custom_vertices_set_compare(v_comp) ) {}
19template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
22labeled_vertex_set_graph<VertexType,VertexLabelType,VertexLabellerType>(v_lab),
23labeled_edge_non_mixed_graph<VertexType,EdgeLabelType,EdgeLabellerType>(std::move(e_lab)),
24vertices( custom_vertices_set_compare(v_comp) ) {}
26template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
29labeled_vertex_set_graph<VertexType,VertexLabelType,VertexLabellerType>(std::move(v_lab)),
30labeled_edge_non_mixed_graph<VertexType,EdgeLabelType,EdgeLabellerType>(e_lab),
31vertices( custom_vertices_set_compare(v_comp) ) {}
33template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
36labeled_vertex_set_graph<VertexType,VertexLabelType,VertexLabellerType>(std::move(v_lab)),
37labeled_edge_non_mixed_graph<VertexType,EdgeLabelType,EdgeLabellerType>(std::move(e_lab)),
38vertices( custom_vertices_set_compare(v_comp) ) {}
40template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
43labeled_vertex_set_graph<VertexType,VertexLabelType,VertexLabellerType>(v_lab),
44labeled_edge_non_mixed_graph<VertexType,EdgeLabelType,EdgeLabellerType>(e_lab),
45vertices( custom_vertices_set_compare(std::move(v_comp)) ) {}
47template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
50labeled_vertex_set_graph<VertexType,VertexLabelType,VertexLabellerType>(v_lab),
51labeled_edge_non_mixed_graph<VertexType,EdgeLabelType,EdgeLabellerType>(std::move(e_lab)),
52vertices( custom_vertices_set_compare(std::move(v_comp)) ) {}
54template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
57labeled_vertex_set_graph<VertexType,VertexLabelType,VertexLabellerType>(std::move(v_lab)),
58labeled_edge_non_mixed_graph<VertexType,EdgeLabelType,EdgeLabellerType>(e_lab),
59vertices( custom_vertices_set_compare(std::move(v_comp)) ) {}
61template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
64labeled_vertex_set_graph<VertexType,VertexLabelType,VertexLabellerType>(std::move(v_lab)),
65labeled_edge_non_mixed_graph<VertexType,EdgeLabelType,EdgeLabellerType>(std::move(e_lab)),
66vertices( custom_vertices_set_compare(std::move(v_comp)) ) {}
68template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
71 for (
auto ugraph_vertices_itr = vertices.begin(); ugraph_vertices_itr != vertices.end(); ++ugraph_vertices_itr) {
72 auto& ugv_itr_vertex_container = *ugraph_vertices_itr;
73 auto& ugv_itr_vc_adj = ugv_itr_vertex_container.adj;
74 for (
auto edge_endpoint_to_deallocate = ugv_itr_vc_adj.begin(); edge_endpoint_to_deallocate != ugv_itr_vc_adj.end(); ++edge_endpoint_to_deallocate) {
75 safe_edge_endpoint_deallocation(*edge_endpoint_to_deallocate);
77 ugv_itr_vc_adj.clear();
81template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
83 return vertices.size();
86template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
89 if ( graphdom::graph<VertexType>::get_owner_graph(vertex) !=
this ) {
90 throw std::runtime_error(
"Error");
92 const auto*
const vertex_container_ptr =
static_cast< const vertex_container*
>( graphdom::graph< VertexType >::get_vertex_container( vertex ) );
93 return vertex_container_ptr->vertex_label;
96template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
99 if ( graphdom::graph<VertexType>::get_owner_graph( edge ) !=
this ) {
100 throw std::runtime_error(
"Error");
106 static_cast<edge_endpoint*
>(
114template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
117 if ( graphdom::graph<VertexType>::get_owner_graph(const_vertex_ptr) ==
this ) {
118 const auto*
const vertex_container_to_erase_ptr =
119 static_cast< const vertex_container*
>( graphdom::graph<VertexType>::get_vertex_container(const_vertex_ptr) );
120 if ( vertex_container_to_erase_ptr !=
nullptr ) {
121 const auto vertex_container_to_erase_found_vertices_itr = vertices.find( *vertex_container_to_erase_ptr );
122 auto& vertex_container_to_erase_adj = ( *vertex_container_to_erase_found_vertices_itr ).adj;
123 for (
auto vertex_container_to_erase_adj_itr = vertex_container_to_erase_adj.begin();
124 vertex_container_to_erase_adj_itr != vertex_container_to_erase_adj.end();
125 ++vertex_container_to_erase_adj_itr) {
126 const auto& edge_endpoint_vertex_container =
128 static_cast< const vertex_container*
>(
132 vertex_container_to_erase_adj_itr
135 ).vertex_container_ptr
138 if ( ( &edge_endpoint_vertex_container ) != vertex_container_to_erase_ptr ) {
139 auto& edge_endpoint_vertex_container_adj = edge_endpoint_vertex_container.adj;
140 const auto vertex_container_to_erase_founded_in_edge_endpoint_vertex_container_adj =
141 edge_endpoint_vertex_container_adj.find( vertex_container_to_erase_ptr );
142 safe_edge_endpoint_deallocation( *vertex_container_to_erase_founded_in_edge_endpoint_vertex_container_adj );
143 edge_endpoint_vertex_container_adj.erase( vertex_container_to_erase_founded_in_edge_endpoint_vertex_container_adj );
145 safe_edge_endpoint_deallocation( *vertex_container_to_erase_adj_itr );
147 vertices.erase(vertex_container_to_erase_found_vertices_itr);
154template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
155typename graphdom::graph<VertexType>::adj_list_iterator
158 if ( graphdom::graph<VertexType>::get_owner_graph(edge_itr) !=
this ) {
159 throw std::runtime_error(
"Error");
161 auto const edge_itr_begin_point =
static_cast< const vertex_container*
>( graphdom::graph<VertexType>::get_begin_point( edge_itr ) );
163 auto const edge_itr_endpoint =
static_cast< const vertex_container*
>( ( *( *inner_iterator_of_begin_point_adj ) ).vertex_container_ptr );
164 if ( edge_itr_begin_point != edge_itr_endpoint ) {
165 auto inner_iterator_of_end_point_adj = ( (*edge_itr_endpoint).adj ).find( edge_itr_begin_point );
166 safe_edge_endpoint_deallocation(*inner_iterator_of_end_point_adj);
167 ( (*edge_itr_endpoint).adj ).erase( inner_iterator_of_end_point_adj );
169 safe_edge_endpoint_deallocation(*inner_iterator_of_begin_point_adj);
172 edge_itr_begin_point,
174 ( (*edge_itr_begin_point).adj ).erase( inner_iterator_of_begin_point_adj )
178template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
181 if ( graphdom::graph<VertexType>::get_owner_graph(vertex) !=
this ) {
182 throw std::runtime_error(
"Error");
184 const auto*
const vertex_container_ptr =
static_cast< const vertex_container*
>( graphdom::graph< VertexType >::get_vertex_container( vertex ) );
185 return const_cast< VertexLabelType&
>( (*vertex_container_ptr).vertex_label );
188template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
189std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>
191 const VertexType& v_core,
const VertexLabelType& vertex_label) {
192 auto inner_insertion_result = vertices.emplace(
196 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
197 graphdom::graph<VertexType>::vertex_handle_factory(
199 *(inner_insertion_result.first),
202 inner_insertion_result.second
206template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
207std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>
209const VertexType& v_core, VertexLabelType&& vertex_label) {
210 const auto lower_bound = vertices.lower_bound(v_core);
211 if ( lower_bound == vertices.cend() ) {
212 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
213 graphdom::graph<VertexType>::vertex_handle_factory(
215 *( vertices.emplace_hint(lower_bound, v_core, std::move(vertex_label)) ),
221 if ( ( vertices.key_comp() )( v_core, *lower_bound ) ) {
222 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
223 graphdom::graph<VertexType>::vertex_handle_factory(
225 *( vertices.emplace_hint(lower_bound, v_core, std::move(vertex_label)) ),
231 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
232 graphdom::graph<VertexType>::vertex_handle_factory(
241template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
242std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>
244VertexType&& v_core,
const VertexLabelType& vertex_label) {
245 const auto lower_bound = vertices.lower_bound(v_core);
246 if ( lower_bound == vertices.cend() ) {
247 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
248 graphdom::graph<VertexType>::vertex_handle_factory(
250 *( vertices.emplace_hint(lower_bound, std::move(v_core), vertex_label) ),
256 if ( ( vertices.key_comp() )( v_core, *lower_bound ) ) {
257 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
258 graphdom::graph<VertexType>::vertex_handle_factory(
260 *( vertices.emplace_hint(lower_bound, std::move(v_core), vertex_label) ),
266 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
267 graphdom::graph<VertexType>::vertex_handle_factory(
276template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
277std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>
279VertexType&& v_core, VertexLabelType&& vertex_label) {
280 const auto lower_bound = vertices.lower_bound(v_core);
281 if ( lower_bound == vertices.cend() ) {
282 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
283 graphdom::graph<VertexType>::vertex_handle_factory(
285 *( vertices.emplace_hint(lower_bound, std::move(v_core), std::move(vertex_label)) ),
291 if ( ( vertices.key_comp() )( v_core, *lower_bound ) ) {
292 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
293 graphdom::graph<VertexType>::vertex_handle_factory(
295 *( vertices.emplace_hint(lower_bound, std::move(v_core), std::move(vertex_label)) ),
301 return std::pair<typename graphdom::graph<VertexType>::vertex_handle,
bool>(
302 graphdom::graph<VertexType>::vertex_handle_factory(
311template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
314 if ( graphdom::graph<VertexType>::get_owner_graph( edge ) !=
this ) {
315 throw std::runtime_error(
"Error");
321 static_cast<edge_endpoint*
>(
329template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
333 const EdgeLabelType& edge_label) {
335 graphdom::graph<VertexType>::get_owner_graph( first_endpoint ) !=
this ||
336 graphdom::graph<VertexType>::get_owner_graph( second_endpoint ) !=
this
338 throw std::runtime_error(
"Error");
340 auto const begin_point_vertex_container =
static_cast< const vertex_container*
>( graphdom::graph<VertexType>::get_vertex_container( first_endpoint ) );
341 auto const end_point_vertex_container =
static_cast< const vertex_container*
>( graphdom::graph<VertexType>::get_vertex_container( second_endpoint ) );
342 if ( begin_point_vertex_container ==
nullptr || end_point_vertex_container ==
nullptr ) {
343 throw std::runtime_error(
"Error");
345 std::unique_ptr< edge_endpoint > edge_endpoint_to_insert_in_begin_point_adj(
new edge_endpoint( end_point_vertex_container , edge_label ) );
346 const auto inner_insertion_result_in_begin_point_adj = ( begin_point_vertex_container->adj ).insert( edge_endpoint_to_insert_in_begin_point_adj.get() );
347 if ( inner_insertion_result_in_begin_point_adj.second ) {
348 edge_endpoint_to_insert_in_begin_point_adj.release();
349 if ( begin_point_vertex_container != end_point_vertex_container ) {
350 std::unique_ptr< edge_endpoint > edge_endpoint_to_insert_in_end_point_adj(
352 begin_point_vertex_container ,
353 (
static_cast< edge_endpoint*
>( *( inner_insertion_result_in_begin_point_adj.first ) ) )->edge_label_ptr
356 const auto inner_insertion_result_in_end_point_adj = ( ( end_point_vertex_container->adj ).insert( edge_endpoint_to_insert_in_end_point_adj.get() ) ).second;
357 if ( inner_insertion_result_in_end_point_adj ) {
358 edge_endpoint_to_insert_in_end_point_adj.release();
361 safe_edge_endpoint_deallocation( *( inner_insertion_result_in_begin_point_adj.first ) );
362 ( begin_point_vertex_container->adj ).erase( inner_insertion_result_in_begin_point_adj.first );
368template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
372 EdgeLabelType&& edge_label) {
374 graphdom::graph<VertexType>::get_owner_graph( first_endpoint ) !=
this ||
375 graphdom::graph<VertexType>::get_owner_graph( second_endpoint ) !=
this
377 throw std::runtime_error(
"Error");
379 auto const begin_point_vertex_container =
static_cast< const vertex_container*
>( graphdom::graph<VertexType>::get_vertex_container( first_endpoint ) );
380 auto const end_point_vertex_container =
static_cast< const vertex_container*
>( graphdom::graph<VertexType>::get_vertex_container( second_endpoint ) );
381 if ( begin_point_vertex_container ==
nullptr || end_point_vertex_container ==
nullptr ) {
382 throw std::runtime_error(
"Error");
384 const auto lower_bound = ( begin_point_vertex_container->adj ).lower_bound( end_point_vertex_container );
385 if ( lower_bound == ( begin_point_vertex_container->adj ).cend() ) {
386 const auto first_insertion_itr = ( begin_point_vertex_container->adj ).emplace_hint( lower_bound,
new edge_endpoint( end_point_vertex_container , std::move(edge_label) ) );
387 if ( begin_point_vertex_container != end_point_vertex_container ) {
388 ( end_point_vertex_container->adj ).emplace(
new edge_endpoint( begin_point_vertex_container,
static_cast< const edge_endpoint*
>( *first_insertion_itr )->edge_label_ptr ) );
392 if ( ( ( begin_point_vertex_container->adj ).key_comp() )( end_point_vertex_container, *lower_bound ) ) {
393 const auto first_insertion_itr = ( begin_point_vertex_container->adj ).emplace_hint( lower_bound,
new edge_endpoint( end_point_vertex_container , std::move(edge_label) ) );
394 if ( begin_point_vertex_container != end_point_vertex_container ) {
395 ( end_point_vertex_container->adj ).emplace(
new edge_endpoint( begin_point_vertex_container,
static_cast< const edge_endpoint*
>( *first_insertion_itr )->edge_label_ptr ) );
424template<
typename VertexType,
typename VertexLabelType,
typename EdgeLabelType,
typename Compare,
typename VertexLabellerType,
typename EdgeLabellerType>
427 typename graphdom::graph<VertexType>::template edge_endpoint<VertexContainerPointerType>* ee_ptr) {
428 delete static_cast<edge_endpoint*
>(ee_ptr);
Definition full_labeled_set_ugraph.h:37
std::size_t order() const override
Returns the order of *this, i.e. the number of vertices inside the graph.
Definition full_labeled_set_ugraph.h:82
void insert_edge(const typename graph< VertexType >::vertex_const_handle &first_endpoint, const typename graph< VertexType >::vertex_const_handle &second_endpoint, const EdgeLabelType &edge_label) override
Definition full_labeled_set_ugraph.h:330
const VertexLabelType & get_vertex_label(const typename graph< VertexType >::vertex_const_handle &vertex) const override
Definition full_labeled_set_ugraph.h:87
void erase_vertex(const typename graphdom::graph< VertexType >::vertex_const_handle &) override
Removes the vertex identified by vertex.
Definition full_labeled_set_ugraph.h:115
const EdgeLabelType & get_edge_label(const typename graph< VertexType >::adj_list_const_iterator &) const override
Definition full_labeled_set_ugraph.h:97
graphdom::graph< VertexType >::adj_list_iterator erase_edge(const typename graph< VertexType >::adj_list_const_iterator &) override
Definition full_labeled_set_ugraph.h:156
std::pair< typename graph< VertexType >::vertex_handle, bool > insert_vertex(const VertexType &v_core, const VertexLabelType &vertex_label) override
Definition full_labeled_set_ugraph.h:190
Every valid instance of this class can be used to identify a specific vertex of a graph and to access...
Definition vertex_const_handle.h:35
Every graph created using this library is an instance of a concrete class publicly derived,...
Definition graph.h:43
Every set graph created using this library is an instance of a concrete class publicly derived,...
Definition set_graph.h:18
@ undirected
This enum value means undirected edge.
Definition graph.h:22