-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.cs
More file actions
38 lines (32 loc) · 1.12 KB
/
Copy pathGraph.cs
File metadata and controls
38 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections.Generic;
namespace FluentApi.Graph
{
public class Graph
{
private readonly List<GraphEdge> _edges = new List<GraphEdge>();
private readonly Dictionary<string, GraphNode> _nodes = new Dictionary<string, GraphNode>();
public Graph(string graphName, bool directed, bool strict)
{
GraphName = graphName;
Directed = directed;
Strict = strict;
}
public string GraphName { get; }
public bool Directed { get; }
public bool Strict { get; }
public IEnumerable<GraphEdge> Edges => _edges;
public IEnumerable<GraphNode> Nodes => _nodes.Values;
public GraphNode AddNode(string name)
{
if (!_nodes.TryGetValue(name, out var result))
_nodes.Add(name, result = new GraphNode(name));
return result;
}
public GraphEdge AddEdge(string sourceNode, string destinationNode)
{
var result = new GraphEdge(sourceNode, destinationNode, Directed);
_edges.Add(result);
return result;
}
}
}