Skip to content

Commit

Permalink
230622
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed Jun 22, 2023
1 parent 7739a99 commit f9c2afa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="Tynab.YANLib" Version="3.1.7" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 7 additions & 2 deletions Id Generator Snowflake Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
using static Id_Generator_Snowflake.IdGenerator;
using static System.Threading.Tasks.Parallel;
using static System.Threading.Thread;
using static YANLib.YANNum;

var idGen = new IdGenerator(0, 0);
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<long>();
var numIds = 100;
var top = 10;
Expand Down Expand Up @@ -79,7 +83,8 @@

foreach (var id in genIds.Take(top))
{
WriteLine($"ID: {id} - Time: {ExtractIdComponents(id).Item1} - WorkerID: {ExtractIdComponents(id).Item2} - DatacenterID: {ExtractIdComponents(id).Item3}");
var tupl = ExtractIdComponents(id);
WriteLine($"ID (generated): {id} - Time (extracted): {tupl.Item1} - WorkerID (extracted): {tupl.Item2} - DatacenterID (extracted): {tupl.Item3}");
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions Id Generator Snowflake/Common/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

internal static class Constant
{
internal const int WKR_ID_BITS = 7; // Number of bits used to store the Worker Id
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
internal const int SEQ_BITS = 11; // Number of bits used to store the Sequence
internal const int SEQ_BITS = 13; // Number of bits used to store the Sequence

internal const long MAX_WKR_ID = -1 ^ (-1 << WKR_ID_BITS); // Maximum value of the Worker Id
internal const long MAX_DC_ID = -1 ^ (-1 << DC_ID_BITS); // Maximum value of the Datacenter Id
Expand Down

0 comments on commit f9c2afa

Please sign in to comment.