From 4655dab631f4c3b9db27cb64a0271ddbddeefb68 Mon Sep 17 00:00:00 2001 From: Jason Bock Date: Mon, 22 Jan 2024 07:31:14 -0600 Subject: [PATCH] Minor formatting cleanup --- src/Rocks/Models/EquatableArray.cs | 292 ++++++++++++++--------------- 1 file changed, 146 insertions(+), 146 deletions(-) diff --git a/src/Rocks/Models/EquatableArray.cs b/src/Rocks/Models/EquatableArray.cs index 890506d7..f2de95a3 100644 --- a/src/Rocks/Models/EquatableArray.cs +++ b/src/Rocks/Models/EquatableArray.cs @@ -13,14 +13,14 @@ namespace Rocks.Models; /// internal static class EquatableArray { - /// - /// Creates an instance from a given . - /// - /// The type of items in the input array. - /// The input instance. - /// An instance from a given . - public static EquatableArray AsEquatableArray(this ImmutableArray array) - where T : IEquatable => new(array); + /// + /// Creates an instance from a given . + /// + /// The type of items in the input array. + /// The input instance. + /// An instance from a given . + public static EquatableArray AsEquatableArray(this ImmutableArray array) + where T : IEquatable => new(array); } /// @@ -30,144 +30,144 @@ public static EquatableArray AsEquatableArray(this ImmutableArray array internal readonly struct EquatableArray : IEquatable>, IEnumerable where T : IEquatable { - /// - /// The underlying array. - /// - private readonly T[]? array; - - /// - /// Creates a new instance. - /// - /// The input to wrap. - public EquatableArray(ImmutableArray array) => - this.array = Unsafe.As, T[]?>(ref array); - - /// - /// Gets a reference to an item at a specified position within the array. - /// - /// The index of the item to retrieve a reference to. - /// A reference to an item at a specified position within the array. - public T this[int index] - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.AsImmutableArray()[index]; - } - - /// - /// Gets a value indicating whether the current array is empty. - /// - public bool IsEmpty - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.AsImmutableArray().IsEmpty; - } - - /// - /// Gets a value indicating whether the current array is default or empty. - /// - public bool IsDefaultOrEmpty - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.AsImmutableArray().IsDefaultOrEmpty; - } - - /// - /// Gets the length of the current array. - /// - public int Length - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.AsImmutableArray().Length; - } - - /// - public bool Equals(EquatableArray array) => this.AsSpan().SequenceEqual(array.AsSpan()); - - /// - public override bool Equals(object? obj) => obj is EquatableArray array && Equals(this, array); - - /// - public override unsafe int GetHashCode() - { - if (this.array is not T[] array) - { - return 0; - } - - var hashCode = 0; - - foreach (var value in array) - { - hashCode = unchecked(hashCode * (int)0xA5555529 + value.GetHashCode()); - } - - return hashCode; - } - - /// - /// Gets an instance from the current . - /// - /// The from the current . - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ImmutableArray AsImmutableArray() => Unsafe.As>(ref Unsafe.AsRef(in this.array)); - - /// - /// Creates an instance from a given . - /// - /// The input instance. - /// An instance from a given . - public static EquatableArray FromImmutableArray(ImmutableArray array) => new(array); - - /// - /// Returns a wrapping the current items. - /// - /// A wrapping the current items. - public ReadOnlySpan AsSpan() => this.AsImmutableArray().AsSpan(); - - /// - /// Copies the contents of this instance. to a mutable array. - /// - /// The newly instantiated array. - public T[] ToArray() => this.AsImmutableArray().ToArray(); - - /// - /// Gets an value to traverse items in the current array. - /// - /// An value to traverse items in the current array. - public ImmutableArray.Enumerator GetEnumerator() => this.AsImmutableArray().GetEnumerator(); - - /// - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.AsImmutableArray()).GetEnumerator(); - - /// - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.AsImmutableArray()).GetEnumerator(); - - /// - /// Implicitly converts an to . - /// - /// An instance from a given . - public static implicit operator EquatableArray(ImmutableArray array) => + /// + /// The underlying array. + /// + private readonly T[]? array; + + /// + /// Creates a new instance. + /// + /// The input to wrap. + public EquatableArray(ImmutableArray array) => + this.array = Unsafe.As, T[]?>(ref array); + + /// + /// Gets a reference to an item at a specified position within the array. + /// + /// The index of the item to retrieve a reference to. + /// A reference to an item at a specified position within the array. + public T this[int index] + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => this.AsImmutableArray()[index]; + } + + /// + /// Gets a value indicating whether the current array is empty. + /// + public bool IsEmpty + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => this.AsImmutableArray().IsEmpty; + } + + /// + /// Gets a value indicating whether the current array is default or empty. + /// + public bool IsDefaultOrEmpty + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => this.AsImmutableArray().IsDefaultOrEmpty; + } + + /// + /// Gets the length of the current array. + /// + public int Length + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => this.AsImmutableArray().Length; + } + + /// + public bool Equals(EquatableArray array) => this.AsSpan().SequenceEqual(array.AsSpan()); + + /// + public override bool Equals(object? obj) => obj is EquatableArray array && Equals(this, array); + + /// + public override unsafe int GetHashCode() + { + if (this.array is not T[] array) + { + return 0; + } + + var hashCode = 0; + + foreach (var value in array) + { + hashCode = unchecked(hashCode * (int)0xA5555529 + value.GetHashCode()); + } + + return hashCode; + } + + /// + /// Gets an instance from the current . + /// + /// The from the current . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ImmutableArray AsImmutableArray() => Unsafe.As>(ref Unsafe.AsRef(in this.array)); + + /// + /// Creates an instance from a given . + /// + /// The input instance. + /// An instance from a given . + public static EquatableArray FromImmutableArray(ImmutableArray array) => new(array); + + /// + /// Returns a wrapping the current items. + /// + /// A wrapping the current items. + public ReadOnlySpan AsSpan() => this.AsImmutableArray().AsSpan(); + + /// + /// Copies the contents of this instance. to a mutable array. + /// + /// The newly instantiated array. + public T[] ToArray() => this.AsImmutableArray().ToArray(); + + /// + /// Gets an value to traverse items in the current array. + /// + /// An value to traverse items in the current array. + public ImmutableArray.Enumerator GetEnumerator() => this.AsImmutableArray().GetEnumerator(); + + /// + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.AsImmutableArray()).GetEnumerator(); + + /// + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.AsImmutableArray()).GetEnumerator(); + + /// + /// Implicitly converts an to . + /// + /// An instance from a given . + public static implicit operator EquatableArray(ImmutableArray array) => EquatableArray.FromImmutableArray(array); - /// - /// Implicitly converts an to . - /// - /// An instance from a given . - public static implicit operator ImmutableArray(EquatableArray array) => array.AsImmutableArray(); - - /// - /// Checks whether two values are the same. - /// - /// The first value. - /// The second value. - /// Whether and are equal. - public static bool operator ==(EquatableArray left, EquatableArray right) => left.Equals(right); - - /// - /// Checks whether two values are not the same. - /// - /// The first value. - /// The second value. - /// Whether and are not equal. - public static bool operator !=(EquatableArray left, EquatableArray right) => !left.Equals(right); + /// + /// Implicitly converts an to . + /// + /// An instance from a given . + public static implicit operator ImmutableArray(EquatableArray array) => array.AsImmutableArray(); + + /// + /// Checks whether two values are the same. + /// + /// The first value. + /// The second value. + /// Whether and are equal. + public static bool operator ==(EquatableArray left, EquatableArray right) => left.Equals(right); + + /// + /// Checks whether two values are not the same. + /// + /// The first value. + /// The second value. + /// Whether and are not equal. + public static bool operator !=(EquatableArray left, EquatableArray right) => !left.Equals(right); } \ No newline at end of file