2 using System.Collections.Generic;
5 using System.Threading.Tasks;
57 return path.Other(arc, node);
67 return path.Other(arc, node);
75 for (
int i = 0; i < 2; i++)
77 Arc arc = (i == 0 ? arc1 : arc2);
81 case ArcFilter.All: yield
return arc;
break;
83 case ArcFilter.Forward:
if (path.
IsEdge(arc) || path.
U(arc) == u) yield
return arc;
break;
84 case ArcFilter.Backward:
if (path.
IsEdge(arc) || path.
V(arc) == u) yield
return arc;
break;
102 private int nodeCount;
103 private Dictionary<Node, Arc> nextArc;
104 private Dictionary<Node, Arc> prevArc;
105 private HashSet<Arc> arcs;
106 private int edgeCount;
113 nextArc =
new Dictionary<Node, Arc>();
114 prevArc =
new Dictionary<Node, Arc>();
115 arcs =
new HashSet<Arc>();
138 throw new InvalidOperationException(
"Path not empty.");
150 Node u =
U(arc), v =
V(arc);
153 throw new ArgumentException(
"Arc not valid or path is a cycle.");
155 if (newNode !=
LastNode) nodeCount++;
156 nextArc[newNode] = arc;
158 if (!arcs.Contains(arc))
161 if (
IsEdge(arc)) edgeCount++;
173 Node u =
U(arc), v =
V(arc);
176 throw new ArgumentException(
"Arc not valid or path is a cycle.");
180 prevArc[newNode] = arc;
181 if (!arcs.Contains(arc))
184 if (
IsEdge(arc)) edgeCount++;
195 { var tmp = nextArc; nextArc = prevArc; prevArc = tmp; }
201 return nextArc.TryGetValue(node, out arc) ? arc :
Arc.
Invalid;
207 return prevArc.TryGetValue(node, out arc) ? arc :
Arc.
Invalid;
234 n =
Graph.Other(arc, n);
241 if (filter ==
ArcFilter.All)
return arcs;
242 if (edgeCount == 0)
return Enumerable.Empty<
Arc>();
243 return arcs.Where(arc =>
IsEdge(arc));
248 return this.ArcsHelper(u, filter);
253 return Arcs(u, filter).Where(arc => this.Other(arc, u) == v);
263 return filter ==
ArcFilter.All ? arcs.Count : edgeCount;
268 return Arcs(u, filter).Count();
273 return Arcs(u, v, filter).Count();
283 return arcs.Contains(arc);
298 private readonly
int nodeCount;
299 private readonly
bool isCycle, directed;
302 public Node LastNode {
get {
return nodeCount > 0 ?
new Node(isCycle ? 1 : nodeCount) : Node.Invalid; } }
314 this.nodeCount = nodeCount;
315 isCycle = (topology ==
Topology.Cycle);
323 return new Node(1L + index);
330 return (
int)(node.
Id - 1);
335 if (!isCycle && node.
Id == nodeCount)
return Arc.
Invalid;
336 return new Arc(node.
Id);
342 return isCycle ?
new Arc(nodeCount) : Arc.Invalid;
343 return new Arc(node.
Id - 1);
353 return new Node(arc.
Id == nodeCount ? 1 : arc.
Id + 1);
363 for (
int i = 1; i <= nodeCount; i++)
364 yield
return new Node(i);
369 if (directed && filter ==
ArcFilter.Edge) yield
break;
370 for (
int i = 1, n = ArcCountInternal(); i <= n; i++)
371 yield
return new Arc(i);
376 return this.ArcsHelper(u, filter);
381 return Arcs(u, filter).Where(arc => this.Other(arc, u) == v);
389 private int ArcCountInternal()
391 return nodeCount == 0 ? 0 : (isCycle ? nodeCount : nodeCount - 1);
396 return directed && filter ==
ArcFilter.Edge ? 0 : ArcCountInternal();
401 return Arcs(u, filter).Count();
406 return Arcs(u, v, filter).Count();
411 return node.
Id >= 1 && node.
Id <= nodeCount;
416 return arc.
Id >= 1 && arc.
Id <= ArcCountInternal();