8#include <unordered_set>
9#include <unordered_map>
22template <
typename T>
requires requires (T v) { v.vertex_id; }
25 return std::hash<std::size_t>{}(v.vertex_id);
35 template <
typename T>
requires requires (T v) { v.vertex_id; }
37 return a.vertex_id == b.vertex_id;
51 GRAPHLE_MAKE_NIEBLOID(to_edge, ([] (
const auto& e) {
return std::pair { to_vertex<V>(e.first), to_vertex<V>(e.second) }; }),
typename V);
58 template <
typename M,
typename K>
constexpr auto range_at_map_key(M&& map,
const K& key) {
59 using view_type =
decltype(std::views::all(map.at(key)));
61 return map.contains(key)
75 std::vector<std::pair<vertex, vertex>>
edges;
85 .deduce_compare_as = graphle::meta::deduce_as<graphle::compare_by_value<vertex>>,
103 std::unordered_map<vertex, std::vector<vertex>>
edges;
107 auto vs = g.
vertices | std::views::transform(to_vertex<vertex>);
108 auto es = g.
edges | std::views::transform(to_edge<vertex>);
115 for (
const auto& e : es) result.edges[e.first].push_back(e.second);
125 .deduce_compare_as = graphle::meta::deduce_as<graphle::compare_by_value<vertex>>,
144 std::unordered_map<std::size_t, std::shared_ptr<vertex>> vertices;
147 vertices.emplace(v.vertex_id, std::make_shared<vertex>(v.vertex_id));
150 for (
const auto& e : g.
edges) {
151 auto& from = vertices.at(e.first.vertex_id);
152 auto& to = vertices.at(e.second.vertex_id);
154 from->out.push_back(to);
164 .deduce_compare_as = graphle::meta::deduce_as<graphle::compare_by_value<vertex>>,
165 .get_out_edges = [] (
vertex* v) {
166 return views::all(v->out)
167 | views::transform(&std::shared_ptr<vertex>::get)
185 auto vs = g.
vertices | std::views::transform(to_vertex<vertex>);
187 std::unordered_map<std::size_t, vertex*> vertex_map;
189 for (
const auto [from, to] : g.
edges) {
190 for (
auto v : { from, to }) {
191 if (!vertex_map.contains(v.vertex_id)) {
192 vertex_map.emplace(v.vertex_id, &*std::ranges::find(result.vertices,
vertex { v.vertex_id }));
196 vertex_map.at(from.vertex_id)->out.push_back(vertex_map.at(to.vertex_id));
206 .deduce_compare_as = graphle::meta::deduce_as<graphle::compare_by_value<vertex>>,
222 std::vector<std::shared_ptr<vertex>>
in;
223 std::vector<std::shared_ptr<vertex>>
out;
230 std::unordered_map<std::size_t, std::shared_ptr<vertex>> vertices;
233 vertices.emplace(v.vertex_id, std::make_shared<vertex>(v.vertex_id));
236 for (
const auto& e : g.
edges) {
237 auto& from = vertices.at(e.first.vertex_id);
238 auto& to = vertices.at(e.second.vertex_id);
240 from->out.push_back(to);
241 to->in.push_back(from);
251 .deduce_compare_as = graphle::meta::deduce_as<graphle::compare_by_value<vertex>>,
252 .get_out_edges = [] (
vertex* v) {
253 return views::all(v->out)
254 | views::transform(&std::shared_ptr<vertex>::get)
257 .get_in_edges = [] (
vertex* v) {
258 return views::all(v->in)
259 | views::transform(&std::shared_ptr<vertex>::get)
274 std::vector<vertex*>
in;
282 auto vs = g.
vertices | std::views::transform(to_vertex<vertex>);
284 std::unordered_map<std::size_t, vertex*> vertex_map;
286 for (
const auto [from, to] : g.
edges) {
287 for (
auto v : { from, to }) {
288 if (!vertex_map.contains(v.vertex_id)) {
289 vertex_map.emplace(v.vertex_id, &*std::ranges::find(result.vertices,
vertex { v.vertex_id }));
293 vertex_map.at(from.vertex_id)->out.push_back(vertex_map.at(to.vertex_id));
294 vertex_map.at(to.vertex_id)->in.push_back(vertex_map.at(from.vertex_id));
304 .deduce_compare_as = graphle::meta::deduce_as<graphle::compare_by_value<vertex>>,
#define GRAPHLE_MAKE_NIEBLOID(Name, Function,...)
constexpr bool operator==(const T &a, const T &b)
constexpr auto transform_edge(F &&fn)
constexpr auto maybe_exists
constexpr auto range_at_map_key(M &&map, const K &key)
constexpr addressof_t addressof
constexpr as_const_t as_const
meta::deduce_as_t< Vertex > deduce_vertex_type
std::vector< std::shared_ptr< vertex > > in
std::vector< std::shared_ptr< vertex > > out
std::shared_ptr< vertex > root
constexpr auto view_as_graph(void)
static in_out_edge_graph from_ve_list(const ve_list_graph &g, std::size_t root=0)
std::vector< std::shared_ptr< vertex > > out
constexpr auto view_as_graph(void)
std::shared_ptr< vertex > root
static out_edge_graph from_ve_list(const ve_list_graph &g, std::size_t root=0)
std::vector< vertex * > out
std::vector< vertex * > in
std::vector< vertex > vertices
static v_list_in_out_edge_graph from_ve_list(const ve_list_graph &g)
constexpr auto view_as_graph(void)
std::vector< vertex * > out
static v_list_out_edge_graph from_ve_list(const ve_list_graph &g)
std::vector< vertex > vertices
constexpr auto view_as_graph(void)
constexpr auto view_as_graph(void)
static constexpr ve_list_graph from_ve_list(const ve_list_graph &g)
std::vector< vertex > vertices
std::vector< std::pair< vertex, vertex > > edges
constexpr auto view_as_graph(void)
std::unordered_map< vertex, std::vector< vertex > > edges
std::unordered_set< vertex > vertices
static ve_map_graph from_ve_list(const ve_list_graph &g)
constexpr std::size_t operator()(const T &v) const