using System.Collections; namespace PkmnLib.Plugin.Gen7.SourceGen; /// /// An immutable array wrapper with sequence-based equality, so that incremental generator pipeline /// values containing collections cache correctly. /// public readonly struct EquatableArray : IEquatable>, IReadOnlyList where T : IEquatable { private readonly T[]? _array; public EquatableArray(T[] array) { _array = array; } public int Count => _array?.Length ?? 0; public T this[int index] => _array![index]; public bool Equals(EquatableArray other) { if (Count != other.Count) return false; for (var i = 0; i < Count; i++) { if (!this[i].Equals(other[i])) return false; } return true; } public override bool Equals(object? obj) => obj is EquatableArray other && Equals(other); public override int GetHashCode() { unchecked { var hash = 17; for (var i = 0; i < Count; i++) { hash = hash * 31 + this[i].GetHashCode(); } return hash; } } public IEnumerator GetEnumerator() => ((IEnumerable)(_array ?? [])).GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }