-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathIDiGraph.cs
More file actions
62 lines (48 loc) · 1.37 KB
/
IDiGraph.cs
File metadata and controls
62 lines (48 loc) · 1.37 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
namespace Advanced.Algorithms.DataStructures.Graph;
/// <summary>
/// Directed graph.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IDiGraph<T>
{
bool IsWeightedGraph { get; }
IDiGraphVertex<T> ReferenceVertex { get; }
IEnumerable<IDiGraphVertex<T>> VerticesAsEnumberable { get; }
int VerticesCount { get; }
bool ContainsVertex(T value);
IDiGraphVertex<T> GetVertex(T key);
bool HasEdge(T source, T destination);
IDiGraph<T> Clone();
}
public interface IDiGraphVertex<T>
{
T Key { get; }
IEnumerable<IDiEdge<T>> OutEdges { get; }
IEnumerable<IDiEdge<T>> InEdges { get; }
int OutEdgeCount { get; }
int InEdgeCount { get; }
IDiEdge<T> GetOutEdge(IDiGraphVertex<T> targetVertex);
}
public interface IDiEdge<T>
{
T TargetVertexKey { get; }
IDiGraphVertex<T> TargetVertex { get; }
TW Weight<TW>() where TW : IComparable;
}
internal class DiEdge<T, TC> : IDiEdge<T> where TC : IComparable
{
private readonly object weight;
internal DiEdge(IDiGraphVertex<T> target, TC weight)
{
TargetVertex = target;
this.weight = weight;
}
public T TargetVertexKey => TargetVertex.Key;
public IDiGraphVertex<T> TargetVertex { get; }
public TW Weight<TW>() where TW : IComparable
{
return (TW)weight;
}
}