Giter Club home page Giter Club logo

unique's Introduction

unique

Tests Nuget

Unique allows for the creation of a "Deterministic Guid" which will be unique in a SpaceId over time with a high probability. The same Guid will be generated for a given Namespace ID and name.

Usage

In C# using Unique.CSharp you can use NamedGuid.NewGuid to generate a new Guid. You can check the version of the generated Guid by passing a Guid to Version.

// C# example
using Unique.CSharp;
//...
// Use the pre-defined DNS namespace
Guid uniqueIdForDns = NamedGuid.NewGuid(SpaceId.DNS, "example.com");
Console.WriteLine($"DNS example.com ID is {uniqueIdForDns}");
// OUTPUT: DNS example.com ID is cfbff0d1-9375-5685-968c-48ce8b15ae17

// Use a custom namespace Guid
Guid customGuid = Guid.Parse("AA0F4712-691F-4C72-B5EC-19730324EAFD");
Guid uniqueIdForCustomSpace = NamedGuid.NewGuid(customGuid, "[email protected]");
Console.WriteLine($"Custom [email protected] ID is {uniqueIdForCustomSpace}");
// OUTPUT: Custom [email protected] ID is dbead1ff-3f86-5d73-b577-cb00ee3fccaf

// Get the version of any Guid
int version = NamedGuid.Version(uniqueIdForCustomSpace);
Console.WriteLine($"Version is {version}");
// OUTPUT: Version is 5
// Since the default hash algorithm is SHA-1 the version is always 5
// Use Unique.NamedGuid.newGuid to define the hash algorithm.

version = NamedGuid.Version(Guid.NewGuid());
Console.WriteLine($"Version is {version}");
// OUTPUT: Version is 4

If you need to generate using a byte[] or change the algorithm, use the functions found on Unique.NamedGuid, Unique.NS and Unigue.Algorithm.

// F# example
let guid = NamedGuid.newGuid Algorithm.MD5 NS.DNS "www.example.com"
// val: 5df41881-3aed-3515-88a7-2f4a814cf09e

unique's People

Contributors

dburriss avatar

Watchers

 avatar  avatar

unique's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.