修改约束条件
This commit is contained in:
@@ -55,9 +55,9 @@ namespace Yitter.IdGenerator
|
||||
|
||||
/// <summary>
|
||||
/// 最小序列数(含)
|
||||
/// 默认11,不小于5,不大于MaxSeqNumber-2
|
||||
/// 默认5,不小于1,不大于MaxSeqNumber-2
|
||||
/// </summary>
|
||||
public virtual ushort MinSeqNumber { get; set; } = 11;
|
||||
public virtual ushort MinSeqNumber { get; set; } = 5;
|
||||
|
||||
/// <summary>
|
||||
/// 最大漂移次数(含),
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Yitter.IdGenerator
|
||||
}
|
||||
|
||||
var maxWorkerIdNumber = Math.Pow(2, options.WorkerIdBitLength) - 1;
|
||||
if (options.WorkerId < 1 || options.WorkerId > maxWorkerIdNumber)
|
||||
if (options.WorkerId < 0 || options.WorkerId > maxWorkerIdNumber)
|
||||
{
|
||||
throw new ApplicationException("WorkerId error. (range:[1, " + maxWorkerIdNumber + "]");
|
||||
}
|
||||
@@ -57,13 +57,18 @@ 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 - 2;
|
||||
if (options.MinSeqNumber < 5 || options.MinSeqNumber > maxValue)
|
||||
var maxValue = maxSeqNumber;// maxSeqNumber - 2;
|
||||
if (options.MinSeqNumber < 1 || options.MinSeqNumber > maxValue)
|
||||
{
|
||||
throw new ApplicationException("MinSeqNumber error. (range:[5, " + maxValue + "]");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user