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

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