1 Star 0 Fork 0

瑞哥 / rtool

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
UniqueIdQueue.go 846 Bytes
Copy Edit Raw Blame History
Your Name authored 2023-10-27 11:11 +08:00 . 2023/10/27 周五 11:11:48.12
package rtool
import (
"fmt"
"sync"
"time"
)
type AccUniqueIdQueue struct {
lock sync.Mutex
IndexID int64
QueueList []string
}
func NewUniqueIdQueue() *AccUniqueIdQueue {
return &AccUniqueIdQueue{
lock: sync.Mutex{},
IndexID: time.Now().UnixNano(),
QueueList: make([]string, 0),
}
}
func (q *AccUniqueIdQueue) RPush(uniqueID string) {
q.lock.Lock()
defer q.lock.Unlock()
q.QueueList = append(q.QueueList, uniqueID)
}
func (q *AccUniqueIdQueue) LPush(uniqueID string) {
q.lock.Lock()
defer q.lock.Unlock()
q.QueueList = append([]string{uniqueID}, q.QueueList...)
}
func (q *AccUniqueIdQueue) AutoUniqueID() string {
q.lock.Lock()
defer q.lock.Unlock()
if len(q.QueueList) <= 0 {
q.IndexID++
rt := fmt.Sprint(q.IndexID)
return rt
}
rt := q.QueueList[0]
q.QueueList = q.QueueList[1:]
return rt
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ruige_fun/rtool.git
git@gitee.com:ruige_fun/rtool.git
ruige_fun
rtool
rtool
aa158f5f2a1d

Search