< Summary

Class:GDX.ArrayExtensions
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/ArrayExtensions.cs
Covered lines:73
Uncovered lines:0
Coverable lines:73
Total lines:182
Line coverage:100% (73 of 73)
Covered branches:0
Total branches:0
Covered methods:8
Total methods:8
Method coverage:100% (8 of 8)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Clear[T]()0%110100%
ContainsItem[T](...)0%330100%
ContainsReference[T](...)0%330100%
ContainsValue[T](...)0%330100%
FirstIndexOfItem[T](...)0%330100%
FirstIndexOfValue[T](...)0%330100%
LastIndexOfItem[T](...)0%330100%
LastIndexOfValue[T](...)0%330100%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/ArrayExtensions.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Runtime.CompilerServices;
 7
 8namespace GDX
 9{
 10    /// <summary>
 11    ///     Array Based Extension Methods
 12    /// </summary>
 13    [VisualScriptingCompatible(2)]
 14    public static class ArrayExtensions
 15    {
 16        /// <summary>
 17        ///     Set all elements in an array to the default values.
 18        /// </summary>
 19        /// <remarks>
 20        ///     This does not alter the <paramref name="targetArray"/>'s length.
 21        /// </remarks>
 22        /// <param name="targetArray">The array to be defaulted.</param>
 23        /// <typeparam name="T">The type of the array.</typeparam>
 24        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 25        public static void Clear<T>(this T[] targetArray)
 126        {
 127            Array.Clear(targetArray, 0, targetArray.Length);
 128        }
 29
 30        /// <summary>
 31        ///     <para>Does <paramref name="targetArray" /> contain <paramref name="targetValue" />?</para>
 32        /// </summary>
 33        /// <param name="targetArray">The <see cref="System.Array" /> to look in.</param>
 34        /// <param name="targetValue">The target item to look for.</param>
 35        /// <typeparam name="T">The type of the <see cref="System.Array" />.</typeparam>
 36        /// <returns>true/false</returns>
 37        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 38        public static bool ContainsItem<T>(this T[] targetArray, T targetValue) where T : class
 339        {
 340            int count = targetArray.Length;
 2041            for (int i = 0; i < count; i++)
 942            {
 943                if (targetArray[i] == targetValue)
 244                {
 245                    return true;
 46                }
 747            }
 148            return false;
 349        }
 50
 51        /// <summary>
 52        ///     <para>Does <paramref name="targetArray" /> contain <paramref name="targetItem" />?</para>
 53        /// </summary>
 54        /// <remarks>Ignores equality check and end up comparing object pointers.</remarks>
 55        /// <param name="targetArray">The <see cref="System.Array" /> to look in.</param>
 56        /// <param name="targetItem">The target item to look for.</param>
 57        /// <typeparam name="T">The type of the <see cref="System.Array" />.</typeparam>
 58        /// <returns>true/false</returns>
 59        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 60        public static bool ContainsReference<T>(this T[] targetArray, T targetItem) where T : class
 261        {
 262            int count = targetArray.Length;
 1263            for (int i = 0; i < count; i++)
 564            {
 65#pragma warning disable
 66                // ReSharper disable All
 567                if ((System.Object)targetArray[i] == (System.Object)targetItem)
 168                {
 169                    return true;
 70                }
 71                // ReSharper restore All
 72#pragma warning restore
 473            }
 174            return false;
 275        }
 76
 77        /// <summary>
 78        ///     <para>Does <paramref name="targetArray" /> contain <paramref name="targetValue" />?</para>
 79        /// </summary>
 80        /// <param name="targetArray">The <see cref="System.Array" /> to look in.</param>
 81        /// <param name="targetValue">The target value to look for.</param>
 82        /// <typeparam name="T">The type of the <see cref="System.Array" />.</typeparam>
 83        /// <returns>true/false</returns>
 84        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 85        public static bool ContainsValue<T>(this T[] targetArray, T targetValue) where T : IEquatable<T>
 986        {
 987            int count = targetArray.Length;
 3288            for (int i = 0; i < count; i++)
 1589            {
 1590                if (targetArray[i].Equals(targetValue))
 891                {
 892                    return true;
 93                }
 794            }
 195            return false;
 996        }
 97
 98        /// <summary>
 99        ///     Find the first index of <paramref name="targetItem" /> in <paramref name="targetArray" />.
 100        /// </summary>
 101        /// <remarks>Ignores equality check and end up comparing object pointers.</remarks>
 102        /// <param name="targetArray">The array which to look in.</param>
 103        /// <param name="targetItem">The object to be found.</param>
 104        /// <typeparam name="T">The type of the array.</typeparam>
 105        /// <returns>The index of <paramref name="targetItem" /> in <paramref name="targetArray" />, or -1 if not found.
 106        public static int FirstIndexOfItem<T>(this T[] targetArray, T targetItem) where T : class
 2107        {
 2108            int length = targetArray.Length;
 14109            for (int i = 0; i < length; i++)
 6110            {
 6111                if (targetArray[i] == targetItem)
 1112                {
 1113                    return i;
 114                }
 5115            }
 1116            return -1;
 2117        }
 118
 119        /// <summary>
 120        ///     Find the first index of <paramref name="targetValue" /> in <paramref name="targetArray" />.
 121        /// </summary>
 122        /// <param name="targetArray">The array which to look in.</param>
 123        /// <param name="targetValue">The value to be found.</param>
 124        /// <typeparam name="T">The type of the array.</typeparam>
 125        /// <returns>The index of <paramref name="targetValue" /> in <paramref name="targetArray" />, or -1 if not found
 126        public static int FirstIndexOfValue<T>(this T[] targetArray, T targetValue) where T : struct
 2127        {
 2128            int length = targetArray.Length;
 32129            for (int i = 0; i < length; i++)
 15130            {
 15131                if (targetArray[i].Equals(targetValue))
 1132                {
 1133                    return i;
 134                }
 14135            }
 136
 1137            return -1;
 2138        }
 139
 140        /// <summary>
 141        ///     Find the last index of <paramref name="targetItem" /> in <paramref name="targetArray" />.
 142        /// </summary>
 143        /// <param name="targetArray">The array which to look in.</param>
 144        /// <param name="targetItem">The object to be found.</param>
 145        /// <typeparam name="T">The type of the array.</typeparam>
 146        /// <returns>The index of <paramref name="targetItem" /> in <paramref name="targetArray" />, or -1 if not found.
 147        public static int LastIndexOfItem<T>(this T[] targetArray, T targetItem) where T : class
 2148        {
 2149            int length = targetArray.Length;
 12150            for (int i = length - 1; i >= 0; i--)
 5151            {
 5152                if (targetArray[i] == targetItem)
 1153                {
 1154                    return i;
 155                }
 4156            }
 157
 1158            return -1;
 2159        }
 160
 161        /// <summary>
 162        ///     Find the last index of <paramref name="targetValue" /> in <paramref name="targetArray" />.
 163        /// </summary>
 164        /// <param name="targetArray">The array which to look in.</param>
 165        /// <param name="targetValue">The value to be found.</param>
 166        /// <typeparam name="T">The type of the array.</typeparam>
 167        /// <returns>The index of <paramref name="targetValue" /> in <paramref name="targetArray" />, or -1 if not found
 168        public static int LastIndexOfValue<T>(this T[] targetArray, T targetValue) where T : struct
 2169        {
 2170            int length = targetArray.Length;
 32171            for (int i = length - 1; i >= 0; i--)
 15172            {
 15173                if (targetArray[i].Equals(targetValue))
 1174                {
 1175                    return i;
 176                }
 14177            }
 178
 1179            return -1;
 2180        }
 181    }
 182}