< Summary

Class:GDX.Collections.Generic.DictionaryPrimes
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Collections/Generic/DictionaryPrimes.cs
Covered lines:21
Uncovered lines:12
Coverable lines:33
Total lines:100
Line coverage:63.6% (21 of 33)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:6
Method coverage:50% (3 of 6)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetPrime(...)0%3.013090.91%
GetPrimeAtIndex(...)0%110100%
GetPrimesLength()0%2100%
GetNextSize(...)0%5.015093.33%
SetDefaultPrimes()0%2100%
SetPrimes(...)0%2100%

File(s)

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

#LineLine coverage
 1namespace GDX.Collections.Generic
 2{
 3    /// <summary>
 4    ///     A default selection of prime numbers used with different collections.
 5    /// </summary>
 6    public static class DictionaryPrimes
 7    {
 8        /// <summary>
 9        ///     The cached array of prime numbers.
 10        /// </summary>
 11        static int[] s_Primes;
 12        /// <summary>
 13        ///     The number of predetermined prime numbers in <see cref="s_Primes"/>.
 14        /// </summary>
 15        static int s_PrimesLength;
 16
 17        /// <summary>
 18        ///     Get the nearest prime number greater then or equal to the provided <paramref name="minimum"/>.
 19        /// </summary>
 20        /// <param name="minimum">The lowest possible value.</param>
 21        /// <returns>A prime number.</returns>
 22        public static int GetPrime(int minimum)
 6423        {
 15624            for (int i = 0; i < s_PrimesLength; i++)
 7825            {
 7826                int prime = s_Primes[i];
 14227                if (prime >= minimum) return prime;
 1428            }
 029            return int.MaxValue;
 6430        }
 31
 32        /// <summary>
 33        ///     Get the prime number in <see cref="s_Primes"/> at index.
 34        /// </summary>
 35        /// <remarks>No out of bounds detection.</remarks>
 36        /// <param name="index">The valid array index requested.</param>
 37        /// <returns>A prime number.</returns>
 38        public static int GetPrimeAtIndex(int index)
 639        {
 640            return s_Primes[index];
 641        }
 42
 43        /// <summary>
 44        ///     Get the number of prime numbers
 45        /// </summary>
 46        /// <returns></returns>
 47        public static int GetPrimesLength()
 048        {
 049            return s_PrimesLength;
 050        }
 51
 52        /// <summary>
 53        /// Returns size of hashtable to grow to.
 54        /// </summary>
 55        /// <param name="oldSize"></param>
 56        /// <returns></returns>
 57        public static int GetNextSize(int oldSize)
 1758        {
 1759            uint newSize = 2U * unchecked((uint)oldSize);
 60
 61            const int k_MaxPrime = int.MaxValue;
 1762            newSize = newSize > k_MaxPrime ? k_MaxPrime : newSize;
 63
 1764            int primesLength = s_PrimesLength;
 1765            int[] primes = s_Primes;
 66
 16467            for (int i = 0; i < primesLength; i++)
 8268            {
 8269                int prime = primes[i];
 9970                if (prime >= newSize) return prime;
 6571            }
 72
 073            return k_MaxPrime;
 1774        }
 75
 76        /// <summary>
 77        ///     Establish the default prime numbers in <see cref="s_Primes"/>.
 78        /// </summary>
 79        public static void SetDefaultPrimes()
 080        {
 081            SetPrimes( new []{
 82                17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
 83                1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591,
 84                17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437,
 85                187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263,
 86                1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369, 12582917, 25165843,
 87                50331653, 100663319, 201326611, 402653189, 805306457, 1610612741 });
 088        }
 89
 90        /// <summary>
 91        ///     Set the <see cref="s_Primes"/> array with the provided <paramref name="primes"/>.
 92        /// </summary>
 93        /// <param name="primes">An array of prime numbers.</param>
 94        public static void SetPrimes(int[] primes)
 095        {
 096            s_Primes = primes;
 097            s_PrimesLength = primes.Length;
 098        }
 99    }
 100}