Files
ID/Assets/Code/Lab6/Edge.cs
T
2026-02-18 10:43:12 +03:00

42 lines
973 B
C#

using System;
namespace Code.Lab6
{
[Serializable]
public class Edge : IComparable<Edge>
{
public float cost;
public readonly Vertex Vertex;
public Edge(Vertex vertex = null, float cost = 1f)
{
Vertex = vertex;
this.cost = cost;
}
public int CompareTo(Edge other)
{
var result = cost - other.cost;
var idA = Vertex.GetInstanceID();
var idB = other.Vertex.GetInstanceID();
if (idA == idB) return 0;
return (int)result;
}
public bool Equals(Edge other)
{
return other.Vertex.id == Vertex.id;
}
public override bool Equals(object obj)
{
var other = (Edge)obj;
return other != null && other.Vertex.id == Vertex.id;
}
public override int GetHashCode()
{
return Vertex.GetHashCode();
}
}
}