Skip to content

Commit

Permalink
Cleanup, fix, and update version.
Browse files Browse the repository at this point in the history
  • Loading branch information
electricessence committed Jul 4, 2021
1 parent 9cc5556 commit 9ece956
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,5 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
source/nuget.config
37 changes: 37 additions & 0 deletions Open.Numeric.Primes.sln
Original file line number Diff line number Diff line change
@@ -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
9 changes: 0 additions & 9 deletions source/MillerRabin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>.Shared.Rent(len);
var bytes = byteArray.AsSpan();
#else
var bytes = new byte[len]; // .LongLength?
#endif

for (var i = 0; i < certainty; i++)
{
Expand Down Expand Up @@ -182,10 +177,6 @@ static bool IsProbablePrimeInternal(in BigInteger source, int certainty = 10)
return false;
}

#if NETSTANDARD2_1
System.Buffers.ArrayPool<byte>.Shared.Return(byteArray);
#endif

return true;
}

Expand Down
7 changes: 4 additions & 3 deletions source/Open.Numeric.Primes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>electricessence</Authors>
<Description>
Expand All @@ -16,7 +17,7 @@
<PackageProjectUrl>https://github.com/Open-NET-Libraries/Open.Numeric.Primes/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Open-NET-Libraries/Open.Numeric.Primes/</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>2.0.0</Version>
<Version>2.0.1</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand All @@ -38,8 +39,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Open.Collections" Version="2.8.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
<PackageReference Include="Open.Collections" Version="2.10.2" />
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
Expand Down
2 changes: 1 addition & 1 deletion source/Optimized.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 0 additions & 3 deletions source/PrimalityBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Open.Numeric.Primes
{
[SuppressMessage("ReSharper", "MemberCanBeProtected.Global")]
public abstract class PrimalityBase<T> : IEnumerable<T>
where T : struct
{
Expand Down Expand Up @@ -125,7 +124,6 @@ public override IEnumerator<uint> GetEnumerator()
/// </summary>
/// <param name="value">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.</param>
/// <returns>An enumerable that will iterate every prime starting at the starting value</returns>
[SuppressMessage("ReSharper", "SuspiciousTypeConversion.Global")]
public IEnumerable<int> StartingAt(int value)
{
var absStart = (uint)Math.Abs(value);
Expand Down Expand Up @@ -317,7 +315,6 @@ public override IEnumerator<ulong> GetEnumerator()
/// </summary>
/// <param name="value">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.</param>
/// <returns>An enumerable that will iterate every prime starting at the starting value</returns>
[SuppressMessage("ReSharper", "SuspiciousTypeConversion.Global")]
public IEnumerable<long> StartingAt(long value)
{
var absStart = (ulong)Math.Abs(value);
Expand Down
2 changes: 1 addition & 1 deletion source/Primes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/// <summary>
/// Iterates the prime factors of the provided value.
Expand Down
5 changes: 2 additions & 3 deletions source/TrialDivision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ namespace Open.Numeric.Primes
public static class TrialDivision
{
public static readonly ImmutableArray<ushort> 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<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);

static readonly ushort LastKnown = FirstKnown.Last();
//static readonly ushort LastKnown = FirstKnown.Last();

public class U32 : PrimalityU32Base
{
Expand Down
2 changes: 1 addition & 1 deletion speed/Open.Numeric.Primes.Speed.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<LangVersion>preview</LangVersion>
Expand Down
16 changes: 11 additions & 5 deletions tests/Open.Numeric.Primes.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 9ece956

Please sign in to comment.