C# · Keys

Keys

using Cloud.Unum.USearch; 3.0.0-rc.1 · 4c3e5023

Keys are 128 bits wide and render as lowercase dashed UUIDs, with integer identities parked in the low eight bytes, so 42UL converts implicitly and TryGetUInt64 reads one back. A full identity comes from Key.Parse("0123abcd-4567-89ef-fedc-ba9876543210"), or Key.TryParse when the text may be malformed. Parsing reads the dashes as separators rather than positions, so they may sit anywhere or nowhere, and what they leave behind must be thirty-two hexadecimal digits of either case. Key.FromGuid and Key.ToGuid carry an identity across to System.Guid, which is where a time-ordered Guid.CreateVersion7() key comes from.

API

StructKeyA 128-bit entry identity, most significant byte first, rendered as a lowercase dashed UUID.12
Types.cs:250 ↗
struct Key

Mirrors usearch_key_t.

Keys need not be unique: several entries may share one, and DenseIndex.Count reports how many. Integer identities park in the low eight bytes, so the key 42 prints as 00000000-0000-0000-0000-00000000002a.

The sixteen bytes are held in the order the ABI fixes rather than in a Guid field, whose first three groups sit little-endian in memory and would cross the boundary byte-swapped. The UUID vocabulary is reached through ToGuid and FromGuid instead, and it is what renders and parses a key.

ByteCountThe number of identity bytes a key carries.
Types.cs:253 ↗
const int ByteCount;
FromUInt64Parks an integer identity in the low eight bytes, zeroing the rest.
Types.cs:272 ↗
Key FromUInt64(ulong value);

Parameters

valueThe integer identity.

Returns

The key holding that identity.

operator KeyParks an integer identity in the low eight bytes, zeroing the rest.
Types.cs:307 ↗
implicit operator Key(ulong value);

Parameters

valueThe integer identity.
FromGuidReads a UUID's canonical byte order as an identity.
Types.cs:312 ↗
Key FromGuid(Guid identity);

Parameters

identityThe UUID.

Returns

The key its bytes spell.

ParseReads the rendering ToString produces; dashes may sit anywhere.
Types.cs:351 ↗
Key Parse(string text);

Parameters

textThe thirty-two hexadecimal digits, dashed or not.

Returns

The key those digits spell.

TryParseReads the rendering ToString produces, without throwing.
Types.cs:369 ↗
bool TryParse(string? text, out Key key);

The dashes are separators rather than positions, so they may sit anywhere or nowhere. What they leave behind must be thirty-two hexadecimal digits, of either case.

Parameters

textThe thirty-two hexadecimal digits, dashed or not.
keyThe key those digits spell, or the nil key when they do not.

Returns

True when the text parsed, false otherwise.

*× 2Compares two keys byte by byte.
Types.cs:442 ↗
bool operator==(Key left, Key right);
Symbol
operator==
operator!=

Parameters

leftThe first key.
rightThe second key.

Returns

True when every byte agrees.

TryGetUInt64Reads the integer identity in the low eight bytes.
Types.cs:286 ↗
bool TryGetUInt64(out ulong value);

Parameters

valueThe identity, when the high eight bytes carry nothing.

Returns

True when the high eight bytes are zero, false otherwise.

ToGuidReads the identity as a UUID, whose canonical byte order is the ABI's.
Types.cs:322 ↗
Guid ToGuid();

Returns

The UUID the sixteen bytes spell.

ToStringRenders the key as a lowercase dashed UUID.
Types.cs:346 ↗
override string ToString();

Returns

The thirty-six character rendering.

EqualsCompares two keys byte by byte.
Types.cs:407 ↗
bool Equals(Key other);
override bool Equals(object? other);

Compares this key against any object.

Parameters

otherThe key to compare against.

Returns

True when every byte agrees.

GetHashCodeHashes the sixteen identity bytes.
Types.cs:427 ↗
override int GetHashCode();

Returns

A hash agreeing with Equals(Key).