From bdb9fd2c1467becf53a7cbe5616f17aaa57835db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=B8=8C=E5=A4=B7?= <63851587@qq.com> Date: Wed, 14 Apr 2021 11:23:09 +0800 Subject: [PATCH] =?UTF-8?q?!12=20=E6=B3=A8=E9=87=8A=E6=B2=A1=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=88=B0=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Go/source/idgen/SnowWorkerM1.go | 30 ++++++++--------- PHP/src/snowflake/snowflake.c | 32 +++++++++---------- PHP/src/snowflake/snowflake.h | 4 +-- .../V/source/core/SnowWorkerM1.v | 30 ++++++++--------- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/Go/source/idgen/SnowWorkerM1.go b/Go/source/idgen/SnowWorkerM1.go index e60807d..a1c3f5d 100644 --- a/Go/source/idgen/SnowWorkerM1.go +++ b/Go/source/idgen/SnowWorkerM1.go @@ -28,8 +28,8 @@ type SnowWorkerM1 struct { _TurnBackIndex byte _IsOverCost bool _OverCostCountInOneTerm uint32 - _GenCountInOneTerm uint32 - _TermIndex uint32 + // _GenCountInOneTerm uint32 + // _TermIndex uint32 sync.Mutex } @@ -100,8 +100,8 @@ func NewSnowWorkerM1(options *IdGeneratorOptions) ISnowWorker { _TurnBackIndex: 0, _IsOverCost: false, _OverCostCountInOneTerm: 0, - _GenCountInOneTerm: 0, - _TermIndex: 0, + // _GenCountInOneTerm: 0, + // _TermIndex: 0, } } @@ -115,9 +115,9 @@ func (m1 *SnowWorkerM1) BeginOverCostAction(useTimeTick int64) { } func (m1 *SnowWorkerM1) EndOverCostAction(useTimeTick int64) { - if m1._TermIndex > 10000 { - m1._TermIndex = 0 - } + // if m1._TermIndex > 10000 { + // m1._TermIndex = 0 + // } } func (m1 *SnowWorkerM1) BeginTurnBackAction(useTimeTick int64) { @@ -131,21 +131,21 @@ func (m1 *SnowWorkerM1) EndTurnBackAction(useTimeTick int64) { func (m1 *SnowWorkerM1) NextOverCostId() int64 { currentTimeTick := m1.GetCurrentTimeTick() if currentTimeTick > m1._LastTimeTick { - m1.EndOverCostAction(currentTimeTick) + // m1.EndOverCostAction(currentTimeTick) m1._LastTimeTick = currentTimeTick m1._CurrentSeqNumber = m1.MinSeqNumber m1._IsOverCost = false m1._OverCostCountInOneTerm = 0 - m1._GenCountInOneTerm = 0 + // m1._GenCountInOneTerm = 0 return m1.CalcId(m1._LastTimeTick) } if m1._OverCostCountInOneTerm >= m1.TopOverCostCount { - m1.EndOverCostAction(currentTimeTick) + // m1.EndOverCostAction(currentTimeTick) m1._LastTimeTick = m1.GetNextTimeTick() m1._CurrentSeqNumber = m1.MinSeqNumber m1._IsOverCost = false m1._OverCostCountInOneTerm = 0 - m1._GenCountInOneTerm = 0 + // m1._GenCountInOneTerm = 0 return m1.CalcId(m1._LastTimeTick) } if m1._CurrentSeqNumber > m1.MaxSeqNumber { @@ -153,12 +153,12 @@ func (m1 *SnowWorkerM1) NextOverCostId() int64 { m1._CurrentSeqNumber = m1.MinSeqNumber m1._IsOverCost = true m1._OverCostCountInOneTerm++ - m1._GenCountInOneTerm++ + // m1._GenCountInOneTerm++ return m1.CalcId(m1._LastTimeTick) } - m1._GenCountInOneTerm++ + // m1._GenCountInOneTerm++ return m1.CalcId(m1._LastTimeTick) } @@ -195,12 +195,12 @@ func (m1 *SnowWorkerM1) NextNormalId() int64 { if m1._CurrentSeqNumber > m1.MaxSeqNumber { m1.BeginOverCostAction(currentTimeTick) - m1._TermIndex++ + // m1._TermIndex++ m1._LastTimeTick++ m1._CurrentSeqNumber = m1.MinSeqNumber m1._IsOverCost = true m1._OverCostCountInOneTerm = 1 - m1._GenCountInOneTerm = 1 + // m1._GenCountInOneTerm = 1 return m1.CalcId(m1._LastTimeTick) } diff --git a/PHP/src/snowflake/snowflake.c b/PHP/src/snowflake/snowflake.c index 2db5555..f7e0aa1 100644 --- a/PHP/src/snowflake/snowflake.c +++ b/PHP/src/snowflake/snowflake.c @@ -8,7 +8,7 @@ #include "windows.h" #endif -static void EndOverCostAction(uint64_t useTimeTick, snowflake *flake); +// static void EndOverCostAction(uint64_t useTimeTick, snowflake *flake); static inline uint64_t NextOverCostId(snowflake *flake); static inline uint64_t NextNormalId(snowflake *flake); static inline uint64_t GetCurrentTimeTick(snowflake *flake); @@ -121,35 +121,35 @@ void Config(snowflake *flake) flake->Method = flake->Method; } -static inline void EndOverCostAction(uint64_t useTimeTick, snowflake *flake) -{ - if (flake->_TermIndex > 10000) - { - flake->_TermIndex = 0; - } -} +// static inline void EndOverCostAction(uint64_t useTimeTick, snowflake *flake) +// { +// if (flake->_TermIndex > 10000) +// { +// flake->_TermIndex = 0; +// } +// } static inline uint64_t NextOverCostId(snowflake *flake) { uint64_t currentTimeTick = GetCurrentTimeTick(flake); if (currentTimeTick > flake->_LastTimeTick) { - EndOverCostAction(currentTimeTick, flake); + // EndOverCostAction(currentTimeTick, flake); flake->_LastTimeTick = currentTimeTick; flake->_CurrentSeqNumber = flake->MinSeqNumber; flake->_IsOverCost = 0; flake->_OverCostCountInOneTerm = 0; - flake->_GenCountInOneTerm = 0; + // flake->_GenCountInOneTerm = 0; return CalcId(flake); } if (flake->_OverCostCountInOneTerm > flake->TopOverCostCount) { - EndOverCostAction(currentTimeTick, flake); + // EndOverCostAction(currentTimeTick, flake); flake->_LastTimeTick = GetNextTimeTick(flake); flake->_CurrentSeqNumber = flake->MinSeqNumber; flake->_IsOverCost = 0; flake->_OverCostCountInOneTerm = 0; - flake->_GenCountInOneTerm = 0; + // flake->_GenCountInOneTerm = 0; return CalcId(flake); } if (flake->_CurrentSeqNumber > flake->MaxSeqNumber) @@ -158,11 +158,11 @@ static inline uint64_t NextOverCostId(snowflake *flake) flake->_CurrentSeqNumber = flake->MinSeqNumber; flake->_IsOverCost = 1; flake->_OverCostCountInOneTerm++; - flake->_GenCountInOneTerm++; + // flake->_GenCountInOneTerm++; return CalcId(flake); } - flake->_GenCountInOneTerm++; + // flake->_GenCountInOneTerm++; return CalcId(flake); } @@ -194,12 +194,12 @@ static inline uint64_t NextNormalId(snowflake *flake) } if (flake->_CurrentSeqNumber > flake->MaxSeqNumber) { - flake->_TermIndex++; + // flake->_TermIndex++; flake->_LastTimeTick++; flake->_CurrentSeqNumber = flake->MinSeqNumber; flake->_IsOverCost = 1; flake->_OverCostCountInOneTerm = 1; - flake->_GenCountInOneTerm = 1; + // flake->_GenCountInOneTerm = 1; return CalcId(flake); } return CalcId(flake); diff --git a/PHP/src/snowflake/snowflake.h b/PHP/src/snowflake/snowflake.h index 7e2ac13..00fde18 100644 --- a/PHP/src/snowflake/snowflake.h +++ b/PHP/src/snowflake/snowflake.h @@ -18,8 +18,8 @@ typedef struct snowflake uint8_t _TurnBackIndex; uint8_t _IsOverCost; uint32_t _OverCostCountInOneTerm; - uint32_t _GenCountInOneTerm; - uint32_t _TermIndex; + // uint32_t _GenCountInOneTerm; + // uint32_t _TermIndex; volatile unsigned int _Lock; } snowflake; diff --git a/zzz-OtherLanguages/V/source/core/SnowWorkerM1.v b/zzz-OtherLanguages/V/source/core/SnowWorkerM1.v index 92080d4..d9aead1 100644 --- a/zzz-OtherLanguages/V/source/core/SnowWorkerM1.v +++ b/zzz-OtherLanguages/V/source/core/SnowWorkerM1.v @@ -25,8 +25,8 @@ mut: turnback_index byte is_over_cost bool overcostcount_inoneterm u32 - gencount_inoneterm u32 - term_index u32 + // gencount_inoneterm u32 + // term_index u32 } pub fn make_sf_m1(options &contract.IdGeneratorOptions) &contract.ISnowWorker { @@ -78,11 +78,11 @@ pub fn make_sf_m1(options &contract.IdGeneratorOptions) &contract.ISnowWorker { // } -fn (mut m1 SnowWorkerM1) end_over_cost_action() { - if m1.term_index > 10000 { - m1.term_index = 0 - } -} +// fn (mut m1 SnowWorkerM1) end_over_cost_action() { +// if m1.term_index > 10000 { +// m1.term_index = 0 +// } +// } // fn (m1 &SnowWorkerM1) begin_turn_back_action(use_time_tick i64) { @@ -95,21 +95,21 @@ fn (mut m1 SnowWorkerM1) end_over_cost_action() { fn (mut m1 SnowWorkerM1) next_over_cost_id() u64 { current_time_tick := m1.get_current_time_tick() if current_time_tick > m1.last_time_tick { - m1.end_over_cost_action() + // m1.end_over_cost_action() m1.last_time_tick = current_time_tick m1.current_seqnumber = m1.min_seqnumber m1.is_over_cost = false m1.overcostcount_inoneterm = 0 - m1.gencount_inoneterm = 0 + // m1.gencount_inoneterm = 0 return m1.calc_id() } if m1.overcostcount_inoneterm >= m1.top_over_cost_count { - m1.end_over_cost_action() + // m1.end_over_cost_action() m1.last_time_tick = m1.get_next_time_tick() m1.current_seqnumber = m1.min_seqnumber m1.is_over_cost = false m1.overcostcount_inoneterm = 0 - m1.gencount_inoneterm = 0 + // m1.gencount_inoneterm = 0 return m1.calc_id() } if m1.current_seqnumber > m1.max_seqnumber { @@ -117,11 +117,11 @@ fn (mut m1 SnowWorkerM1) next_over_cost_id() u64 { m1.current_seqnumber = m1.min_seqnumber m1.is_over_cost = true m1.overcostcount_inoneterm++ - m1.gencount_inoneterm++ + // m1.gencount_inoneterm++ return m1.calc_id() } - m1.gencount_inoneterm++ + // m1.gencount_inoneterm++ return m1.calc_id() } @@ -152,12 +152,12 @@ fn (mut m1 SnowWorkerM1) next_normal_id() u64 { } if m1.current_seqnumber > m1.max_seqnumber { // m1.begin_over_cost_action(current_time_tick) - m1.term_index++ + // m1.term_index++ m1.last_time_tick++ m1.current_seqnumber = m1.min_seqnumber m1.is_over_cost = true m1.overcostcount_inoneterm = 1 - m1.gencount_inoneterm = 1 + // m1.gencount_inoneterm = 1 return m1.calc_id() }