1
0
mirror of synced 2026-04-27 10:48:41 +08:00

auto commit

This commit is contained in:
yitter
2021-04-02 22:22:55 +08:00
parent e494b91cae
commit 84d1d67dcb
22 changed files with 95 additions and 314 deletions

View File

@@ -0,0 +1,31 @@
/*
* 版权属于yitter(yitter@126.com)
* 代码编辑guoyahao
* 代码修订yitter
* 开源地址https://gitee.com/yitter/idgenerator
*/
package idgen
type IdGeneratorOptions struct {
Method uint16 // 雪花计算方法,1-漂移算法|2-传统算法默认1
BaseTime int64 // 基础时间ms单位不能超过当前系统时间
WorkerId uint16 // 机器码,与 WorkerIdBitLength 有关系
WorkerIdBitLength byte // 机器码位长范围1-21要求序列数位长+机器码位长不超过22
SeqBitLength byte // 序列数位长范围2-21要求序列数位长+机器码位长不超过22
MaxSeqNumber uint32 // 最大序列数由SeqBitLength计算的最大值
MinSeqNumber uint32 // 最小序列数默认5不小于1不大于MaxSeqNumber
TopOverCostCount uint32 // 最大漂移次数默认2000推荐范围500-10000与计算能力有关
}
func NewIdGeneratorOptions(workerId uint16) *IdGeneratorOptions {
return &IdGeneratorOptions{
Method: 1,
WorkerId: workerId,
BaseTime: 1582136402000,
WorkerIdBitLength: 6,
SeqBitLength: 6,
MaxSeqNumber: 0,
MinSeqNumber: 5,
TopOverCostCount: 2000,
}
}