1
0
mirror of synced 2026-03-26 22:28:42 +08:00

修改约束条件

This commit is contained in:
zhouzj
2021-03-14 12:09:41 +08:00
parent 633f1fed03
commit 85dfbd8528
3 changed files with 49 additions and 35 deletions

View File

@@ -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 + "]");
}