From 9ece95677d628cf7f1df3b701b9515b2301b24ec Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Sat, 3 Jul 2021 21:08:35 -0700 Subject: [PATCH] Cleanup, fix, and update version. --- .gitignore | 3 ++- Open.Numeric.Primes.sln | 37 ++++++++++++++++++++++++++ source/MillerRabin.cs | 9 ------- source/Open.Numeric.Primes.csproj | 7 ++--- source/Optimized.cs | 2 +- source/PrimalityBase.cs | 3 --- source/Primes.cs | 2 +- source/TrialDivision.cs | 5 ++-- speed/Open.Numeric.Primes.Speed.csproj | 2 +- tests/Open.Numeric.Primes.Tests.csproj | 16 +++++++---- 10 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 Open.Numeric.Primes.sln diff --git a/.gitignore b/.gitignore index 3c4efe2..c0cc03b 100644 --- a/.gitignore +++ b/.gitignore @@ -258,4 +258,5 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc \ No newline at end of file +*.pyc +source/nuget.config diff --git a/Open.Numeric.Primes.sln b/Open.Numeric.Primes.sln new file mode 100644 index 0000000..9e3766c --- /dev/null +++ b/Open.Numeric.Primes.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31410.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.Numeric.Primes", "source\Open.Numeric.Primes.csproj", "{A1D27164-24BD-4DE5-A783-7BF93B32253B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.Numeric.Primes.Speed", "speed\Open.Numeric.Primes.Speed.csproj", "{12663275-69B7-4B4E-899B-07267780F7F0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Open.Numeric.Primes.Tests", "tests\Open.Numeric.Primes.Tests.csproj", "{AE71AD73-B001-45E7-BC34-CC220CF29CD6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A1D27164-24BD-4DE5-A783-7BF93B32253B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1D27164-24BD-4DE5-A783-7BF93B32253B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1D27164-24BD-4DE5-A783-7BF93B32253B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1D27164-24BD-4DE5-A783-7BF93B32253B}.Release|Any CPU.Build.0 = Release|Any CPU + {12663275-69B7-4B4E-899B-07267780F7F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12663275-69B7-4B4E-899B-07267780F7F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {12663275-69B7-4B4E-899B-07267780F7F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {12663275-69B7-4B4E-899B-07267780F7F0}.Release|Any CPU.Build.0 = Release|Any CPU + {AE71AD73-B001-45E7-BC34-CC220CF29CD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE71AD73-B001-45E7-BC34-CC220CF29CD6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE71AD73-B001-45E7-BC34-CC220CF29CD6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE71AD73-B001-45E7-BC34-CC220CF29CD6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6A37AACA-4943-4B9F-9877-700D44C7EFCE} + EndGlobalSection +EndGlobal diff --git a/source/MillerRabin.cs b/source/MillerRabin.cs index 59b6902..2502bc7 100644 --- a/source/MillerRabin.cs +++ b/source/MillerRabin.cs @@ -148,12 +148,7 @@ static bool IsProbablePrimeInternal(in BigInteger source, int certainty = 10) // byte arrays of the same length as the source. var rng = RandomNumberGenerator.Create(); var len = source.ToByteArray().Length; // .LongLength? -#if NETSTANDARD2_1 - var byteArray = System.Buffers.ArrayPool.Shared.Rent(len); - var bytes = byteArray.AsSpan(); -#else var bytes = new byte[len]; // .LongLength? -#endif for (var i = 0; i < certainty; i++) { @@ -182,10 +177,6 @@ static bool IsProbablePrimeInternal(in BigInteger source, int certainty = 10) return false; } -#if NETSTANDARD2_1 - System.Buffers.ArrayPool.Shared.Return(byteArray); -#endif - return true; } diff --git a/source/Open.Numeric.Primes.csproj b/source/Open.Numeric.Primes.csproj index 0184f5b..163bae1 100644 --- a/source/Open.Numeric.Primes.csproj +++ b/source/Open.Numeric.Primes.csproj @@ -4,6 +4,7 @@ netstandard2.0;netstandard2.1 latest enable + true True electricessence @@ -16,7 +17,7 @@ https://github.com/Open-NET-Libraries/Open.Numeric.Primes/ https://github.com/Open-NET-Libraries/Open.Numeric.Primes/ git - 2.0.0 + 2.0.1 MIT true @@ -38,8 +39,8 @@ - - + + diff --git a/source/Optimized.cs b/source/Optimized.cs index c6cae3c..2fdb774 100644 --- a/source/Optimized.cs +++ b/source/Optimized.cs @@ -13,7 +13,7 @@ protected override bool IsPrimeInternal(in ulong value) ? Polynomial.IsPrimeInternal(Convert.ToUInt32(value)) : MillerRabin.IsPrime(in value); - public readonly BigInt Big = new BigInt(); + public readonly BigInt Big = new(); public class BigInt : PrimalityBigIntBase { diff --git a/source/PrimalityBase.cs b/source/PrimalityBase.cs index 88bba1b..2d24733 100644 --- a/source/PrimalityBase.cs +++ b/source/PrimalityBase.cs @@ -7,7 +7,6 @@ namespace Open.Numeric.Primes { - [SuppressMessage("ReSharper", "MemberCanBeProtected.Global")] public abstract class PrimalityBase : IEnumerable where T : struct { @@ -125,7 +124,6 @@ public override IEnumerator GetEnumerator() /// /// Allows for skipping ahead any integer before checking for inclusive and subsequent primes. Passing a negative number here will produce a negative set of prime numbers. /// An enumerable that will iterate every prime starting at the starting value - [SuppressMessage("ReSharper", "SuspiciousTypeConversion.Global")] public IEnumerable StartingAt(int value) { var absStart = (uint)Math.Abs(value); @@ -317,7 +315,6 @@ public override IEnumerator GetEnumerator() /// /// Allows for skipping ahead any integer before checking for inclusive and subsequent primes. Passing a negative number here will produce a negative set of prime numbers. /// An enumerable that will iterate every prime starting at the starting value - [SuppressMessage("ReSharper", "SuspiciousTypeConversion.Global")] public IEnumerable StartingAt(long value) { var absStart = (ulong)Math.Abs(value); diff --git a/source/Primes.cs b/source/Primes.cs index ba1a201..85c5277 100644 --- a/source/Primes.cs +++ b/source/Primes.cs @@ -122,7 +122,7 @@ static double ToDouble(in float value) : double.Parse(value.ToString(CultureInfo.InvariantCulture)); } - public static readonly Optimized Numbers = new Optimized(); + public static readonly Optimized Numbers = new(); /// /// Iterates the prime factors of the provided value. diff --git a/source/TrialDivision.cs b/source/TrialDivision.cs index 4a15ff3..5817e18 100644 --- a/source/TrialDivision.cs +++ b/source/TrialDivision.cs @@ -10,10 +10,9 @@ namespace Open.Numeric.Primes public static class TrialDivision { public static readonly ImmutableArray FirstKnown - = (new ushort[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541 }) - .ToImmutableArray(); + = ImmutableArray.Create(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541); - static readonly ushort LastKnown = FirstKnown.Last(); + //static readonly ushort LastKnown = FirstKnown.Last(); public class U32 : PrimalityU32Base { diff --git a/speed/Open.Numeric.Primes.Speed.csproj b/speed/Open.Numeric.Primes.Speed.csproj index 2abf88c..a8da5eb 100644 --- a/speed/Open.Numeric.Primes.Speed.csproj +++ b/speed/Open.Numeric.Primes.Speed.csproj @@ -1,7 +1,7 @@  Exe - netcoreapp3.1 + net5.0 preview diff --git a/tests/Open.Numeric.Primes.Tests.csproj b/tests/Open.Numeric.Primes.Tests.csproj index 2fe860c..308bbbc 100644 --- a/tests/Open.Numeric.Primes.Tests.csproj +++ b/tests/Open.Numeric.Primes.Tests.csproj @@ -1,16 +1,22 @@  - netcoreapp3.1 + net5.0 false - - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +