1
0
mirror of synced 2026-02-20 03:47:56 +08:00
This commit is contained in:
zhouzj
2021-03-20 22:39:52 +08:00
parent 0953456f5a
commit c50a16e205
3 changed files with 8 additions and 8 deletions

View File

@@ -4,7 +4,7 @@
* 代码修订yitter
* 开源地址https://gitee.com/yitter/idgenerator
*/
package idgen
package gen
import (
"math"
@@ -35,7 +35,7 @@ func NewDefaultIdGenerator(options *contract.IdGeneratorOptions) *DefaultIdGener
maxWorkerIdNumber := uint16(math.Pow(float64(2), float64(options.WorkerIdBitLength))) - 1
if options.WorkerId > maxWorkerIdNumber {
panic("WorkerId error. (range:[1, "+ string(maxWorkerIdNumber)+ "]")
panic("WorkerId error. (range:[1, " + string(maxWorkerIdNumber) + "]")
}
if options.SeqBitLength < 2 || options.SeqBitLength > 21 {
@@ -44,11 +44,11 @@ func NewDefaultIdGenerator(options *contract.IdGeneratorOptions) *DefaultIdGener
maxSeqNumber := uint32(math.Pow(2, float64(options.SeqBitLength))) - 1
if options.MaxSeqNumber > maxSeqNumber {
panic("MaxSeqNumber error. (range:[1, "+ string(maxSeqNumber)+ "]")
panic("MaxSeqNumber error. (range:[1, " + string(maxSeqNumber) + "]")
}
if options.MinSeqNumber > maxSeqNumber {
panic("MinSeqNumber error. (range:[1, "+ string(maxSeqNumber)+ "]")
panic("MinSeqNumber error. (range:[1, " + string(maxSeqNumber) + "]")
}
var snowWorker contract.ISnowWorker

View File

@@ -4,7 +4,7 @@
* 代码修订yitter
* 开源地址https://gitee.com/yitter/idgenerator
*/
package idgen
package gen
import (
"sync"

View File

@@ -4,12 +4,12 @@ import (
"fmt"
"time"
"yitidgen/contract"
"yitidgen/idgen"
"yitidgen/gen"
)
func main() {
// 方法一直接采用默认方法生成一个Id
var yid = idgen.YitIdHelper{}
var yid = gen.YitIdHelper{}
fmt.Println(yid.NextId())
// 方法二:自定义参数
@@ -22,7 +22,7 @@ func main() {
var times = 50000
for ; ; {
for {
var begin = time.Now().UnixNano() / 1e6
for i := 0; i < times; i++ {
yid.NextId()