Struct GDID
Represents a Global Distributed ID key (key field) used in distributed databases that identify entities with a
combination of unsigned 32 bit integer 'Era' and unsigned 64 bit integer 'ID'.
The first 32 bit integer is an 'era' in which the 'ID' (64 bit) was created, consequently
a GDID is a 12 byte = 96 bit integer that can hold 2^96 = 79,228,162,514,264,337,593,543,950,336 combinations.
The ID consists of two segments: 4 bit authority + 60 bits counter. Authority segment occupies
the most significant 4 bits of uint64, so the system may efficiently query the data store to identify the highest
stored ID value in a range. Authorities identify one of 16 possible ID generation sources in the global distributed system,
therefore ID duplications are not possible between authorities.
Within a single era, GDID structure may identify
2^60 = 1,152,921,504,606,846,976(per authority) * 16(authorities) = 2^64 = 18,446,744,073,709,551,616 total combinations.
Because of such a large number of combinations supported by GDID.ID alone (having the same Era), some systems may
always use Era=0 and only store the ID part (i.e. as UNSIGNED BIGINT in SQL datastores).
Note GDID.Zero is never returned by generators as it represents the absence of a value (special value)
Implements
System.IComparable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Assembly: Azos.dll
Syntax
[Serializable]
public struct GDID : IDataStoreKey, IDistributedStableHashProvider, IComparable<GDID>, IEquatable<GDID>, IComparable, IJSONWritable
Constructors
GDID(Byte[], Int32)
Declaration
public GDID(byte[] bytes, int startIdx = 0)
Parameters
Type |
Name |
Description |
System.Byte[] |
bytes |
|
System.Int32 |
startIdx |
|
GDID(UInt32, Int32, UInt64)
Declaration
public GDID(uint era, int authority, ulong counter)
Parameters
Type |
Name |
Description |
System.UInt32 |
era |
|
System.Int32 |
authority |
|
System.UInt64 |
counter |
|
GDID(UInt32, UInt64)
Declaration
public GDID(uint era, ulong id)
Parameters
Type |
Name |
Description |
System.UInt32 |
era |
|
System.UInt64 |
id |
|
Fields
AUTHORITY_MASK
Declaration
public const ulong AUTHORITY_MASK = 17293822569102704640UL
Field Value
Type |
Description |
System.UInt64 |
|
AUTHORITY_MAX
Provides maximum value for authority segment
Declaration
public const int AUTHORITY_MAX = 15
Field Value
Type |
Description |
System.Int32 |
|
COUNTER_MASK
Declaration
public const ulong COUNTER_MASK = 1152921504606846975UL
Field Value
Type |
Description |
System.UInt64 |
|
COUNTER_MAX
Provides maximum value for counter segment
Declaration
public const ulong COUNTER_MAX = 1152921504606846975UL
Field Value
Type |
Description |
System.UInt64 |
|
Era
Declaration
Field Value
Type |
Description |
System.UInt32 |
|
ID
Declaration
Field Value
Type |
Description |
System.UInt64 |
|
Zero
Declaration
public static readonly GDID Zero
Field Value
Properties
Authority
Returns the 0..15 index of the authority that issued this ID
Declaration
public int Authority { get; }
Property Value
Type |
Description |
System.Int32 |
|
Bytes
Returns the GDID buffer as BigEndian Era:ID tuple
Declaration
public byte[] Bytes { get; }
Property Value
Type |
Description |
System.Byte[] |
|
Counter
Returns the 60 bits of counter segment of this id (without athority segment upper 4 bits)
Declaration
public ulong Counter { get; }
Property Value
Type |
Description |
System.UInt64 |
|
IsZero
True is this instance is invalid - represents 0:0:0
Declaration
public bool IsZero { get; }
Property Value
Type |
Description |
System.Boolean |
|
Methods
CompareTo(GDID)
Declaration
public int CompareTo(GDID other)
Parameters
Type |
Name |
Description |
GDID |
other |
|
Returns
Type |
Description |
System.Int32 |
|
CompareTo(Object)
Declaration
public int CompareTo(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
Returns
Type |
Description |
System.Int32 |
|
Equals(GDID)
Declaration
public bool Equals(GDID other)
Parameters
Type |
Name |
Description |
GDID |
other |
|
Returns
Type |
Description |
System.Boolean |
|
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
Returns
Type |
Description |
System.Boolean |
|
Overrides
System.ValueType.Equals(System.Object)
GetDistributedStableHash()
Declaration
public ulong GetDistributedStableHash()
Returns
Type |
Description |
System.UInt64 |
|
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type |
Description |
System.Int32 |
|
Overrides
System.ValueType.GetHashCode()
Parse(String)
Declaration
public static GDID Parse(string str)
Parameters
Type |
Name |
Description |
System.String |
str |
|
Returns
ToHexString()
Declaration
public string ToHexString()
Returns
Type |
Description |
System.String |
|
ToString()
Returns the guaranted parsable stable string representation of GDID in the form 'Era:Authority:Counter'
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Overrides
System.ValueType.ToString()
TryParse(String, out GDID)
Declaration
public static bool TryParse(string str, out GDID gdid)
Parameters
Type |
Name |
Description |
System.String |
str |
|
GDID |
gdid |
|
Returns
Type |
Description |
System.Boolean |
|
TryParse(String, out Nullable<GDID>)
Declaration
public static bool TryParse(string str, out GDID? gdid)
Parameters
Type |
Name |
Description |
System.String |
str |
|
System.Nullable<GDID> |
gdid |
|
Returns
Type |
Description |
System.Boolean |
|
WriteAsJSON(TextWriter, Int32, JSONWritingOptions)
Declaration
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null)
Parameters
Type |
Name |
Description |
System.IO.TextWriter |
wri |
|
System.Int32 |
nestingLevel |
|
JSONWritingOptions |
options |
|
Operators
Equality(GDID, GDID)
Declaration
public static bool operator ==(GDID x, GDID y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
GreaterThan(GDID, GDID)
Declaration
public static bool operator>(GDID x, GDID y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
GreaterThanOrEqual(GDID, GDID)
Declaration
public static bool operator >=(GDID x, GDID y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Inequality(GDID, GDID)
Declaration
public static bool operator !=(GDID x, GDID y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
LessThan(GDID, GDID)
Declaration
public static bool operator <(GDID x, GDID y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
LessThanOrEqual(GDID, GDID)
Declaration
public static bool operator <=(GDID x, GDID y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Implements
System.IComparable<T>
System.IEquatable<T>
System.IComparable
Extension Methods