# Keys

> USearch for Zig

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.

```zig
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`.

`const Key = @import("usearch").Key;`

## Key

A 128-bit entry identity, rendered canonically as a lowercase dashed UUID.

```zig
pub const Key = extern struct
```

Keys need not be unique: several entries may share one, and [`DenseIndex.count`](https://www.unum.cloud/docs/usearch/zig/metrics.md#count) reports how
many. Integer identities park in the low eight bytes, so `Key.fromInteger(42)` renders as
`00000000-0000-0000-0000-00000000002a`.

- `bytes` `[16]u8`: The sixteen identity bytes, most significant first.

## nil

The all-zero key.

```zig
pub const nil: Key
```

## fromInteger

Parks an integer identity in the low eight bytes, zeroing the rest.

```zig
pub fn fromInteger(value: u64) Key
```

## asInteger

The integer identity in the low eight bytes, or null when the high eight are not zero.

```zig
pub fn asInteger(self: Key) ?u64
```

## format

Renders the canonical lowercase dashed UUID, which is what `{f}` prints.

```zig
pub fn format(
    self: Key,
    writer: *std.Io.Writer,
) std.Io.Writer.Error!void
```

## parse

Reads the rendering [`format`](#format) produces, where dashes may sit anywhere or nowhere.

```zig
pub fn parse(text: []const u8) Error!Key
```

Anything but thirty-two hexadecimal digits, of either case, is [`Error.Malformed`](https://www.unum.cloud/docs/usearch/zig/errors.md#Malformed).

