Zig · Keys

Keys

const Key = @import("usearch").Key; 3.0.0-rc.1 · 4c3e5023

A key is 128 bits of opaque identity, and integer identities park in the low eight bytes, so a UUID rendering and an integer identity sort alike. Keys need not be unique: several entries may share one, count reports how many, contains whether any, and get returns their vectors.

const key: usearch.Key = .fromInteger(42);
const value = key.asInteger(); // 42, or null when the high eight bytes are set

std.debug.print("{f}\n", .{key}); // 00000000-0000-0000-0000-00000000002a
const parsed = try usearch.Key.parse("00000000-0000-0000-0000-00000000002a");

format renders the canonical lowercase dashed UUID, so a key prints through {f} and through any writer. parse reads that rendering back, taking dashes anywhere or nowhere and either case of digit, and refusing anything else with Error.Malformed.

API

StructKeyA 128-bit entry identity, rendered canonically as a lowercase dashed UUID.5
types.zig:210 ↗
pub const Key = extern struct

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 Key.fromInteger(42) renders as 00000000-0000-0000-0000-00000000002a.

Fields

bytes[16]u8The sixteen identity bytes, most significant first.
nilThe all-zero key.
types.zig:215 ↗
pub const nil: Key
fromIntegerParks an integer identity in the low eight bytes, zeroing the rest.
types.zig:218 ↗
pub fn fromInteger(value: u64) Key
asIntegerThe integer identity in the low eight bytes, or null when the high eight are not zero.
types.zig:225 ↗
pub fn asInteger(self: Key) ?u64
formatRenders the canonical lowercase dashed UUID, which is what {f} prints.
types.zig:231 ↗
pub fn format(
    self: Key,
    writer: *std.Io.Writer,
) std.Io.Writer.Error!void
parseReads the rendering format produces, where dashes may sit anywhere or nowhere.
types.zig:241 ↗
pub fn parse(text: []const u8) Error!Key

Anything but thirty-two hexadecimal digits, of either case, is Error.Malformed.