1
0
mirror of synced 2026-04-19 06:48:39 +08:00

auto commit

This commit is contained in:
yitter
2021-04-05 21:21:39 +08:00
parent be0994641d
commit 2f4adc1a2e
13 changed files with 46 additions and 53 deletions

View File

@@ -84,6 +84,6 @@ func NewDefaultIdGenerator(options *IdGeneratorOptions) *DefaultIdGenerator {
}
}
func (dig DefaultIdGenerator) NewLong() uint64 {
func (dig DefaultIdGenerator) NewLong() int64 {
return dig.SnowWorker.NextId()
}

View File

@@ -7,5 +7,5 @@
package idgen
type ISnowWorker interface {
NextId() uint64
NextId() int64
}

View File

@@ -128,7 +128,7 @@ func (m1 *SnowWorkerM1) EndTurnBackAction(useTimeTick int64) {
}
func (m1 *SnowWorkerM1) NextOverCostId() uint64 {
func (m1 *SnowWorkerM1) NextOverCostId() int64 {
currentTimeTick := m1.GetCurrentTimeTick()
if currentTimeTick > m1._LastTimeTick {
m1.EndOverCostAction(currentTimeTick)
@@ -163,7 +163,7 @@ func (m1 *SnowWorkerM1) NextOverCostId() uint64 {
}
// NextNormalID .
func (m1 *SnowWorkerM1) NextNormalId() uint64 {
func (m1 *SnowWorkerM1) NextNormalId() int64 {
currentTimeTick := m1.GetCurrentTimeTick()
if currentTimeTick < m1._LastTimeTick {
if m1._TurnBackTimeTick < 1 {
@@ -209,15 +209,15 @@ func (m1 *SnowWorkerM1) NextNormalId() uint64 {
}
// CalcID .
func (m1 *SnowWorkerM1) CalcId(useTimeTick int64) uint64 {
result := uint64(useTimeTick<<m1._TimestampShift) + uint64(m1.WorkerId<<m1.SeqBitLength) + uint64(m1._CurrentSeqNumber)
func (m1 *SnowWorkerM1) CalcId(useTimeTick int64) int64 {
result := int64(useTimeTick<<m1._TimestampShift) + int64(m1.WorkerId<<m1.SeqBitLength) + int64(m1._CurrentSeqNumber)
m1._CurrentSeqNumber++
return result
}
// CalcTurnBackID .
func (m1 *SnowWorkerM1) CalcTurnBackId(useTimeTick int64) uint64 {
result := uint64(useTimeTick<<m1._TimestampShift) + uint64(m1.WorkerId<<m1.SeqBitLength) + uint64(m1._TurnBackIndex)
func (m1 *SnowWorkerM1) CalcTurnBackId(useTimeTick int64) int64 {
result := int64(useTimeTick<<m1._TimestampShift) + int64(m1.WorkerId<<m1.SeqBitLength) + int64(m1._TurnBackIndex)
m1._TurnBackTimeTick--
return result
}
@@ -238,7 +238,7 @@ func (m1 *SnowWorkerM1) GetNextTimeTick() int64 {
}
// NextId .
func (m1 *SnowWorkerM1) NextId() uint64 {
func (m1 *SnowWorkerM1) NextId() int64 {
m1.Lock()
defer m1.Unlock()
if m1._IsOverCost {

View File

@@ -21,7 +21,7 @@ func NewSnowWorkerM2(options *IdGeneratorOptions) ISnowWorker {
}
}
func (m2 SnowWorkerM2) NextId() uint64 {
func (m2 SnowWorkerM2) NextId() int64 {
m2.Lock()
defer m2.Unlock()
currentTimeTick := m2.GetCurrentTimeTick()
@@ -38,6 +38,6 @@ func (m2 SnowWorkerM2) NextId() uint64 {
fmt.Println("Time error for {0} milliseconds", strconv.FormatInt(m2._LastTimeTick-currentTimeTick, 10))
}
m2._LastTimeTick = currentTimeTick
result := uint64(currentTimeTick << m2._TimestampShift) + uint64(m2.WorkerId<<m2.SeqBitLength) + uint64(m2._CurrentSeqNumber)
result := int64(currentTimeTick << m2._TimestampShift) + int64(m2.WorkerId<<m2.SeqBitLength) + int64(m2._CurrentSeqNumber)
return result
}

View File

@@ -15,7 +15,7 @@ func SetIdGenerator(options *IdGeneratorOptions) {
}
// NextId .
func NextId() uint64 {
func NextId() int64 {
if idGenerator == nil {
singletonMutex.Lock()
defer singletonMutex.Unlock()

View File

@@ -16,7 +16,7 @@ func SetOptions(workerId uint16) {
}
//export NextId
func NextId() uint64 {
func NextId() int64 {
return idgen.NextId()
}