Swift · Keys

Keys

import USearch 3.0.0-rc.1 · 4c3e5023

A key is sixteen opaque bytes, rendered as a lowercase dashed UUID. Integer identities park in the low eight bytes, so Key(42) prints as 00000000-0000-0000-0000-00000000002a and an integer literal is a key wherever one is expected. Keys need not be unique: several entries may share one, and count(key:) reports how many.

A key is Codable as that same string, so a document written by any SDK reads back here unchanged.

let key: Key = 42
assert(key.integerIdentity == 42)
let parsed = try Key(parsing: key.description)                             // equal to `key`
let encoded = String(decoding: try JSONEncoder().encode(key), as: UTF8.self) // "\"\(key)\""

API

StructKeyA 128-bit entry identity, most significant byte first, rendered as a lowercase dashed UUID.7
Types.swift:148 ↗
struct Key

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

Conforms to

Hashable, Comparable, CustomStringConvertible, ExpressibleByIntegerLiteral, Sendable, Equatable, Decodable, Encodable
nilKeyThe all-zero key.
Types.swift:154 ↗
static let nilKey: Key
initBuilds the all-zero key.
Types.swift:157 ↗
init()
init(_ value: UInt64)

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

init(integerLiteral value: UInt64)
init(bytes: [UInt8]) throws(USearchError)

Adopts sixteen bytes, most significant first.

init(parsing text: String) throws(USearchError)

Reads the rendering description produces.

init(from decoder: any Decoder) throws

Reads the key from the lowercase dashed rendering description produces.

byteArrayThe sixteen identity bytes, most significant first.
Types.swift:194 ↗
var byteArray: [UInt8] { get }
integerIdentityThe integer identity in the low eight bytes, and nil when the high eight carry anything.
Types.swift:197 ↗
var integerIdentity: UInt64? { get }
description
Types.swift:204 ↗
var description: String { get }
*× 3
Types.swift:218 ↗
func hash(into hasher: inout Hasher)
Symbol
hash
==
<
encodeWrites the key as that same rendering.
Types.swift:257 ↗
func encode(to encoder: any Encoder) throws