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.

IdGeneratorOptions.cs 2.7 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
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
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * 版权属于:yitter(yitter@126.com)
  3. * 开源地址:https://gitee.com/yitter/idgenerator
  4. * 版权协议:MIT
  5. * 版权说明:只要保留本版权,你可以免费使用、修改、分发本代码。
  6. * 免责条款:任何因为本代码产生的系统、法律、政治、宗教问题,均与版权所有者无关。
  7. *
  8. */
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Text;
  12. namespace Yitter.IdGenerator
  13. {
  14. public class IdGeneratorOptions
  15. {
  16. /// <summary>
  17. /// 雪花计算方法
  18. /// (1-漂移算法|2-传统算法),默认1
  19. /// </summary>
  20. public virtual short Method { get; set; } = 1;
  21. /// <summary>
  22. /// 基础时间(UTC格式)
  23. /// 不能超过当前系统时间
  24. /// </summary>
  25. public virtual DateTime BaseTime { get; set; } = new DateTime(2020, 2, 20, 2, 20, 2, 20, DateTimeKind.Utc);
  26. /// <summary>
  27. /// 机器码
  28. /// 必须由外部设定,最大值 2^WorkerIdBitLength-1
  29. /// </summary>
  30. public virtual ushort WorkerId { get; set; } = 0;
  31. /// <summary>
  32. /// 机器码位长
  33. /// 默认值6,取值范围 [1, 15](要求:序列数位长+机器码位长不超过22)
  34. /// </summary>
  35. public virtual byte WorkerIdBitLength { get; set; } = 6;//10;
  36. /// <summary>
  37. /// 序列数位长
  38. /// 默认值6,取值范围 [3, 21](要求:序列数位长+机器码位长不超过22)
  39. /// </summary>
  40. public virtual byte SeqBitLength { get; set; } = 6;//10;
  41. /// <summary>
  42. /// 最大序列数(含)
  43. /// 设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,表示最大序列数取最大值(2^SeqBitLength-1])
  44. /// </summary>
  45. public virtual int MaxSeqNumber { get; set; } = 0;
  46. /// <summary>
  47. /// 最小序列数(含)
  48. /// 默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位
  49. /// </summary>
  50. public virtual ushort MinSeqNumber { get; set; } = 5;
  51. /// <summary>
  52. /// 最大漂移次数(含),
  53. /// 默认2000,推荐范围500-10000(与计算能力有关)
  54. /// </summary>
  55. public virtual int TopOverCostCount { get; set; } = 2000;
  56. public IdGeneratorOptions()
  57. {
  58. }
  59. public IdGeneratorOptions(ushort workerId)
  60. {
  61. WorkerId = workerId;
  62. }
  63. }
  64. }