Skip to content

Commit

Permalink
#7 Set TData constraint to struct 4 Nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
mfe- committed Dec 23, 2019
1 parent 016daa2 commit 40a748c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
16 changes: 2 additions & 14 deletions DataStructures/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace DataStructures
{
[DebuggerDisplay("U={U}->V={V},Edge ={Weighted}")]
[DataContract(Namespace = "http://schemas.get.com/Graph/Edges")]
public class Edge<TData> : IEdge<TData>
public class Edge<TData> where TData : struct, IEdge<TData>
{
private IVertex _u;
private IVertex _v;
Expand Down Expand Up @@ -35,19 +35,7 @@ public Edge(IVertex pu, IVertex pv, int pweighted)
_v = pv;
_weighted = pweighted;
}
/// <summary>
/// Initializes a new instance of the Edge class.
/// </summary>
/// <param name="pu">Vertex of the Edge</param>
/// <param name="pv">Vertex of the Edge</param>
/// <param name="pweighted">Sets the Weighted of the Edge</param>
public Edge(IVertex<TData> pu, IVertex<TData> pv, int pweighted)
{
_u = pu;
_v = pv;
_weighted = pweighted;
}
public TData Value { get; set; }
public TData? Value { get; set; }
/// <summary>
/// Get or sets the Vertex of the Edge
/// </summary>
Expand Down
12 changes: 6 additions & 6 deletions DataStructures/Vertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace DataStructures
{
[DebuggerDisplay("Vertex={Weighted},GUID={_Guid}")]
[DataContract(Namespace = "http://schemas.get.com/Graph/Vertex")]
public class Vertex<TData> : IVertex<TData>
public class Vertex<TData> where TData : struct, IVertex<TData>
{
private ObservableCollection<IEdge> _Edges = new ObservableCollection<IEdge>();
[DataMember(Name = "Guid", Order = 3, IsRequired = true)]
private readonly Guid _Guid;
private int _weighted;
private TData _Data;
private TData? _Data;

/// <summary>
/// Initializes a new instance of the Vertex class.
Expand All @@ -32,7 +32,7 @@ public Vertex(int pweighted)
_weighted = pweighted;
}
[DataMember(Name = "Value", Order = 0, IsRequired = false)]
public TData Value
public TData? Value
{
get { return _Data; }
set { _Data = value; NotifyPropertyChanged(nameof(Value)); }
Expand Down Expand Up @@ -69,11 +69,11 @@ public int Size
/// <param name="directed">False if the edge should be undirected (2 edges); othwise directed (1 edge)</param>
public virtual IEdge AddEdge(IVertex u, int weighted = 0, bool directed = true)
{
IEdge<TData> e1 = new Edge<TData>(this, u, weighted);
IEdge<TData> e1 = new Edge<TData>((IVertex)this, u, weighted);
_Edges.Add(e1);
if (!directed)
{
u.AddEdge((IVertex)this, weighted, true);
u?.AddEdge((IVertex)this, weighted, true);
}
return _Edges.Last();
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public override bool Equals(object obj)
return this._Guid.Equals((obj as Vertex<TData>)?._Guid);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// Returns the Hashvalue for this typ based on the internal used guid
/// </summary>
/// <returns>A hash code for the current Object.</returns>
public override int GetHashCode()
Expand Down

0 comments on commit 40a748c

Please sign in to comment.