LfrlAnvil.Identifiers 0.2.1

dotnet add package LfrlAnvil.Identifiers --version 0.2.1                
NuGet\Install-Package LfrlAnvil.Identifiers -Version 0.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LfrlAnvil.Identifiers" Version="0.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LfrlAnvil.Identifiers --version 0.2.1                
#r "nuget: LfrlAnvil.Identifiers, 0.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LfrlAnvil.Identifiers as a Cake Addin
#addin nuget:?package=LfrlAnvil.Identifiers&version=0.2.1

// Install LfrlAnvil.Identifiers as a Cake Tool
#tool nuget:?package=LfrlAnvil.Identifiers&version=0.2.1                

(root) NuGet Badge

LfrlAnvil.Identifiers

This project contains a generator of sequential 64-bit identifiers based on a timestamp.

Documentation

Technical documentation can be found here.

Examples

Following is an example of the simplest way to create a generator and generate a single identifier from it:

// use an ITimestampProvider instance of your choice
// this provider will be used by the generator to get the current timestamp
// during new identifier creation
ITimestampProvider timestamps = ...;

// create a new generator instance
var generator = new IdentifierGenerator( timestamps );

// create the next identifier
var identifier = generator.Generate();

// it's also possible to extract a timestamp from an identifier
var timestamp = generator.GetTimestamp( identifier );

Identifiers consist of a 48-bit high value and a 16-bit low value.

The low value represents an ordinal from across all identifiers generated with the same high value.

The high value represents the timestamp, as a number of time units that have passed since the base timestamp of the generator. By default, the time unit, or epsilon, is defined as 1 millisecond and the base timestamp is the unix epoch. However, those values can be changed through generator options.

Be advised though, that if generated identifiers are to be consistent across multiple applications or multiple executions of the same application, then the time epsilon and the base timestamp must remain the same, especially when at least one identifier has been generated already. Otherwise, identifiers may get duplicated or their timestamp data may get corrupted.

Increasing the precision of a time epsilon has a side-effect of reducing the maximum timestamp that the generator can produce; the generator will run out of values sooner. The default time epsilon (1 milliscond) allows to create identifiers in a span of ~8925 standard years (365 days per year), with a maximum rate of 65 536 000 identifiers per second. Changing this value to e.g. 1 microsecond means that the generator will run out of values in just ~8.9 standard years, but its maximum rate of generated identifiers will be 65 536 000 000 per second.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.1 110 6/16/2024
0.2.0 100 6/16/2024
0.1.1 95 5/29/2024
0.1.0 100 5/26/2024