GraphDom
Loading...
Searching...
No Matches
base_adj_list.h
1/*
2 * Copyright 2026 Michele Comparini
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef GRAPHDOM_BASE_ADJ_LIST_IMPL_H
8#define GRAPHDOM_BASE_ADJ_LIST_IMPL_H
9
10#include "../../graph.h"
11#include "../base_adj_list.h"
12#include "../adj_list_base_iterator.h"
13
14template <typename VertexType>
15template <typename VertexContainerPointerType>
16graphdom::graph<VertexType>::base_adj_list<VertexContainerPointerType>::base_adj_list(
17 const graph<VertexType>* const adj_list_owner_graph_pointer,
18 const graph_edges_type adj_list_owner_graph_edges_type,
19 const VertexContainerPointerType adj_list_common_begin_point_vertex_container_pointer,
20 const graph<VertexType>::edges_type_selection_type adj_list_edges_type_selection
21) :
22adj_list_owner_graph_pointer(adj_list_owner_graph_pointer),
23adj_list_owner_graph_edges_type(adj_list_owner_graph_edges_type),
24adj_list_common_begin_point_vertex_container_pointer(adj_list_common_begin_point_vertex_container_pointer),
25adj_list_edges_type_selection(adj_list_edges_type_selection) {}
26
27template <typename VertexType>
28template <typename VertexContainerPointerType>
29template <typename K>
30constexpr typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>
31graphdom::graph<VertexType>::base_adj_list<VertexContainerPointerType>::internal_begin() const {
32 static_assert(
33 std::is_same< K , graphdom::graph<VertexType>::vertex_container* >::value ||
34 std::is_same< K , const graphdom::graph<VertexType>::vertex_container* >::value
35 );
36 auto* const undirected_adj_set = get_adj_set_if_accessible<K>(graphdom::edge_type::undirected);
37 auto* const directed_adj_set = get_adj_set_if_accessible<K>(graphdom::edge_type::directed);
38 if ( ( undirected_adj_set == nullptr ) && ( directed_adj_set == nullptr ) ) {
39 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
40 adj_list_owner_graph_pointer,
41 adj_list_owner_graph_edges_type,
42 adj_list_common_begin_point_vertex_container_pointer,
43 adj_list_edges_type_selection,
44 ( adj_list_owner_graph_edges_type == undirected ) ? graphdom::edge_type::undirected : graphdom::edge_type::directed
45 );
46 }
47 if ( undirected_adj_set != nullptr ) {
48 if ( undirected_adj_set->empty() && directed_adj_set != nullptr ) {
49 if ( directed_adj_set->empty() ) {
50 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
51 adj_list_owner_graph_pointer,
52 adj_list_owner_graph_edges_type,
53 adj_list_common_begin_point_vertex_container_pointer,
54 adj_list_edges_type_selection,
56 undirected_adj_set->begin()
57 );
58 }
59 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
60 adj_list_owner_graph_pointer,
61 adj_list_owner_graph_edges_type,
62 adj_list_common_begin_point_vertex_container_pointer,
63 adj_list_edges_type_selection,
65 directed_adj_set->begin()
66 );
67 }
68 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
69 adj_list_owner_graph_pointer,
70 adj_list_owner_graph_edges_type,
71 adj_list_common_begin_point_vertex_container_pointer,
72 adj_list_edges_type_selection,
74 undirected_adj_set->begin()
75 );
76 }
77 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
78 adj_list_owner_graph_pointer,
79 adj_list_owner_graph_edges_type,
80 adj_list_common_begin_point_vertex_container_pointer,
81 adj_list_edges_type_selection,
83 directed_adj_set->begin()
84 );
85}
86
87template <typename VertexType>
88template <typename VertexContainerPointerType>
89template <typename K>
90constexpr typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>
91graphdom::graph<VertexType>::base_adj_list<VertexContainerPointerType>::internal_end() const {
92 static_assert(
93 std::is_same< K , graphdom::graph<VertexType>::vertex_container* >::value ||
94 std::is_same< K , const graphdom::graph<VertexType>::vertex_container* >::value
95 );
96 auto* const undirected_adj_set = get_adj_set_if_accessible<K>(graphdom::edge_type::undirected);
97 auto* const directed_adj_set = get_adj_set_if_accessible<K>(graphdom::edge_type::directed);
98 if ( ( undirected_adj_set == nullptr ) && ( directed_adj_set == nullptr ) ) {
99 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
100 adj_list_owner_graph_pointer,
101 adj_list_owner_graph_edges_type,
102 adj_list_common_begin_point_vertex_container_pointer,
103 adj_list_edges_type_selection,
104 ( adj_list_owner_graph_edges_type == undirected ) ? graphdom::edge_type::undirected : graphdom::edge_type::directed
105 );
106 }
107 if ( directed_adj_set != nullptr ) {
108 if ( directed_adj_set->empty() && undirected_adj_set != nullptr ) {
109 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
110 adj_list_owner_graph_pointer,
111 adj_list_owner_graph_edges_type,
112 adj_list_common_begin_point_vertex_container_pointer,
113 adj_list_edges_type_selection,
115 undirected_adj_set->end()
116 );
117 }
118 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
119 adj_list_owner_graph_pointer,
120 adj_list_owner_graph_edges_type,
121 adj_list_common_begin_point_vertex_container_pointer,
122 adj_list_edges_type_selection,
124 directed_adj_set->end()
125 );
126 }
127 return typename graphdom::graph<VertexType>::template adj_list_base_iterator<VertexContainerPointerType>(
128 adj_list_owner_graph_pointer,
129 adj_list_owner_graph_edges_type,
130 adj_list_common_begin_point_vertex_container_pointer,
131 adj_list_edges_type_selection,
133 undirected_adj_set->end()
134 );
135}
136
137template <typename VertexType>
138template <typename VertexContainerPointerType>
139template <typename K>
140constexpr typename graphdom::graph<VertexType>::template adj_set<K>*
141graphdom::graph<VertexType>::base_adj_list<VertexContainerPointerType>::get_adj_set_if_accessible(const graphdom::edge_type edge_type) const {
142 static_assert(
143 std::is_same< K , graphdom::graph<VertexType>::vertex_container* >::value ||
144 std::is_same< K , const graphdom::graph<VertexType>::vertex_container* >::value
145 );
146 auto* const undirected_adj =
147 ( adj_list_owner_graph_edges_type == mixed ) ?
148 &( ( static_cast< const typename graphdom::graph<VertexType>::mixed_graph_vertex_container<K>* >( adj_list_common_begin_point_vertex_container_pointer ) )->undirected_adj )
149 :
150 (
151 ( adj_list_owner_graph_edges_type == undirected ) ?
152 &( ( static_cast< const typename graphdom::graph<VertexType>::non_mixed_graph_vertex_container<K>* >( adj_list_common_begin_point_vertex_container_pointer ) )->adj )
153 :
154 nullptr
155 );
156 auto* const directed_adj =
157 ( adj_list_owner_graph_edges_type == mixed ) ?
158 &( ( static_cast< const typename graphdom::graph<VertexType>::mixed_graph_vertex_container<K>* >( adj_list_common_begin_point_vertex_container_pointer ) )->directed_adj )
159 :
160 (
161 ( adj_list_owner_graph_edges_type == directed ) ?
162 &( ( static_cast< const typename graphdom::graph<VertexType>::non_mixed_graph_vertex_container<K>* >( adj_list_common_begin_point_vertex_container_pointer ) )->adj )
163 :
164 nullptr
165 );
166 if ( edge_type == edge_type::undirected ) {
167 if ( adj_list_edges_type_selection != directed_edges ) {
168 return undirected_adj;
169 }
170 return nullptr;
171 }
172 if ( adj_list_edges_type_selection != undirected_edges ) {
173 return directed_adj;
174 }
175 return nullptr;
176}
177
178#endif //GRAPHDOM_BASE_ADJ_LIST_IMPL_H
Every graph created using this library is an instance of a concrete class publicly derived,...
Definition graph.h:43
edge_type
The enumerated type whose values represent the two types of edges of a graph.
Definition graph.h:21
@ undirected
This enum value means undirected edge.
Definition graph.h:22
@ directed
This enum value means directed edge.
Definition graph.h:23