Refactored to use ValueTask<>
This commit is contained in:
parent
976643dd9b
commit
45e8596588
@ -22,7 +22,7 @@ namespace FastRng.Double.Distributions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetDistributedValue(CancellationToken token)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -24,7 +24,7 @@ namespace FastRng.Double.Distributions
|
|||||||
|
|
||||||
public double Scale { get; set; } = 1;
|
public double Scale { get; set; } = 1;
|
||||||
|
|
||||||
public async Task<double> GetDistributedValue(CancellationToken token)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -7,6 +7,6 @@ namespace FastRng.Double.Distributions
|
|||||||
{
|
{
|
||||||
public IRandom Random { get; set; }
|
public IRandom Random { get; set; }
|
||||||
|
|
||||||
public Task<double> GetDistributedValue(CancellationToken token);
|
public ValueTask<double> GetDistributedValue(CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ namespace FastRng.Double.Distributions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -7,6 +7,6 @@ namespace FastRng.Double.Distributions
|
|||||||
{
|
{
|
||||||
public IRandom Random { get; set; }
|
public IRandom Random { get; set; }
|
||||||
|
|
||||||
public async Task<double> GetDistributedValue(CancellationToken token = default) => this.Random == null ? 0 : await this.Random.GetUniform(token);
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default) => this.Random == null ? 0 : await this.Random.GetUniform(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,13 +6,13 @@ namespace FastRng.Double
|
|||||||
{
|
{
|
||||||
public interface IRandom
|
public interface IRandom
|
||||||
{
|
{
|
||||||
public Task<double> GetUniform(CancellationToken cancel = default);
|
public ValueTask<double> GetUniform(CancellationToken cancel = default);
|
||||||
|
|
||||||
public Task<uint> NextNumber(uint rangeStart, uint rangeEnd, IDistribution distribution, CancellationToken cancel = default);
|
public ValueTask<uint> NextNumber(uint rangeStart, uint rangeEnd, IDistribution distribution, CancellationToken cancel = default);
|
||||||
|
|
||||||
public Task<ulong> NextNumber(ulong rangeStart, ulong rangeEnd, IDistribution distribution, CancellationToken cancel = default);
|
public ValueTask<ulong> NextNumber(ulong rangeStart, ulong rangeEnd, IDistribution distribution, CancellationToken cancel = default);
|
||||||
|
|
||||||
public Task<float> NextNumber(float rangeStart, float rangeEnd, IDistribution distribution, CancellationToken cancel = default);
|
public ValueTask<float> NextNumber(float rangeStart, float rangeEnd, IDistribution distribution, CancellationToken cancel = default);
|
||||||
|
|
||||||
public void StopProducer();
|
public void StopProducer();
|
||||||
}
|
}
|
||||||
|
@ -133,9 +133,9 @@ namespace FastRng.Double
|
|||||||
|
|
||||||
#region Implementing interface
|
#region Implementing interface
|
||||||
|
|
||||||
public async Task<double> GetUniform(CancellationToken cancel = default) => await this.channelRandomUniformDistributedDouble.Reader.ReadAsync(cancel);
|
public async ValueTask<double> GetUniform(CancellationToken cancel = default) => await this.channelRandomUniformDistributedDouble.Reader.ReadAsync(cancel);
|
||||||
|
|
||||||
public async Task<uint> NextNumber(uint rangeStart, uint rangeEnd, IDistribution distribution, CancellationToken cancel = default)
|
public async ValueTask<uint> NextNumber(uint rangeStart, uint rangeEnd, IDistribution distribution, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
{
|
||||||
@ -151,7 +151,7 @@ namespace FastRng.Double
|
|||||||
return (uint) ((distributedValue * range) + rangeStart);
|
return (uint) ((distributedValue * range) + rangeStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ulong> NextNumber(ulong rangeStart, ulong rangeEnd, IDistribution distribution, CancellationToken cancel = default(CancellationToken))
|
public async ValueTask<ulong> NextNumber(ulong rangeStart, ulong rangeEnd, IDistribution distribution, CancellationToken cancel = default(CancellationToken))
|
||||||
{
|
{
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
{
|
||||||
@ -167,7 +167,7 @@ namespace FastRng.Double
|
|||||||
return (ulong) ((distributedValue * range) + rangeStart);
|
return (ulong) ((distributedValue * range) + rangeStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<float> NextNumber(float rangeStart, float rangeEnd, IDistribution distribution, CancellationToken cancel = default(CancellationToken))
|
public async ValueTask<float> NextNumber(float rangeStart, float rangeEnd, IDistribution distribution, CancellationToken cancel = default(CancellationToken))
|
||||||
{
|
{
|
||||||
if (rangeStart > rangeEnd)
|
if (rangeStart > rangeEnd)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user