Satsuma
a delicious .NET graph library
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Pages
ReverseGraph.cs
Go to the documentation of this file.
1 #region License
2 /*This file is part of Satsuma Graph Library
3 Copyright © 2013 Balázs Szalkai
4 
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source
22  distribution.*/
23 #endregion
24 
25 using System;
26 using System.Collections.Generic;
27 using System.Linq;
28 
29 namespace Satsuma
30 {
34  public sealed class ReverseGraph : IGraph
35  {
36  private IGraph graph;
37 
39  public static ArcFilter Reverse(ArcFilter filter)
40  {
41  if (filter == ArcFilter.Forward) return ArcFilter.Backward;
42  if (filter == ArcFilter.Backward) return ArcFilter.Forward;
43  return filter;
44  }
45 
46  public ReverseGraph(IGraph graph)
47  {
48  this.graph = graph;
49  }
50 
51  public Node U(Arc arc)
52  {
53  return graph.V(arc);
54  }
55 
56  public Node V(Arc arc)
57  {
58  return graph.U(arc);
59  }
60 
61  public bool IsEdge(Arc arc)
62  {
63  return graph.IsEdge(arc);
64  }
65 
66  public IEnumerable<Node> Nodes()
67  {
68  return graph.Nodes();
69  }
70 
71  public IEnumerable<Arc> Arcs(ArcFilter filter = ArcFilter.All)
72  {
73  return graph.Arcs(filter);
74  }
75 
76  public IEnumerable<Arc> Arcs(Node u, ArcFilter filter = ArcFilter.All)
77  {
78  return graph.Arcs(u, Reverse(filter));
79  }
80 
81  public IEnumerable<Arc> Arcs(Node u, Node v, ArcFilter filter = ArcFilter.All)
82  {
83  return graph.Arcs(u, v, Reverse(filter));
84  }
85 
86  public int NodeCount()
87  {
88  return graph.NodeCount();
89  }
90 
91  public int ArcCount(ArcFilter filter = ArcFilter.All)
92  {
93  return graph.ArcCount(filter);
94  }
95 
96  public int ArcCount(Node u, ArcFilter filter = ArcFilter.All)
97  {
98  return graph.ArcCount(u, Reverse(filter));
99  }
100 
101  public int ArcCount(Node u, Node v, ArcFilter filter = ArcFilter.All)
102  {
103  return graph.ArcCount(u, v, Reverse(filter));
104  }
105 
106  public bool HasNode(Node node)
107  {
108  return graph.HasNode(node);
109  }
110 
111  public bool HasArc(Arc arc)
112  {
113  return graph.HasArc(arc);
114  }
115  }
116 }