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;
116 private int nodeCount;
117 private Dictionary<Node, Arc> nextArc;
118 private Dictionary<Node, Arc> prevArc;
119 private HashSet<Arc> arcs;
120 private int edgeCount;
127 nextArc =
new Dictionary<Node, Arc>();
128 prevArc =
new Dictionary<Node, Arc>();
129 arcs =
new HashSet<Arc>();
152 throw new InvalidOperationException(
"Path not empty.");
164 Node u =
U(arc), v =
V(arc);
167 throw new ArgumentException(
"Arc not valid or path is a cycle.");
169 if (newNode !=
LastNode) nodeCount++;
170 nextArc[newNode] = arc;
172 if (!arcs.Contains(arc))
175 if (
IsEdge(arc)) edgeCount++;
187 Node u =
U(arc), v =
V(arc);
190 throw new ArgumentException(
"Arc not valid or path is a cycle.");
194 prevArc[newNode] = arc;
195 if (!arcs.Contains(arc))
198 if (
IsEdge(arc)) edgeCount++;
209 { var tmp = nextArc; nextArc = prevArc; prevArc = tmp; }
215 return nextArc.TryGetValue(node, out arc) ? arc :
Arc.
Invalid;
221 return prevArc.TryGetValue(node, out arc) ? arc :
Arc.
Invalid;
248 n =
Graph.Other(arc, n);
255 if (filter ==
ArcFilter.All)
return arcs;
256 if (edgeCount == 0)
return Enumerable.Empty<
Arc>();
257 return arcs.Where(arc =>
IsEdge(arc));
262 return this.ArcsHelper(u, filter);
267 return Arcs(u, filter).Where(arc => this.Other(arc, u) == v);
277 return filter ==
ArcFilter.All ? arcs.Count : edgeCount;
282 return Arcs(u, filter).Count();
287 return Arcs(u, v, filter).Count();
297 return arcs.Contains(arc);
312 private readonly
int nodeCount;
313 private readonly
bool isCycle, directed;
316 public Node LastNode {
get {
return nodeCount > 0 ?
new Node(isCycle ? 1 : nodeCount) : Node.Invalid; } }
328 this.nodeCount = nodeCount;
329 isCycle = (topology ==
Topology.Cycle);
337 return new Node(1L + index);
344 return (
int)(node.
Id - 1);
349 if (!isCycle && node.
Id == nodeCount)
return Arc.
Invalid;
350 return new Arc(node.
Id);
356 return isCycle ?
new Arc(nodeCount) : Arc.Invalid;
357 return new Arc(node.
Id - 1);
367 return new Node(arc.
Id == nodeCount ? 1 : arc.
Id + 1);
377 for (
int i = 1; i <= nodeCount; i++)
378 yield
return new Node(i);
383 if (directed && filter ==
ArcFilter.Edge) yield
break;
384 for (
int i = 1, n = ArcCountInternal(); i <= n; i++)
385 yield
return new Arc(i);
390 return this.ArcsHelper(u, filter);
395 return Arcs(u, filter).Where(arc => this.Other(arc, u) == v);
403 private int ArcCountInternal()
405 return nodeCount == 0 ? 0 : (isCycle ? nodeCount : nodeCount - 1);
410 return directed && filter ==
ArcFilter.Edge ? 0 : ArcCountInternal();
415 return Arcs(u, filter).Count();
420 return Arcs(u, v, filter).Count();
425 return node.
Id >= 1 && node.
Id <= nodeCount;
430 return arc.
Id >= 1 && arc.
Id <= ArcCountInternal();