summaryrefslogtreecommitdiffstats
path: root/IO/GraphFile.cs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-04-22 01:08:21 -0500
committerToby Vincent <tobyv13@gmail.com>2021-04-22 01:08:21 -0500
commite3c487f39f44cdecb514fd33e0f5d3f4465451b2 (patch)
treed709d682404c6aa5480837b64cf42935ce96b407 /IO/GraphFile.cs
parentf87b88ce4020ca132d4e683dac59a8dafd5d3ae2 (diff)
added more generics
Diffstat (limited to 'IO/GraphFile.cs')
-rw-r--r--IO/GraphFile.cs12
1 files changed, 7 insertions, 5 deletions
diff --git a/IO/GraphFile.cs b/IO/GraphFile.cs
index 42a1b2b..2e00eef 100644
--- a/IO/GraphFile.cs
+++ b/IO/GraphFile.cs
@@ -3,13 +3,15 @@ using Interfaces;
namespace Graph.IO
{
+ using Graph = Graph<Vertex<Edge<double>, double>, Edge<double>, double>;
+
public static class GraphFile
{
// read a graph from file using IFileReader (i.e. Dependancy injection for unit testing)
- public static Graph<double> Read(IFileReader reader)
+ public static Graph Read(IFileReader reader)
{
string[] lines = reader.Lines;
- Graph<double> graph = new Graph<double>();
+ Graph graph = new Graph();
foreach (string line in reader.Lines)
{
@@ -42,11 +44,11 @@ namespace Graph.IO
}
// write a graph to file using IFileWriter (i.e. Dependancy injection for unit testing)
- public static void Print(Graph<double> graph, IFileWriter writer)
+ public static void Print(Graph graph, IFileWriter writer)
{
// create array of strings with a size equal to vertices
string[] lines = new string[graph.Vertices.Count];
-
+
// add each vertex to it's parents output line
graph.Vertices.ForEach(vertex =>
{
@@ -57,7 +59,7 @@ namespace Graph.IO
// for vertex & parent, create string if not already
lines[vertex.Id] ??= $"{vertex.Id}";
lines[vertex.Parent] ??= $"{vertex.Parent}";
-
+
// add vertex + weight to parent's string & visa versa
lines[vertex.Parent] += $" {vertex.Id} {vertex.Key.ToString("F1")}";
lines[vertex.Id] += $" {vertex.Parent} {vertex.Key.ToString("F1")}";