You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

IdGenOptions.h 1.4 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * 版权属于:yitter(yitter@126.com)
  3. * 开源地址:https://gitee.com/yitter/idgenerator
  4. */
  5. #pragma once
  6. #include <stdint.h>
  7. typedef struct IdGenOptions {
  8. /// 雪花计算方法,(1-漂移算法|2-传统算法),默认1
  9. uint8_t Method;
  10. /// 基础时间(ms单位),不能超过当前系统时间
  11. uint64_t BaseTime;
  12. /// 机器码,必须由外部设定,最大值 2^WorkerIdBitLength-1
  13. uint32_t WorkerId;
  14. /// 机器码位长,默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22)
  15. uint8_t WorkerIdBitLength;
  16. /// 序列数位长,默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22)
  17. uint8_t SeqBitLength;
  18. /// 最大序列数(含),设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1])
  19. uint32_t MaxSeqNumber;
  20. /// 最小序列数(含),默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位
  21. uint32_t MinSeqNumber;
  22. /// 最大漂移次数(含),默认2000,推荐范围 500-20000(与计算能力有关)
  23. uint32_t TopOverCostCount;
  24. } IdGeneratorOptions;
  25. extern IdGeneratorOptions BuildIdGenOptions(uint32_t workerId);