Skip to content

Commit

Permalink
Merge pull request #19 from Tynab-x-Longkunz/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Tynab authored Feb 13, 2024
2 parents d6e04b1 + c8e091f commit f6de824
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void Setup()
public void GenerateIds() => For(0, Size, index =>
{
var id = _idGenerator?.NextId() ?? 0;

lock (_generatedIds!)
{
if (!_generatedIds.Add(id))
Expand Down
5 changes: 5 additions & 0 deletions Id Generator Snowflake Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

var wkrId = GenerateRandomLong(0, 31);
var dcId = GenerateRandomLong(0, 31);

WriteLine($"WorkerId (setup): {wkrId} - DatacenterId (setup): {dcId}");

var idGen = new IdGenerator(wkrId, dcId);
var genIds = new HashSet<object>();
var numIds = 100;
Expand Down Expand Up @@ -118,6 +120,7 @@
foreach (var id in genIds.Take(top))
{
(DateTime, long, long) tupl;

switch (flow)
{
case 2:
Expand All @@ -131,12 +134,14 @@
break;
}
}

WriteLine($"Id (generated): {id} - Time (extracted): {tupl.Item1} - WorkerId (extracted): {tupl.Item2} - DatacenterId (extracted): {tupl.Item3}");
}
#endif

#if RELEASE
using Id_Generator_Snowflake_Benchmarks.Benchmarks;

using static BenchmarkDotNet.Running.BenchmarkRunner;

_ = Run<IdGeneratorBenchmarks>();
Expand Down
2 changes: 1 addition & 1 deletion Id Generator Snowflake/Common/Constant.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Id_Generator_Snowflake.Common;

internal static class Constant
internal readonly struct Constant
{
internal const int WKR_ID_BITS = 5; // Number of bits used to store the Worker Id
internal const int DC_ID_BITS = 5; // Number of bits used to store the Datacenter Id
Expand Down

0 comments on commit f6de824

Please sign in to comment.