[求助]雪花算法生成ID缩短

)
workerID 单机,dataCenterID 只有一个,如何调整,41位缩短支持2030年即可,生成后的ID 例如:92235017786232830 越短越好。

41bit timestamp | 10 bit machineID : 5bit workerID 5bit dataCenterID | 12 bit sequenceBits
最多使用69年

const (
    workerIDBits     = uint64(5) // 10bit 工作机器ID中的 5bit workerID
    dataCenterIDBits = uint64(5) // 10 bit 工作机器ID中的 5bit dataCenterID
    sequenceBits     = uint64(12)
    maxWorkerID     = int64(-1) ^ (int64(-1) << workerIDBits) //节点ID的最大值 用于防止溢出
    maxDataCenterID = int64(-1) ^ (int64(-1) << dataCenterIDBits)
    maxSequence     = int64(-1) ^ (int64(-1) << sequenceBits)
    timeLeft = uint8(22) // timeLeft = workerIDBits + sequenceBits // 时间戳向左偏移量
    dataLeft = uint8(17) // dataLeft = dataCenterIDBits + sequenceBits
    workLeft = uint8(12) // workLeft = sequenceBits // 节点IDx向左偏移量
    // 2020-05-20 08:00:00 +0800 CST
    twepoch = int64(1589923200000) // 常量时间戳(毫秒)
)
最佳答案

你的意思是这样?

const (
    workerIDBits = uint64(10) // 10bit 工作机器ID
    sequenceBits = uint64(12)
    maxWorkerID  = int64(-1) ^ (int64(-1) << workerIDBits) //节点ID的最大值 用于防止溢出
    maxSequence = int64(-1) ^ (int64(-1) << sequenceBits)
    timeLeft = uint8(22) // timeLeft = workerIDBits + sequenceBits // 时间戳向左偏移量
    workLeft = uint8(12) // workLeft = sequenceBits // 节点IDx向左偏移量
    // 2020-05-20 08:00:00 +0800 CST
    twepoch = int64(1589923200000) // 常量时间戳(毫秒)
)
3年前 评论
00x00 (楼主) 3年前
讨论数量: 1
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!