Skip to content

Commit f76caf5

Browse files
committed
initial hyperedge impl
1 parent c8aa3cc commit f76caf5

27 files changed

Lines changed: 243 additions & 81 deletions

include/gl/edge_descriptor.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ class edge_descriptor final {
6868
~edge_descriptor() = default;
6969

7070
[[nodiscard]] bool operator==(const edge_descriptor& other) const noexcept
71-
requires(type_traits::is_directed_v<type>)
71+
requires(type_traits::c_directed_edge<type>)
7272
{
7373
return this->_id == other._id and (this->_vertices == other._vertices);
7474
}
7575

7676
[[nodiscard]] bool operator==(const edge_descriptor& other) const noexcept
77-
requires(type_traits::is_undirected_v<type>)
77+
requires(type_traits::c_undirected_edge<type>)
7878
{
7979
return this->_id == other._id
8080
and (this->_vertices == other._vertices
@@ -86,11 +86,11 @@ class edge_descriptor final {
8686
}
8787

8888
[[nodiscard]] constexpr bool is_directed() const noexcept {
89-
return type_traits::is_directed_v<type>;
89+
return type_traits::c_directed_edge<type>;
9090
}
9191

9292
[[nodiscard]] constexpr bool is_undirected() const noexcept {
93-
return type_traits::is_undirected_v<type>;
93+
return type_traits::c_undirected_edge<type>;
9494
}
9595

9696
[[nodiscard]] bool is_valid() const noexcept {
@@ -157,7 +157,7 @@ class edge_descriptor final {
157157
return this->_vertices.first == this->_vertices.second;
158158
}
159159

160-
[[nodiscard]] gl_attr_force_inline properties_ref_type properties() const {
160+
[[nodiscard]] properties_ref_type properties() const {
161161
if (not this->is_valid())
162162
throw std::logic_error("Cannot access properties of an invalid edge");
163163

include/gl/edge_tags.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,38 @@ concept c_edge_directional_tag = c_one_of<T, directed_t, undirected_t>;
2121

2222
} // namespace type_traits
2323

24-
template <type_traits::c_edge_directional_tag EdgeTag, type_traits::c_properties Properties>
24+
template <type_traits::c_edge_directional_tag DirectionalTag, type_traits::c_properties Properties>
2525
class edge_descriptor;
2626

2727
namespace type_traits {
2828

29-
template <typename T>
30-
inline constexpr bool is_directed_v = false;
31-
32-
template <c_instantiation_of<edge_descriptor> EdgeType>
33-
inline constexpr bool is_directed_v<EdgeType> =
34-
std::is_same_v<typename EdgeType::directional_tag, directed_t>;
29+
// TODO: align docs
3530

36-
template <typename T>
37-
inline constexpr bool is_undirected_v = false;
31+
template <typename E>
32+
concept c_directed_edge =
33+
c_instantiation_of<E, edge_descriptor>
34+
and std::same_as<typename E::directional_tag, directed_t>;
3835

39-
template <c_instantiation_of<edge_descriptor> EdgeType>
40-
inline constexpr bool is_undirected_v<EdgeType> =
41-
std::is_same_v<typename EdgeType::directional_tag, undirected_t>;
36+
template <typename E>
37+
concept c_undirected_edge =
38+
c_instantiation_of<E, edge_descriptor>
39+
and std::same_as<typename E::directional_tag, undirected_t>;
4240

4341
} // namespace type_traits
4442

4543
struct directed_t {
4644
using type = std::type_identity_t<directed_t>;
4745

4846
template <type_traits::c_instantiation_of<edge_descriptor> EdgeType>
49-
requires(type_traits::is_directed_v<EdgeType>)
47+
requires(type_traits::c_directed_edge<EdgeType>)
5048
[[nodiscard]] gl_attr_force_inline static bool is_incident_from(
5149
const EdgeType& edge, const types::id_type vertex_id
5250
) {
5351
return vertex_id == edge._vertices.first;
5452
}
5553

5654
template <type_traits::c_instantiation_of<edge_descriptor> EdgeType>
57-
requires(type_traits::is_directed_v<EdgeType>)
55+
requires(type_traits::c_directed_edge<EdgeType>)
5856
[[nodiscard]] gl_attr_force_inline static bool is_incident_to(
5957
const EdgeType& edge, const types::id_type vertex_id
6058
) {
@@ -66,15 +64,15 @@ struct undirected_t {
6664
using type = std::type_identity_t<undirected_t>;
6765

6866
template <type_traits::c_instantiation_of<edge_descriptor> EdgeType>
69-
requires(type_traits::is_undirected_v<EdgeType>)
67+
requires(type_traits::c_undirected_edge<EdgeType>)
7068
[[nodiscard]] gl_attr_force_inline static bool is_incident_from(
7169
const EdgeType& edge, const types::id_type vertex_id
7270
) {
7371
return edge.is_incident_with(vertex_id);
7472
}
7573

7674
template <type_traits::c_instantiation_of<edge_descriptor> EdgeType>
77-
requires(type_traits::is_undirected_v<EdgeType>)
75+
requires(type_traits::c_undirected_edge<EdgeType>)
7876
[[nodiscard]] gl_attr_force_inline static bool is_incident_to(
7977
const EdgeType& edge, const types::id_type vertex_id
8078
) {

include/gl/graph.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ class graph final {
443443

444444
this->_verify_vertex_id(target_id);
445445

446-
if constexpr (type_traits::is_directed_v<edge_type>)
446+
if constexpr (type_traits::c_directed_edge<edge_type>)
447447
return this->has_edge(source_id, target_id) or this->has_edge(target_id, source_id);
448448
else
449449
return this->has_edge(source_id, target_id);
@@ -528,7 +528,7 @@ class graph final {
528528

529529
private:
530530
[[nodiscard]] static constexpr std::string _directed_type_str() {
531-
return type_traits::is_directed_v<edge_type> ? "directed" : "undirected";
531+
return type_traits::c_directed_edge<edge_type> ? "directed" : "undirected";
532532
}
533533

534534
// --- graph element verification methods ---
@@ -605,7 +605,7 @@ class graph final {
605605
// print graph size
606606
os << std::format(
607607
"{} {} {} {} {}\n",
608-
static_cast<int>(type_traits::is_directed_v<edge_type>),
608+
static_cast<int>(type_traits::c_directed_edge<edge_type>),
609609
this->n_vertices(),
610610
this->n_unique_edges(),
611611
static_cast<int>(with_vertex_properties),
@@ -651,7 +651,7 @@ class graph final {
651651
bool directed;
652652
is >> directed;
653653

654-
if (directed != type_traits::is_directed_v<edge_type>)
654+
if (directed != type_traits::c_directed_edge<edge_type>)
655655
throw std::ios_base::failure(std::format(
656656
"Invalid graph specification: directional tag does not match - should be {}",
657657
_directed_type_str()

include/gl/graph_utility.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "graph.hpp"
88

9+
// move to graph.hpp?
10+
911
namespace gl {
1012

1113
// --- general graph utility ---
@@ -15,17 +17,13 @@ namespace type_traits {
1517
template <typename T>
1618
concept c_graph = c_instantiation_of<T, graph>;
1719

18-
template <c_graph GraphType>
19-
inline constexpr bool is_directed_v<GraphType> = is_directed_v<typename GraphType::edge_type>;
20-
21-
template <c_graph GraphType>
22-
inline constexpr bool is_undirected_v<GraphType> = is_undirected_v<typename GraphType::edge_type>;
20+
// TODO: align docs (removed is_{un}directed_v)
2321

24-
template <typename T>
25-
concept c_directed_graph = c_graph<T> and is_directed_v<T>;
22+
template <typename G>
23+
concept c_directed_graph = c_graph<G> and c_directed_edge<typename G::edge_type>;
2624

27-
template <typename T>
28-
concept c_undirected_graph = c_graph<T> and is_undirected_v<T>;
25+
template <typename G>
26+
concept c_undirected_graph = c_graph<G> and c_undirected_edge<typename G::edge_type>;
2927

3028
} // namespace type_traits
3129

include/gl/impl/specialized/adjacency_list.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace detail {
4747
} // namespace detail
4848

4949
template <type_traits::c_instantiation_of<adjacency_list> AdjacencyList>
50-
requires(type_traits::is_directed_v<typename AdjacencyList::edge_type>)
50+
requires(type_traits::c_directed_edge<typename AdjacencyList::edge_type>)
5151
struct directed_adjacency_list {
5252
using impl_type = AdjacencyList;
5353
using edge_type = typename impl_type::edge_type;
@@ -163,7 +163,7 @@ struct directed_adjacency_list {
163163
};
164164

165165
template <type_traits::c_instantiation_of<adjacency_list> AdjacencyList>
166-
requires(type_traits::is_undirected_v<typename AdjacencyList::edge_type>)
166+
requires(type_traits::c_undirected_edge<typename AdjacencyList::edge_type>)
167167
struct undirected_adjacency_list {
168168
using impl_type = AdjacencyList;
169169
using edge_type = typename impl_type::edge_type;
@@ -276,13 +276,13 @@ struct list_impl_traits {
276276
};
277277

278278
template <type_traits::c_instantiation_of<adjacency_list> AdjacencyList>
279-
requires(type_traits::is_directed_v<typename AdjacencyList::edge_type>)
279+
requires(type_traits::c_directed_edge<typename AdjacencyList::edge_type>)
280280
struct list_impl_traits<AdjacencyList> {
281281
using type = directed_adjacency_list<AdjacencyList>;
282282
};
283283

284284
template <type_traits::c_instantiation_of<adjacency_list> AdjacencyList>
285-
requires(type_traits::is_undirected_v<typename AdjacencyList::edge_type>)
285+
requires(type_traits::c_undirected_edge<typename AdjacencyList::edge_type>)
286286
struct list_impl_traits<AdjacencyList> {
287287
using type = undirected_adjacency_list<AdjacencyList>;
288288
};

include/gl/impl/specialized/adjacency_matrix.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ inline void check_edge_override(
4545
} // namespace detail
4646

4747
template <type_traits::c_instantiation_of<adjacency_matrix> AdjacencyMatrix>
48-
requires(type_traits::is_directed_v<typename AdjacencyMatrix::edge_type>)
48+
requires(type_traits::c_directed_edge<typename AdjacencyMatrix::edge_type>)
4949
struct directed_adjacency_matrix {
5050
using impl_type = AdjacencyMatrix;
5151
using vertex_type = typename impl_type::vertex_type;
@@ -165,7 +165,7 @@ struct directed_adjacency_matrix {
165165
};
166166

167167
template <type_traits::c_instantiation_of<adjacency_matrix> AdjacencyMatrix>
168-
requires(type_traits::is_undirected_v<typename AdjacencyMatrix::edge_type>)
168+
requires(type_traits::c_undirected_edge<typename AdjacencyMatrix::edge_type>)
169169
struct undirected_adjacency_matrix {
170170
using impl_type = AdjacencyMatrix;
171171
using vertex_type = typename impl_type::vertex_type;
@@ -286,13 +286,13 @@ struct matrix_impl_traits {
286286
};
287287

288288
template <type_traits::c_instantiation_of<adjacency_matrix> AdjacencyMatrix>
289-
requires(type_traits::is_directed_v<typename AdjacencyMatrix::edge_type>)
289+
requires(type_traits::c_directed_edge<typename AdjacencyMatrix::edge_type>)
290290
struct matrix_impl_traits<AdjacencyMatrix> {
291291
using type = directed_adjacency_matrix<AdjacencyMatrix>;
292292
};
293293

294294
template <type_traits::c_instantiation_of<adjacency_matrix> AdjacencyMatrix>
295-
requires(type_traits::is_undirected_v<typename AdjacencyMatrix::edge_type>)
295+
requires(type_traits::c_undirected_edge<typename AdjacencyMatrix::edge_type>)
296296
struct matrix_impl_traits<AdjacencyMatrix> {
297297
using type = undirected_adjacency_matrix<AdjacencyMatrix>;
298298
};

include/gl/topology/binary_tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ template <type_traits::c_graph GraphType>
4646

4747
template <type_traits::c_graph GraphType>
4848
[[nodiscard]] GraphType bidirectional_regular_binary_tree(const types::size_type depth) {
49-
if constexpr (type_traits::is_directed_v<GraphType>) {
49+
if constexpr (type_traits::c_directed_graph<GraphType>) {
5050
if (depth < detail::min_non_trivial_bin_tree_depth)
5151
return GraphType{depth};
5252

include/gl/topology/bipartite.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ template <type_traits::c_graph GraphType>
1919
for (types::id_type source_id = constants::initial_id; source_id < n_vertices_a; ++source_id) {
2020
for (types::id_type target_id = n_vertices_a; target_id < n_vertices; ++target_id) {
2121
graph.add_edge(source_id, target_id);
22-
if constexpr (type_traits::is_directed_v<GraphType>)
22+
if constexpr (type_traits::c_directed_graph<GraphType>)
2323
graph.add_edge(target_id, source_id);
2424
}
2525
}

include/gl/topology/clique.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ template <type_traits::c_graph GraphType>
1616
for (types::id_type source_id = constants::initial_id; source_id < n_vertices; ++source_id) {
1717
for (types::id_type target_id = constants::initial_id; target_id < source_id; ++target_id) {
1818
graph.add_edge(source_id, target_id);
19-
if constexpr (type_traits::is_directed_v<GraphType>)
19+
if constexpr (type_traits::c_directed_graph<GraphType>)
2020
graph.add_edge(target_id, source_id);
2121
}
2222
}

include/gl/topology/cycle.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ template <type_traits::c_graph GraphType>
2121

2222
template <type_traits::c_graph GraphType>
2323
[[nodiscard]] GraphType bidirectional_cycle(const types::size_type n_vertices) {
24-
if constexpr (type_traits::is_directed_v<GraphType>) {
24+
if constexpr (type_traits::c_directed_graph<GraphType>) {
2525
GraphType graph{n_vertices};
2626

2727
for (types::id_type source_id = constants::initial_id; source_id < n_vertices;

0 commit comments

Comments
 (0)