Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edgelist #70

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/graph/algorithm/mst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void kruskal(E&& e, // graph
T&& t, // out: spanning tree edge list
CompareOp compare // edge value comparitor
) {
using VId = edgelist::vertex_source_id_t<E>;
using VId = edgelist::source_id_t<E>;

auto outer_compare = [&](auto&& i, auto&& j) { return compare(std::get<2>(i), std::get<2>(j)); };
std::sort(e.begin(), e.end(), outer_compare);
Expand Down
12 changes: 6 additions & 6 deletions include/graph/container/utility_edgelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class utility_edgelist {
, source_max_(list.source_max_)
, target_max_(list.target_max_)
, bipartite_(list.bipartite_)
, sorted_source_(list.sourced_source_)
, sorted_source_(list.sorted_source_)
, sorted_target_(list.sorted_target_)
, directed_(list.directed_) {}

Expand Down Expand Up @@ -76,15 +76,15 @@ class utility_edgelist {
return el.storage_;
}

friend constexpr VSourceId& tag_invoke(::std::graph::edgelist::tag_invoke::vertex_id_source_fn_t,
friend constexpr VSourceId& tag_invoke(::std::graph::edgelist::tag_invoke::source_id_fn_t,
utility_edgelist& el,
storage_iterator_type& e) {
return std::get<0>(*e);
value_type& e) {
return std::get<0>(e);
}

friend constexpr EV&
tag_invoke(::std::graph::edgelist::tag_invoke::edge_value_fn_t, utility_edgelist& el, storage_iterator_type& e) {
return std::get<2>(*e);
tag_invoke(::std::graph::edgelist::tag_invoke::edge_value_fn_t, utility_edgelist& el, value_type& e) {
return std::get<2>(e);
}

storage_type storage_;
Expand Down
54 changes: 30 additions & 24 deletions include/graph/detail/graph_cpo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,53 +726,59 @@ namespace edgelist {
TAG_INVOKE_DEF(edges); // edges(e) -> [edge list vertices]
}

template <class E>
auto edges(E&& el) -> decltype(tag_invoke::edges(el)) {
return tag_invoke::edges(el);
template <class EL>
auto edges(EL&& el) {
return el;
}

template <class E>
using edgelist_range_t = decltype(std::graph::edgelist::edges(declval<E&&>()));
template <class EL>
using edgelist_range_t = decltype(edges(declval<EL&&>()));

template <class E>
using edgelist_iterator_t = ranges::iterator_t<edgelist_range_t<E&&>>;
template <class EL>
using edgelist_iterator_t = ranges::iterator_t<edgelist_range_t<EL&&>>;

template <class EL>
using edge_t = ranges::range_value_t<edgelist_range_t<EL>>; // edge value type

template <class EL>
using edge_reference_t = ranges::range_reference_t<edgelist_range_t<EL>>; // edge reference type

namespace tag_invoke {
TAG_INVOKE_DEF(vertex_id_source);
TAG_INVOKE_DEF(source_id);
}

template <class E>
auto vertex_id_source(E&& el, edgelist_iterator_t<E> e) {
return tag_invoke::vertex_id_source(el, e);
template <class EL>
auto source_id(EL&& el, edge_reference_t<EL> uv) {
return tag_invoke::source_id(el, uv);
}

template <class E>
using vertex_source_id_t = decltype(vertex_id_source(declval<E&&>(), declval<edgelist_iterator_t<E>>()));
template <class EL>
using source_id_t = decltype(source_id(declval<EL&&>(), declval<edge_reference_t<EL>>()));

namespace tag_invoke {
TAG_INVOKE_DEF(vertex_id_target);
TAG_INVOKE_DEF(target_id);
}

template <class E>
auto vertex_id_target(E&& el, edgelist_iterator_t<E> e) {
return tag_invoke::vertex_id_target(el, e);
template <class EL>
auto target_id(EL&& el, edge_reference_t<EL> uv) {
return tag_invoke::target_id(el, uv);
}

template <class E>
using vertex_target_id_t = decltype(vertex_id_target(declval<E&&>(), declval<edgelist_iterator_t<E>>()));
template <class EL>
using target_id_t = decltype(target_id(declval<EL&&>(), declval<edge_reference_t<EL>>()));


namespace tag_invoke {
TAG_INVOKE_DEF(edge_value);
}

template <class E>
auto edge_value(E&& el, edgelist_iterator_t<E> e) {
return tag_invoke::edge_value(el, e);
template <class EL>
auto edge_value(EL&& el, edge_reference_t<EL> uv) {
return tag_invoke::edge_value(el, uv);
}

template <class E>
using edge_value_t = decltype(edge_value(declval<E&&>(), declval<edgelist_iterator_t<E>>()));
template <class EL>
using edge_value_t = decltype(edge_value(declval<EL&&>(), declval<edge_reference_t<EL>>()));
} // namespace edgelist

# if 0
Expand Down
8 changes: 4 additions & 4 deletions include/graph/edgelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace std::graph::edgelist {

template <class E>
concept edgelist_range = ranges::forward_range<edgelist_range_t<E>>;
template <class EL>
concept edgelist_range = ranges::forward_range<edgelist_range_t<EL>>;

template <class E>
concept edgelist = edgelist_range<E>;
template <class EL>
concept edgelist = edgelist_range<EL>;
} // namespace std::graph::edgelist

#endif
Loading