修改约束条件
This commit is contained in:
@@ -30,12 +30,13 @@ namespace Yitter.IdGenerator
|
||||
/// <summary>
|
||||
/// 机器码
|
||||
/// 与 WorkerIdBitLength 有关系
|
||||
/// (ushort类型,最大值65535,如果有更高要求,请修改数据类型,或联系作者)
|
||||
/// </summary>
|
||||
public virtual ushort WorkerId { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 机器码位长
|
||||
/// 范围:2-21(要求:序列数位长+机器码位长不超过22)。
|
||||
/// 范围:1-21(要求:序列数位长+机器码位长不超过22)。
|
||||
/// 建议范围:6-12。
|
||||
/// </summary>
|
||||
public virtual byte WorkerIdBitLength { get; set; } = 6;//10;
|
||||
@@ -55,7 +56,7 @@ namespace Yitter.IdGenerator
|
||||
|
||||
/// <summary>
|
||||
/// 最小序列数(含)
|
||||
/// 默认5,不小于1,不大于MaxSeqNumber-2
|
||||
/// 默认5,不小于1,不大于MaxSeqNumber
|
||||
/// </summary>
|
||||
public virtual ushort MinSeqNumber { get; set; } = 5;
|
||||
|
||||
|
||||
@@ -30,24 +30,21 @@ namespace Yitter.IdGenerator
|
||||
|
||||
/// <summary>
|
||||
/// 机器码位长
|
||||
/// (机器码+序列数<=22位)
|
||||
/// </summary>
|
||||
protected readonly byte WorkerIdBitLength = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 自增序列数位长
|
||||
/// (机器码+序列数<=22位)
|
||||
/// </summary>
|
||||
protected readonly byte SeqBitLength = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 最大序列数(含此值)
|
||||
/// 超过最大值,就会从MinSeqNumber开始
|
||||
/// 最大序列数(含)
|
||||
/// </summary>
|
||||
protected readonly int MaxSeqNumber = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 最小序列数(含此值)
|
||||
/// 最小序列数(含)
|
||||
/// </summary>
|
||||
protected readonly ushort MinSeqNumber = 0;
|
||||
|
||||
|
||||
@@ -57,19 +57,15 @@ namespace Yitter.IdGenerator
|
||||
}
|
||||
|
||||
var maxSeqNumber = Math.Pow(2, options.SeqBitLength) - 1;
|
||||
//if (options.MaxSeqNumber > maxSeqNumber)
|
||||
//{
|
||||
// options.MaxSeqNumber = (int)maxSeqNumber;
|
||||
//}
|
||||
if (options.MaxSeqNumber < 0 || options.MaxSeqNumber > maxSeqNumber)
|
||||
{
|
||||
throw new ApplicationException("MaxSeqNumber error. (range:[1, " + maxSeqNumber + "]");
|
||||
}
|
||||
|
||||
var maxValue = maxSeqNumber;// maxSeqNumber - 2;
|
||||
var maxValue = maxSeqNumber; // maxSeqNumber - 1;
|
||||
if (options.MinSeqNumber < 1 || options.MinSeqNumber > maxValue)
|
||||
{
|
||||
throw new ApplicationException("MinSeqNumber error. (range:[5, " + maxValue + "]");
|
||||
throw new ApplicationException("MinSeqNumber error. (range:[1, " + maxValue + "]");
|
||||
}
|
||||
|
||||
switch (options.Method)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<Copyright>Yitter</Copyright>
|
||||
<PackageProjectUrl>https://gitee.com/yitter/idgenerator</PackageProjectUrl>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<Version>1.0.6</Version>
|
||||
<Version>1.0.7</Version>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user