Loc.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // ReSharper disable NonReadonlyMemberInGetHashCode
  2. namespace OpenVIII
  3. {
  4. public struct Loc
  5. {
  6. #region Constructors
  7. private Loc(uint seek, uint length) => (Seek, Length) = (seek, length);
  8. #endregion Constructors
  9. #region Properties
  10. /// <summary>
  11. /// sometimes there is more than one entry at a location each is 8 bytes
  12. /// </summary>
  13. public uint Length { get; }
  14. public uint Max => Seek + Length;
  15. public uint Seek { get; }
  16. #endregion Properties
  17. #region Methods
  18. public static Loc CreateInstance(uint seek, uint length) => new Loc(seek, length);
  19. public static implicit operator Loc((uint seek, uint length) value) => new Loc(value.seek, value.length);
  20. public static implicit operator uint(Loc @input) => @input.Seek;
  21. public static bool operator !=(Loc a, Loc b) => a.Seek != b.Seek || a.Length != b.Length;
  22. public static bool operator ==(Loc a, Loc b) => a.Seek == b.Seek && a.Length == b.Length;
  23. public bool Equals(Loc other) => Seek == other.Seek && Length == other.Length;
  24. public override bool Equals(object obj) => obj is Loc other && Equals(other);
  25. public override int GetHashCode()
  26. {
  27. unchecked
  28. {
  29. return ((int)Seek * 397) ^ (int)Length;
  30. }
  31. }
  32. #endregion Methods
  33. }
  34. }