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.5 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 StartTime { get; set; } = DateTime.MinValue;
  26. /// <summary>
  27. /// 机器码
  28. /// 与 WorkerIdBitLength 有关系
  29. /// </summary>
  30. public virtual ushort WorkerId { get; set; } = 0;
  31. /// <summary>
  32. /// 机器码位长
  33. /// 范围:2-21(要求:序列数位长+机器码位长不超过22)。
  34. /// 建议范围:6-12。
  35. /// </summary>
  36. public virtual byte WorkerIdBitLength { get; set; } = 6;//10;
  37. /// <summary>
  38. /// 序列数位长
  39. /// 范围:2-21(要求:序列数位长+机器码位长不超过22)。
  40. /// 建议范围:6-14。
  41. /// </summary>
  42. public virtual byte SeqBitLength { get; set; } = 6;//10;
  43. /// <summary>
  44. /// 最大序列数(含)
  45. /// (由SeqBitLength计算的最大值)
  46. /// </summary>
  47. public virtual int MaxSeqNumber { get; set; } = 0;
  48. /// <summary>
  49. /// 最小序列数(含)
  50. /// 默认11,不小于5,不大于MaxSeqNumber-2
  51. /// </summary>
  52. public virtual ushort MinSeqNumber { get; set; } = 11;
  53. /// <summary>
  54. /// 最大漂移次数(含),
  55. /// 默认2000,推荐范围500-10000(与计算能力有关)
  56. /// </summary>
  57. public virtual int TopOverCostCount { get; set; } = 2000;
  58. public IdGeneratorOptions()
  59. {
  60. }
  61. public IdGeneratorOptions(ushort workerId)
  62. {
  63. WorkerId = workerId;
  64. }
  65. }
  66. }

雪花算法中非常好用的数字ID生成器