Giter Club home page Giter Club logo

it.id's People

Contributors

pairbit avatar

Watchers

 avatar

it.id's Issues

Optimize Parse

Unsafe.Add(ref Unsafe.As<Id, byte>(ref id), 15) = byte

Optimize read Timestamp

                Span buffer = stackalloc byte[8];
                buffer[0] = timestamp5;
                buffer[1] = timestamp4;
                buffer[2] = timestamp3;
                buffer[3] = timestamp2;
                buffer[4] = timestamp1;
                buffer[5] = timestamp0; // [6], [7] = 0

                var timestampMilliseconds = Unsafe.As<byte, long>(ref MemoryMarshal.GetReference(buffer));

Optimize Equals

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool EqualsCore(in Guid left, in Guid right)
{
if (Vector128.IsHardwareAccelerated)
{
return Vector128.LoadUnsafe(ref Unsafe.As<Guid, byte>(ref Unsafe.AsRef(in left))) == Vector128.LoadUnsafe(ref Unsafe.As<Guid, byte>(ref Unsafe.AsRef(in right)));
}

        ref int rA = ref Unsafe.AsRef(in left._a);
        ref int rB = ref Unsafe.AsRef(in right._a);

        // Compare each element

        return rA == rB
            && Unsafe.Add(ref rA, 1) == Unsafe.Add(ref rB, 1)
            && Unsafe.Add(ref rA, 2) == Unsafe.Add(ref rB, 2)
            && Unsafe.Add(ref rA, 3) == Unsafe.Add(ref rB, 3);
    }

Add methods To* and Parse*

ToHex
ToHexUpper
ToBase32(abc)
ToBase58(abc)
ToBase64
ToBase64Url
ToBase64Path2(char sep)
ToBase85(abc)

ParseHex
ParseBase64

Need Base32Path2 and Base32Path3?

Rename path2 to Base64Path2 (18 length)
Rename path3 to Base64Path3 (19 length)

Base32Path2 (22 length) format v/
32+32^2 = 1 056

Base32Path3 (23 length) format v//
32+32^2+32^3 = 33 824

Base64Path2 (18 length)
Win = 38^2 + 38 = 1 482
Linux = 64^2 + 64 = 4 160

Base64Path3 (19 length)
Win = 38^3 + 38^2 + 38 = 56 354
Linux = 64^3 + 64^2 + 64 = 266 304

Split bench

ToBase
ToString

ParseBase.String
Parse.String
ParseByLen.String

TryParseBase.String
TryParse.String
TryParseByLen.String

TryToBase.String
TryFormat.String

ParseBase.Bytes
Parse.Bytes
ParseByLen.Bytes

TryParseBase.Bytes
TryParse.Bytes
TryParseByLen.Bytes

Add Id32

new Id32(Id, Int32)
new Id32(Id, byte, byte, byte, byte)
new Id32(Id, short, short)

Int32 Value

Id32.New(Int32 value)
Id32.NewObjectId(Int32)

Id32 to Guid

Hex, Base32 and Base64

ToHex(int)
ToBase32(int)
ToBase64(int)

GetMaxValue(length, Idf)
GetMaxValueHex

GetLengthHex(int)
GetLengthBase32(int)
GetLength(int, Idf)

TryToHex(int, span)
TryToBase32
TryToBase64

Id32 ParseHex
Int32 ParseInt
Int32 ParseIntHex

int TryParseInt(chars, Idf)
int TryParseIntHex

Optimize new string

            Span span = stackalloc char[20];
            TryWrite(span);
            unsafe
            {
                return new string((char*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(span)), 0, 26);

Optional marker format

ToBaseUrl (without marker format)
ParseBase64

ToString(Idf format, Bool withMarker)
Parse(Idf format)

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.