namespace Ghost.Core; public interface IHandleType; public interface IIdentifierType; public readonly struct Handle where T : IHandleType { public readonly int id; public readonly int generation; public Handle(int id, int generation) { this.id = id; this.generation = generation; } public static Handle Invalid => new(-1, -1); public bool IsValid => this != Invalid; public readonly override int GetHashCode() { return id.GetHashCode(); } public readonly override bool Equals(object? obj) { return obj is Handle id && Equals(id); } public readonly bool Equals(Handle other) { return id == other.id; } public readonly int CompareTo(Handle other) { return id.CompareTo(other.id); } public static bool operator ==(Handle a, Handle b) { return a.Equals(b); } public static bool operator !=(Handle a, Handle b) { return !a.Equals(b); } } public readonly struct Identifier where T : IIdentifierType { public readonly int value; public Identifier(int value) { this.value = value; } public static Identifier Invalid => new(-1); public bool IsValid => this != Invalid; public readonly override int GetHashCode() { return value.GetHashCode(); } public readonly override bool Equals(object? obj) { return obj is Identifier id && Equals(id); } public readonly bool Equals(Identifier other) { return value == other.value; } public readonly int CompareTo(Identifier other) { return value.CompareTo(other.value); } public static bool operator ==(Identifier a, Identifier b) { return a.Equals(b); } public static bool operator !=(Identifier a, Identifier b) { return !a.Equals(b); } }