Skip to content

Commit

Permalink
finish rewriting all the graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
wmdi committed Oct 3, 2023
1 parent f3c33e5 commit 8f48d5e
Show file tree
Hide file tree
Showing 19 changed files with 471 additions and 392 deletions.
9 changes: 5 additions & 4 deletions lib/utils/graph/include/utils/graph/digraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ struct DiGraphView : virtual public GraphView {
return DiGraphView(make_cow_ptr<T>(std::forward<Args>(args)...));
}

static DiGraphView
unsafe_create_without_ownership(IDiGraphView const &graphView);
protected:
DiGraphView(cow_ptr_t<IDiGraphView> ptr);

private:
DiGraphView(cow_ptr_t<IDiGraphView> ptr);
cow_ptr_t<IDiGraphView> get_ptr() const;

friend struct GraphInternal;
Expand Down Expand Up @@ -70,8 +69,10 @@ struct DiGraph : virtual DiGraphView {
return DiGraph(make_cow_ptr<T>());
}

private:
protected:
DiGraph(cow_ptr_t<IDiGraph>);

private:
cow_ptr_t<IDiGraph> get_ptr();

friend struct GraphInternal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct NodeLabelledMultiDiGraph : virtual NodeLabelledMultiDiGraphView<NodeLabel
protected:
NodeLabelledMultiDiGraph(cow_ptr_t<Interface> ptr, cow_ptr_t<NodeLabelIf> nl)
: NodeLabelledMultiDiGraphView<NodeLabel>(ptr), nl(nl) {}
cow_ptr_t<Interface> get_ptr() {
cow_ptr_t<Interface> get_ptr() const {
return static_cast<cow_ptr_t<Interface>>(ptr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct LabelledMultiDiGraph : virtual LabelledMultiDiGraphView<NodeLabel, EdgeLa
cow_ptr_t<INodeLabel> nl,
cow_ptr_t<IEdgeLabel> el) : LabelledMultiDiGraphView(ptr), nl(nl), el(el) {}

cow_ptr_t<Interface> get_ptr() {
cow_ptr_t<Interface> get_ptr() const {
return static_cast<cow_ptr_t<Interface>>(ptr);
}

Expand Down
3 changes: 0 additions & 3 deletions lib/utils/graph/include/utils/graph/multidiedge.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ struct MultiDiOutput : virtual DiOutput {
};
FF_VISITABLE_STRUCT(MultiDiOutput, src, src_idx);

MultiDiInput get_input(MultiDiEdge const &);
MultiDiOutput get_output(MultiDiEdge const &);

using edge_uid_t = std::pair<std::size_t, std::size_t>;

struct InputMultiDiEdge : virtual MultiDiInput {
Expand Down
11 changes: 6 additions & 5 deletions lib/utils/graph/include/utils/graph/multidigraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ struct MultiDiGraphView : virtual DiGraphView {
make_cow_ptr<T>(std::forward<Args>(args)...));
}

static MultiDiGraphView
unsafe_create_without_ownership(IMultiDiGraphView const &);

private:
protected:
MultiDiGraphView(cow_ptr_t<IMultiDiGraphView> ptr);

private:
cow_ptr_t <IMultiDiGraphView> get_ptr() const;

friend struct GraphInternal;
Expand Down Expand Up @@ -66,8 +65,10 @@ struct MultiDiGraph : virtual MultiDiGraphView {
return MultiDiGraph(make_cow_ptr<T>());
}

private:
protected:
MultiDiGraph(cow_ptr_t<IMultiDiGraph>);

private:
cow_ptr_t<IMultiDiGraph> get_ptr() const;

friend struct GraphInternal;
Expand Down
4 changes: 1 addition & 3 deletions lib/utils/graph/include/utils/graph/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ struct GraphView {

std::unordered_set<Node> query_nodes(NodeQuery const &) const;

static GraphView unsafe_create_without_ownership(IGraphView const &);

template <typename T, typename... Args>
static typename std::enable_if<std::is_base_of<IGraphView, T>::value,
GraphView>::type
Expand Down Expand Up @@ -87,7 +85,7 @@ struct Graph : virtual GraphView {
Graph() = delete;
Graph(Graph const &) = default;

Graph &operator=(Graph);
Graph &operator=(Graph) = default;

friend void swap(Graph &, Graph &);

Expand Down
43 changes: 12 additions & 31 deletions lib/utils/graph/include/utils/graph/open_edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,29 @@ struct OpenMultiDiEdgeQuery {
OpenMultiDiEdgeQuery() = delete;
OpenMultiDiEdgeQuery(InputMultiDiEdgeQuery const &input_edge_query,
MultiDiEdgeQuery const &standard_edge_query,
OutputMultiDiEdgeQuery const &output_edge_query)
: input_edge_query(input_edge_query),
standard_edge_query(standard_edge_query),
output_edge_query(output_edge_query) {}

OpenMultiDiEdgeQuery(MultiDiEdgeQuery const &q)
: OpenMultiDiEdgeQuery(
InputMultiDiEdgeQuery::none(), q, OutputMultiDiEdgeQuery::none()) {}
OpenMultiDiEdgeQuery(InputMultiDiEdgeQuery const &q)
: OpenMultiDiEdgeQuery(
q, MultiDiEdgeQuery::none(), OutputMultiDiEdgeQuery::none()) {}
OpenMultiDiEdgeQuery(OutputMultiDiEdgeQuery const &q)
: OpenMultiDiEdgeQuery(
InputMultiDiEdgeQuery::none(), MultiDiEdgeQuery::none(), q) {}
OutputMultiDiEdgeQuery const &output_edge_query);

OpenMultiDiEdgeQuery(MultiDiEdgeQuery const &q);
OpenMultiDiEdgeQuery(InputMultiDiEdgeQuery const &q);
OpenMultiDiEdgeQuery(OutputMultiDiEdgeQuery const &q);

InputMultiDiEdgeQuery input_edge_query;
MultiDiEdgeQuery standard_edge_query;
OutputMultiDiEdgeQuery output_edge_query;
};
FF_VISITABLE_STRUCT(OpenMultiDiEdgeQuery,
FF_VISITABLE_STRUCT_NONSTANDARD_CONSTRUCTION(OpenMultiDiEdgeQuery,
input_edge_query,
standard_edge_query,
output_edge_query);

struct DownwardOpenMultiDiEdgeQuery {
DownwardOpenMultiDiEdgeQuery() = delete;
DownwardOpenMultiDiEdgeQuery(OutputMultiDiEdgeQuery const &output_edge_query,
MultiDiEdgeQuery const &standard_edge_query)
: output_edge_query(output_edge_query),
standard_edge_query(standard_edge_query) {}
DownwardOpenMultiDiEdgeQuery(OutputMultiDiEdgeQuery const &output_edge_query)
: DownwardOpenMultiDiEdgeQuery(output_edge_query,
MultiDiEdgeQuery::none()) {}
DownwardOpenMultiDiEdgeQuery(MultiDiEdgeQuery const &standard_edge_query)
: DownwardOpenMultiDiEdgeQuery(OutputMultiDiEdgeQuery::all(),
standard_edge_query){};

operator OpenMultiDiEdgeQuery() const {
NOT_IMPLEMENTED();
}
MultiDiEdgeQuery const &standard_edge_query);
DownwardOpenMultiDiEdgeQuery(OutputMultiDiEdgeQuery const &output_edge_query);
DownwardOpenMultiDiEdgeQuery(MultiDiEdgeQuery const &standard_edge_query);

operator OpenMultiDiEdgeQuery() const;

OutputMultiDiEdgeQuery output_edge_query;
MultiDiEdgeQuery standard_edge_query;
Expand All @@ -74,9 +57,7 @@ struct UpwardOpenMultiDiEdgeQuery {
MultiDiEdgeQuery const &);
UpwardOpenMultiDiEdgeQuery(InputMultiDiEdgeQuery const &);
UpwardOpenMultiDiEdgeQuery(MultiDiEdgeQuery const &);
operator OpenMultiDiEdgeQuery() const {
NOT_IMPLEMENTED();
}
operator OpenMultiDiEdgeQuery() const;

InputMultiDiEdgeQuery input_edge_query;
MultiDiEdgeQuery standard_edge_query;
Expand Down
40 changes: 22 additions & 18 deletions lib/utils/graph/include/utils/graph/open_graphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ struct OpenMultiDiGraphView : virtual MultiDiGraphView {
make_cow_ptr<T>(std::forward<Args>(args)...));
}

private:
protected:
OpenMultiDiGraphView(cow_ptr_t<IOpenMultiDiGraphView> ptr);

private:
cow_ptr_t<IOpenMultiDiGraphView> get_ptr() const;

friend struct GraphInternal;
Expand All @@ -45,7 +47,7 @@ struct OpenMultiDiGraph : virtual OpenMultiDiGraphView {
using EdgeQuery = OpenMultiDiEdgeQuery;

OpenMultiDiGraph() = delete;
OpenMultiDiGraph(OpenMultiDiGraph const &);
OpenMultiDiGraph(OpenMultiDiGraph const &) = default;

friend void swap(OpenMultiDiGraph &, OpenMultiDiGraph &);

Expand All @@ -65,8 +67,10 @@ struct OpenMultiDiGraph : virtual OpenMultiDiGraphView {
return make_cow_ptr<T>();
}

private:
protected:
OpenMultiDiGraph(cow_ptr_t<IOpenMultiDiGraph> ptr);

private:
cow_ptr_t<IOpenMultiDiGraph> get_ptr() const;

friend struct GraphInternal;
Expand Down Expand Up @@ -94,7 +98,7 @@ struct UpwardOpenMultiDiGraphView : virtual MultiDiGraphView {
cow_ptr_t<T>(std::forward<Args>(args)...));
}

private:
protected:
UpwardOpenMultiDiGraphView(
cow_ptr_t<IUpwardOpenMultiDiGraphView>);

Expand All @@ -103,7 +107,7 @@ struct UpwardOpenMultiDiGraphView : virtual MultiDiGraphView {
};
CHECK_WELL_BEHAVED_VALUE_TYPE_NO_EQ(UpwardOpenMultiDiGraphView);

struct UpwardOpenMultiDiGraph {
struct UpwardOpenMultiDiGraph : UpwardOpenMultiDiGraphView {
public:
using Edge = UpwardOpenMultiDiEdge;
using EdgeQuery = UpwardOpenMultiDiEdgeQuery;
Expand Down Expand Up @@ -132,15 +136,15 @@ struct UpwardOpenMultiDiGraph {
return UpwardOpenMultiDiGraph(make_cow_ptr<T>());
}

private:
UpwardOpenMultiDiGraph(std::unique_ptr<IUpwardOpenMultiDiGraph>);
protected:
UpwardOpenMultiDiGraph(cow_ptr_t<IUpwardOpenMultiDiGraph>);

private:
cow_ptr_t<IUpwardOpenMultiDiGraph> get_ptr();
cow_ptr_t<IUpwardOpenMultiDiGraph> get_ptr() const;
};
CHECK_WELL_BEHAVED_VALUE_TYPE_NO_EQ(UpwardOpenMultiDiGraph);

struct DownwardOpenMultiDiGraphView : virtual OpenMultiDiSubgraphView {
struct DownwardOpenMultiDiGraphView : virtual MultiDiGraphView {
public:
using Edge = DownwardOpenMultiDiEdge;
using EdgeQuery = DownwardOpenMultiDiEdgeQuery;
Expand All @@ -150,8 +154,8 @@ struct DownwardOpenMultiDiGraphView : virtual OpenMultiDiSubgraphView {

friend void swap(OpenMultiDiGraphView &, OpenMultiDiGraphView &);

std::unordered_set<Node> query_nodes(NodeQuery const &);
std::unordered_set<Edge> query_edges(EdgeQuery const &);
std::unordered_set<Node> query_nodes(NodeQuery const &) const;
std::unordered_set<Edge> query_edges(EdgeQuery const &) const;

template <typename T, typename... Args>
static typename std::enable_if<
Expand All @@ -162,7 +166,7 @@ struct DownwardOpenMultiDiGraphView : virtual OpenMultiDiSubgraphView {
make_cow_ptr<T>(std::forward<Args>(args)...));
}

private:
protected:
DownwardOpenMultiDiGraphView(
cow_ptr_t<Interface>);

Expand All @@ -171,15 +175,14 @@ struct DownwardOpenMultiDiGraphView : virtual OpenMultiDiSubgraphView {
};
CHECK_WELL_BEHAVED_VALUE_TYPE_NO_EQ(DownwardOpenMultiDiGraphView);

struct DownwardOpenMultiDiGraph {
struct DownwardOpenMultiDiGraph : virtual DownwardOpenMultiDiGraphView {
public:
using Edge = DownwardOpenMultiDiEdge;
using EdgeQuery = DownwardOpenMultiDiEdgeQuery;

DownwardOpenMultiDiGraph() = delete;
DownwardOpenMultiDiGraph(DownwardOpenMultiDiGraph const &);

DownwardOpenMultiDiGraph &operator=(DownwardOpenMultiDiGraph);
DownwardOpenMultiDiGraph(DownwardOpenMultiDiGraph const &) = default;
DownwardOpenMultiDiGraph &operator=(DownwardOpenMultiDiGraph const &) = default;

friend void swap(DownwardOpenMultiDiGraph &, DownwardOpenMultiDiGraph &);

Expand All @@ -190,6 +193,7 @@ struct DownwardOpenMultiDiGraph {
void add_edge(Edge const &);
void remove_edge(Edge const &);

std::unordered_set<Node> query_nodes(NodeQuery const &) const;
std::unordered_set<Edge> query_edges(EdgeQuery const &) const;

template <typename T>
Expand All @@ -200,11 +204,11 @@ struct DownwardOpenMultiDiGraph {
return DownwardOpenMultiDiGraph(make_cow_ptr<T>());
}

private:
protected:
DownwardOpenMultiDiGraph(cow_ptr_t<IDownwardOpenMultiDiGraph>);

private:
cow_ptr_t<IDownwardOpenMultiDiGraph> get_ptr();
cow_ptr_t<IDownwardOpenMultiDiGraph> get_ptr() const;
};
CHECK_WELL_BEHAVED_VALUE_TYPE_NO_EQ(DownwardOpenMultiDiGraph);

Expand Down
38 changes: 12 additions & 26 deletions lib/utils/graph/include/utils/graph/undirected.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@ struct IUndirectedGraphView : public IGraphView {
};
CHECK_RC_COPY_VIRTUAL_COMPLIANT(IUndirectedGraphView);

struct UndirectedGraphView {
struct UndirectedGraphView : virtual GraphView {
public:
using Edge = UndirectedEdge;
using EdgeQuery = UndirectedEdgeQuery;

UndirectedGraphView() = delete;

operator GraphView() const;

friend void swap(UndirectedGraphView &, UndirectedGraphView &);

std::unordered_set<Node> query_nodes(NodeQuery const &) const;
std::unordered_set<Edge> query_edges(EdgeQuery const &query) const;

Expand All @@ -47,47 +43,37 @@ struct UndirectedGraphView {
UndirectedGraphView>::type
create(Args &&...args) {
return UndirectedGraphView(
std::make_shared<T>(std::forward<Args>(args)...));
make_cow_ptr<T>(std::forward<Args>(args)...));
}

static UndirectedGraphView
unsafe_create_without_ownership(IUndirectedGraphView const &);

private:
UndirectedGraphView(std::shared_ptr<IUndirectedGraphView const> ptr);
protected:
UndirectedGraphView(cow_ptr_t<IUndirectedGraphView> ptr);

friend struct GraphInternal;

private:
std::shared_ptr<IUndirectedGraphView const> ptr;
cow_ptr_t<IUndirectedGraphView> get_ptr() const;
};
CHECK_WELL_BEHAVED_VALUE_TYPE_NO_EQ(UndirectedGraphView);

struct IUndirectedGraph : public IUndirectedGraphView, public IGraph {
struct IUndirectedGraph : public IUndirectedGraphView {
virtual void add_edge(UndirectedEdge const &) = 0;
virtual void remove_edge(UndirectedEdge const &) = 0;

virtual std::unordered_set<Node>
query_nodes(NodeQuery const &query) const override {
return static_cast<IUndirectedGraphView const *>(this)->query_nodes(query);
}
query_nodes(NodeQuery const &query) const = 0;

virtual IUndirectedGraph *clone() const override = 0;
};

struct UndirectedGraph {
struct UndirectedGraph : virtual UndirectedGraphView {
public:
using Edge = UndirectedEdge;
using EdgeQuery = UndirectedEdgeQuery;

UndirectedGraph() = delete;
UndirectedGraph(UndirectedGraph const &);

UndirectedGraph &operator=(UndirectedGraph);

operator UndirectedGraphView() const;

friend void swap(UndirectedGraph &, UndirectedGraph &);
UndirectedGraph(UndirectedGraph const &) = default;
UndirectedGraph &operator=(UndirectedGraph const &) = default;

Node add_node();
void add_node_unsafe(Node const &);
Expand All @@ -106,13 +92,13 @@ struct UndirectedGraph {
return UndirectedGraph(make_cow_ptr<T>());
}

private:
protected:
UndirectedGraph(cow_ptr_t<IUndirectedGraph>);

friend struct GraphInternal;

private:
cow_ptr_t<IUndirectedGraph> ptr;
cow_ptr_t<IUndirectedGraph> get_ptr() const;
};
CHECK_WELL_BEHAVED_VALUE_TYPE_NO_EQ(UndirectedGraph);

Expand Down
1 change: 1 addition & 0 deletions lib/utils/graph/include/utils/graph/undirected_edge.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef UTILS_GRAPH_INCLUDE_UTILS_GRAPH_UNDIRECTED_EDGE
#define UTILS_GRAPH_INCLUDE_UTILS_GRAPH_UNDIRECTED_EDGE

#include "node.h"

namespace FlexFlow {

Expand Down
Loading

0 comments on commit 8f48d5e

Please sign in to comment.