8
8
#include < algorithm>
9
9
#include < stack>
10
10
11
- ade::Nodes ade::Node::srcNodes () const {
12
- ade::Nodes src_nodes;
11
+ own:: ade::Nodes own:: ade::Node::srcNodes () const {
12
+ own:: ade::Nodes src_nodes;
13
13
src_nodes.reserve (m_src_edges.size ());
14
- std::transform (m_src_edges.begin (), m_src_edges.end (), std::back_inserter (src_nodes), [](ade::EdgeHandle edge) {
15
- return edge->srcNode ();
16
- });
14
+ std::transform (m_src_edges.begin (),
15
+ m_src_edges.end (),
16
+ std::back_inserter (src_nodes),
17
+ [](own::ade::EdgeHandle edge) {
18
+ return edge->srcNode ();
19
+ });
17
20
// FIXME: this was introduced to make the graph
18
21
// the same every run when created the same way.
19
22
// FIXME: cache this information
20
- std::sort (src_nodes.begin (), src_nodes.end (), [&](const ade::NodeHandle& a, const ade::NodeHandle& b) {
23
+ std::sort (src_nodes.begin (), src_nodes.end (), [&](const own:: ade::NodeHandle& a, const own:: ade::NodeHandle& b) {
21
24
auto locked_graph = m_graph.lock ();
22
25
return locked_graph->meta (a).get <detail::CreateIdx>().m_idx <
23
26
locked_graph->meta (b).get <detail::CreateIdx>().m_idx ;
24
27
});
25
28
return src_nodes;
26
29
}
27
30
28
- ade::Nodes ade::Node::dstNodes () const {
29
- ade::Nodes dst_nodes;
31
+ own:: ade::Nodes own:: ade::Node::dstNodes () const {
32
+ own:: ade::Nodes dst_nodes;
30
33
dst_nodes.reserve (m_dst_edges.size ());
31
- std::transform (m_dst_edges.begin (), m_dst_edges.end (), std::back_inserter (dst_nodes), [](ade::EdgeHandle edge) {
32
- return edge->dstNode ();
33
- });
34
+ std::transform (m_dst_edges.begin (),
35
+ m_dst_edges.end (),
36
+ std::back_inserter (dst_nodes),
37
+ [](own::ade::EdgeHandle edge) {
38
+ return edge->dstNode ();
39
+ });
34
40
// FIXME: this was introduced to make the graph
35
41
// the same every run when created the same way.
36
42
// FIXME: cache this information
37
- std::sort (dst_nodes.begin (), dst_nodes.end (), [&](const ade::NodeHandle& a, const ade::NodeHandle& b) {
43
+ std::sort (dst_nodes.begin (), dst_nodes.end (), [&](const own:: ade::NodeHandle& a, const own:: ade::NodeHandle& b) {
38
44
auto locked_graph = m_graph.lock ();
39
45
return locked_graph->meta (a).get <detail::CreateIdx>().m_idx <
40
46
locked_graph->meta (b).get <detail::CreateIdx>().m_idx ;
41
47
});
42
48
return dst_nodes;
43
49
}
44
50
45
- ade::Edges ade::Node::srcEdges () const {
51
+ own:: ade::Edges own:: ade::Node::srcEdges () const {
46
52
return {m_src_edges.begin (), m_src_edges.end ()};
47
53
}
48
54
49
- ade::Edges ade::Node::dstEdges () const {
55
+ own:: ade::Edges own:: ade::Node::dstEdges () const {
50
56
return {m_dst_edges.begin (), m_dst_edges.end ()};
51
57
}
52
58
53
- ade::NodeHandle ade::Graph::create () {
54
- auto node = std::make_shared<ade::Node>(shared_from_this ());
55
- ade::NodeHandle nh (node);
56
- m_nodes.emplace (node.get (), MetaPtr<ade::Node>{node, ade::Meta{}});
59
+ own:: ade::NodeHandle own:: ade::Graph::create () {
60
+ auto node = std::make_shared<own:: ade::Node>(shared_from_this ());
61
+ own:: ade::NodeHandle nh (node);
62
+ m_nodes.emplace (node.get (), MetaPtr<own:: ade::Node>{node, own:: ade::Meta{}});
57
63
this ->meta (nh).set (detail::CreateIdx{m_create_idx++});
58
64
return nh;
59
65
}
60
66
61
- void ade::Graph::remove (ade::NodeHandle nh) {
67
+ void own:: ade::Graph::remove (own:: ade::NodeHandle nh) {
62
68
auto src_edges = nh->srcEdges ();
63
69
for (size_t i = 0 ; i < src_edges.size (); ++i) {
64
70
remove (src_edges[i]);
@@ -70,52 +76,52 @@ void ade::Graph::remove(ade::NodeHandle nh) {
70
76
m_nodes.erase (nh.get ());
71
77
}
72
78
73
- void ade::Graph::remove (ade::EdgeHandle eh) {
79
+ void own:: ade::Graph::remove (own:: ade::EdgeHandle eh) {
74
80
auto src = eh->srcNode ();
75
81
auto dst = eh->dstNode ();
76
82
src->m_dst_edges .erase (eh);
77
83
dst->m_src_edges .erase (eh);
78
84
m_edges.erase (eh.get ());
79
85
}
80
86
81
- ade::EdgeHandle ade::Graph::link (ade::NodeHandle src, ade::NodeHandle dst) {
82
- auto edge = std::make_shared<ade::Edge>(src, dst);
83
- ade::EdgeHandle eh{edge};
84
- m_edges.emplace (edge.get (), MetaPtr<ade::Edge>{edge, ade::Meta{}});
87
+ own:: ade::EdgeHandle own:: ade::Graph::link (own:: ade::NodeHandle src, own:: ade::NodeHandle dst) {
88
+ auto edge = std::make_shared<own:: ade::Edge>(src, dst);
89
+ own:: ade::EdgeHandle eh{edge};
90
+ m_edges.emplace (edge.get (), MetaPtr<own:: ade::Edge>{edge, own:: ade::Meta{}});
85
91
src->m_dst_edges .insert (eh);
86
92
dst->m_src_edges .insert (eh);
87
93
return eh;
88
94
}
89
95
90
- ade::Meta& ade::Graph::meta (ade::NodeHandle handle) {
96
+ own:: ade::Meta& own:: ade::Graph::meta (own:: ade::NodeHandle handle) {
91
97
const auto it = m_nodes.find (handle.get ());
92
98
ASSERT (it != m_nodes.end ());
93
99
return it->second .meta ;
94
100
}
95
101
96
- const ade::Meta& ade::Graph::meta (ade::NodeHandle handle) const {
102
+ const own:: ade::Meta& own:: ade::Graph::meta (own:: ade::NodeHandle handle) const {
97
103
const auto it = m_nodes.find (handle.get ());
98
104
ASSERT (it != m_nodes.end ());
99
105
return it->second .meta ;
100
106
}
101
107
102
- ade::Meta& ade::Graph::meta (ade::EdgeHandle handle) {
108
+ own:: ade::Meta& own:: ade::Graph::meta (own:: ade::EdgeHandle handle) {
103
109
const auto it = m_edges.find (handle.get ());
104
110
ASSERT (it != m_edges.end ());
105
111
return it->second .meta ;
106
112
}
107
113
108
- const ade::Meta& ade::Graph::meta (ade::EdgeHandle handle) const {
114
+ const own:: ade::Meta& own:: ade::Graph::meta (own:: ade::EdgeHandle handle) const {
109
115
const auto it = m_edges.find (handle.get ());
110
116
ASSERT (it != m_edges.end ());
111
117
return it->second .meta ;
112
118
}
113
119
114
- bool ade::Graph::contains (ade::NodeHandle handle) const {
120
+ bool own:: ade::Graph::contains (own:: ade::NodeHandle handle) const {
115
121
return m_nodes.find (handle.get ()) != m_nodes.end ();
116
122
}
117
123
118
- bool ade::Graph::linked (ade::NodeHandle src, ade::NodeHandle dst) {
124
+ bool own:: ade::Graph::linked (own:: ade::NodeHandle src, own:: ade::NodeHandle dst) {
119
125
for (const auto & edge : src->m_dst_edges ) {
120
126
if (edge->dstNode () == dst) {
121
127
return true ;
@@ -124,23 +130,23 @@ bool ade::Graph::linked(ade::NodeHandle src, ade::NodeHandle dst) {
124
130
return false ;
125
131
}
126
132
127
- std::vector<ade::NodeHandle> ade::Graph::nodes () const {
128
- std::vector<ade::NodeHandle> ret;
133
+ std::vector<own:: ade::NodeHandle> own:: ade::Graph::nodes () const {
134
+ std::vector<own:: ade::NodeHandle> ret;
129
135
std::transform (m_nodes.begin (), m_nodes.end (), std::back_inserter (ret), [](const auto & p) {
130
- return ade::NodeHandle{p.second .ptr };
136
+ return own:: ade::NodeHandle{p.second .ptr };
131
137
});
132
138
return ret;
133
139
}
134
140
135
- void ade::Graph::dfs (ade::NodeHandle& nh,
136
- std::unordered_set<ade::NodeHandle>& visited,
137
- std::stack<ade::NodeHandle>& stack) const {
141
+ void own:: ade::Graph::dfs (own:: ade::NodeHandle& nh,
142
+ std::unordered_set<own:: ade::NodeHandle>& visited,
143
+ std::stack<own:: ade::NodeHandle>& stack) const {
138
144
visited.insert (nh);
139
145
auto dst_nodes = nh->dstNodes ();
140
146
141
147
// FIXME: this was introduced to make the graph
142
148
// the same every run when created the same way.
143
- std::sort (dst_nodes.begin (), dst_nodes.end (), [&](const ade::NodeHandle& a, const ade::NodeHandle& b) {
149
+ std::sort (dst_nodes.begin (), dst_nodes.end (), [&](const own:: ade::NodeHandle& a, const own:: ade::NodeHandle& b) {
144
150
return this ->meta (a).get <detail::CreateIdx>().m_idx < this ->meta (b).get <detail::CreateIdx>().m_idx ;
145
151
});
146
152
@@ -153,14 +159,14 @@ void ade::Graph::dfs(ade::NodeHandle& nh,
153
159
stack.push (nh);
154
160
}
155
161
156
- std::vector<ade::NodeHandle> ade::Graph::sorted () const {
157
- std::unordered_set<ade::NodeHandle> visited;
158
- std::stack<ade::NodeHandle> stack;
162
+ std::vector<own:: ade::NodeHandle> own:: ade::Graph::sorted () const {
163
+ std::unordered_set<own:: ade::NodeHandle> visited;
164
+ std::stack<own:: ade::NodeHandle> stack;
159
165
auto nodes = this ->nodes ();
160
166
161
167
// FIXME: this was introduced to make the graph
162
168
// the same every run when created the same way.
163
- std::sort (nodes.begin (), nodes.end (), [&](const ade::NodeHandle& a, const ade::NodeHandle& b) {
169
+ std::sort (nodes.begin (), nodes.end (), [&](const own:: ade::NodeHandle& a, const own:: ade::NodeHandle& b) {
164
170
return this ->meta (a).get <detail::CreateIdx>().m_idx < this ->meta (b).get <detail::CreateIdx>().m_idx ;
165
171
});
166
172
@@ -170,15 +176,15 @@ std::vector<ade::NodeHandle> ade::Graph::sorted() const {
170
176
dfs (nh, visited, stack);
171
177
}
172
178
}
173
- std::vector<ade::NodeHandle> sorted;
179
+ std::vector<own:: ade::NodeHandle> sorted;
174
180
while (!stack.empty ()) {
175
181
sorted.push_back (stack.top ());
176
182
stack.pop ();
177
183
}
178
184
return sorted;
179
185
}
180
186
181
- ade::Meta& ade::Meta::operator +=(const ade::Meta& other) {
187
+ own:: ade::Meta& own:: ade::Meta::operator +=(const own:: ade::Meta& other) {
182
188
for (const auto & p : other.store ) {
183
189
ASSERT (store.emplace (p.first , p.second ).second );
184
190
}
0 commit comments