AStar/Graph/Graph.cs

62 lines
1.2 KiB
C#
Raw Normal View History

2022-11-13 14:02:27 +01:00

namespace Graph
{
public class Graph
{
2022-11-13 14:59:06 +01:00
private Dictionary<ulong, Node> nodes { get; }
2022-11-13 14:02:27 +01:00
public Graph()
{
this.nodes = new();
}
2022-11-13 14:59:06 +01:00
public bool AddNode(ulong id, Node n)
2022-11-13 14:02:27 +01:00
{
2022-11-13 14:59:06 +01:00
return this.nodes.TryAdd(id, n);
2022-11-13 14:02:27 +01:00
}
2022-11-13 14:59:06 +01:00
public Node NodeAtIndex(int i)
{
2022-11-13 14:59:06 +01:00
return this.nodes.Values.ToArray()[i];
}
public int GetNodeCount()
{
return this.nodes.Count;
}
2022-11-13 14:02:27 +01:00
public Node? GetNode(ulong id)
{
2022-11-13 14:59:06 +01:00
if (this.nodes.TryGetValue(id, out Node? n))
return n;
else
return null;
2022-11-13 14:02:27 +01:00
}
public bool ContainsNode(ulong id)
{
2022-11-13 14:59:06 +01:00
return this.nodes.ContainsKey(id);
}
public bool ContainsNode(Node n)
{
return this.nodes.Values.Contains(n);
2022-11-13 14:02:27 +01:00
}
public bool RemoveNode(ulong id)
{
2022-11-13 14:59:06 +01:00
return this.nodes.Remove(id);
2022-11-13 14:02:27 +01:00
}
public bool RemoveNode(Node n)
{
2022-11-13 14:59:06 +01:00
throw new NotImplementedException();
2022-11-13 14:02:27 +01:00
}
public Node ClosestNodeToCoordinates(float lat, float lon)
{
throw new NotImplementedException();
}
}
}