Skip to content

API Reference

Taiizor edited this page Dec 18, 2024 · 4 revisions

📚 API Reference

UUID Struct

Constructors

public UUID()
public UUID(ulong timestamp, ulong random)

Properties

Property Type Description
Time DateTimeOffset The timestamp component of the UUID
Random ulong The random component

Methods

Basic Methods

Method Return Type Description
New() UUID Creates a new UUID
ToString() string 32-character hexadecimal string
ToBase32() string 26-character Base32 encoded string
ToBase64() string Base64 encoded string
ToByteArray() byte[] 16-byte array
ToGuid() Guid Guid conversion

Parse Methods

Method Parameters Return Type Description
Parse(string) input: string UUID Creates UUID from string
TryParse(string?, out UUID) input: string?, result: out UUID bool Safe parsing operation
FromBase64(string) base64: string UUID Creates UUID from Base64 string
TryFromBase64(string, out UUID) base64: string, result: out UUID bool Safe Base64 parsing operation
FromByteArray(byte[]) bytes: byte[] UUID Creates UUID from byte array
TryFromByteArray(byte[], out UUID) bytes: byte[], result: out UUID bool Safe byte array parsing operation

Conversion Methods

Method Parameters Return Type Description
FromGuid(Guid) guid: Guid UUID Creates UUID from Guid
TryWriteBytes(byte[]) destination: byte[] bool Writes to byte array
TryWriteStringify(char[]) destination: char[] bool Writes to char array
TryWriteBytes(Span<byte>) destination: Span<byte> bool Writes to byte span

Operators

Conversion Operators

public static implicit operator UUID(Guid guid)
public static implicit operator Guid(UUID uuid)

Comparison Operators

public static bool operator ==(UUID left, UUID right)
public static bool operator !=(UUID left, UUID right)
public static bool operator <(UUID left, UUID right)
public static bool operator <=(UUID left, UUID right)
public static bool operator >(UUID left, UUID right)
public static bool operator >=(UUID left, UUID right)

Interfaces

The UUID struct implements the following interfaces:

  • IEquatable<UUID>
  • IComparable<UUID>
  • IComparable

Constants

Constant Type Value Description
SIZE int 16 UUID size in bytes

Thread Safety

All public methods are thread-safe. Thread safety is achieved through:

  1. Immutable struct design
  2. ThreadLocal random number generator
  3. Lock-free operations

Performance Characteristics

Operation Time Complexity Space Complexity
Creation O(1) O(1)
Comparison O(1) O(1)
Parse/ToString O(n) O(n)
ToBase32/64 O(n) O(n)

Here, n represents the length of the output string, where n denotes the output size in terms of the number of characters or bytes.