Browse Source

auto commit

tags/v1.0.0
zhouzj 4 years ago
parent
commit
3a2013982f
5 changed files with 14 additions and 5 deletions
  1. +10
    -1
      C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs
  2. +1
    -1
      Go/source/contract/IdGeneratorOptions.go
  3. +1
    -1
      Java/source/src/main/java/com/yitter/contract/IdGeneratorOptions.java
  4. +1
    -1
      README.md
  5. +1
    -1
      Rust/source/src/yitgen/contract/id_generator_options.rs

+ 10
- 1
C#.NET/source/Yitter.IdGenerator/Core/SnowWorkerM1.cs View File

@@ -66,7 +66,11 @@ namespace Yitter.IdGenerator
protected int _GenCountInOneTerm = 0; protected int _GenCountInOneTerm = 0;
protected int _TermIndex = 0; protected int _TermIndex = 0;
//private static long _StartTimeTick = 0;
//private static long _BaseTimeTick = 0;
public Action<OverCostActionArg> GenAction { get; set; } public Action<OverCostActionArg> GenAction { get; set; }


public SnowWorkerM1(IdGeneratorOptions options) public SnowWorkerM1(IdGeneratorOptions options)
{ {
@@ -104,6 +108,9 @@ namespace Yitter.IdGenerator


_TimestampShift = (byte)(WorkerIdBitLength + SeqBitLength); _TimestampShift = (byte)(WorkerIdBitLength + SeqBitLength);
_CurrentSeqNumber = options.MinSeqNumber; _CurrentSeqNumber = options.MinSeqNumber;

//_BaseTimeTick = BaseTime.Ticks;
//_StartTimeTick = (long)(DateTime.UtcNow.Subtract(BaseTime).TotalMilliseconds) - Environment.TickCount;
} }
@@ -314,6 +321,8 @@ namespace Yitter.IdGenerator
protected virtual long GetCurrentTimeTick() protected virtual long GetCurrentTimeTick()
{ {
//return (long)(DateTime.UtcNow - BaseTime).Ticks;
//return (long)(_StartTimeTick + Environment.TickCount);
return (long)(DateTime.UtcNow - BaseTime).TotalMilliseconds; return (long)(DateTime.UtcNow - BaseTime).TotalMilliseconds;
} }
@@ -332,7 +341,7 @@ namespace Yitter.IdGenerator
public virtual long NextId() public virtual long NextId()
{ {
lock (_SyncLock)
lock (_SyncLock)
{ {
return _IsOverCost ? NextOverCostId() : NextNormalId(); return _IsOverCost ? NextOverCostId() : NextNormalId();
} }


+ 1
- 1
Go/source/contract/IdGeneratorOptions.go View File

@@ -8,7 +8,7 @@ package contract


type IdGeneratorOptions struct { type IdGeneratorOptions struct {
Method uint16 // 雪花计算方法,(1-漂移算法|2-传统算法),默认1 Method uint16 // 雪花计算方法,(1-漂移算法|2-传统算法),默认1
BaseTime int64 // 基础时间,不能超过当前系统时间
BaseTime int64 // 基础时间(ms单位),不能超过当前系统时间
WorkerId uint16 // 机器码,与 WorkerIdBitLength 有关系 WorkerId uint16 // 机器码,与 WorkerIdBitLength 有关系
WorkerIdBitLength byte // 机器码位长,范围:1-21(要求:序列数位长+机器码位长不超过22) WorkerIdBitLength byte // 机器码位长,范围:1-21(要求:序列数位长+机器码位长不超过22)
SeqBitLength byte // 序列数位长,范围:2-21(要求:序列数位长+机器码位长不超过22) SeqBitLength byte // 序列数位长,范围:2-21(要求:序列数位长+机器码位长不超过22)


+ 1
- 1
Java/source/src/main/java/com/yitter/contract/IdGeneratorOptions.java View File

@@ -17,7 +17,7 @@ public class IdGeneratorOptions {
public short Method = 1; public short Method = 1;
/** /**
* 基础时间
* 基础时间(ms单位)
* 不能超过当前系统时间 * 不能超过当前系统时间
*/ */
public long BaseTime = 1582136402000L; public long BaseTime = 1582136402000L;


+ 1
- 1
README.md View File

@@ -187,7 +187,7 @@ Rust:[查看示例][4]


QQ群:646049993 QQ群:646049993


即将推出 C/Rust 等版本。
即将推出 C 等版本。




[1]: https://gitee.com/yitter/idgenerator/tree/master/C%23.NET [1]: https://gitee.com/yitter/idgenerator/tree/master/C%23.NET


+ 1
- 1
Rust/source/src/yitgen/contract/id_generator_options.rs View File

@@ -6,7 +6,7 @@
pub struct IdGeneratorOptions { pub struct IdGeneratorOptions {
/// 雪花计算方法,(1-漂移算法|2-传统算法),默认1 /// 雪花计算方法,(1-漂移算法|2-传统算法),默认1
pub Method: u8, pub Method: u8,
/// 基础时间,不能超过当前系统时间
/// 基础时间(ms单位),不能超过当前系统时间
pub BaseTime: i64, pub BaseTime: i64,
/// 机器码,与 WorkerIdBitLength 有关系 /// 机器码,与 WorkerIdBitLength 有关系
pub WorkerId: u32, pub WorkerId: u32,


Loading…
Cancel
Save