Go · Keys

Keys

import "github.com/unum-cloud/USearch/golang" 3.0.0-rc.1 · 4c3e5023

A key is 128 bits of opaque identity, rendered as a lowercase dashed UUID. Keys need not be unique: several entries may share one, and Count reports how many.

key := usearch.KeyFromUint64(42)
fmt.Println(key)                 // 00000000-0000-0000-0000-00000000002a
value, integral := key.Uint64()  // 42, true

parsed, err := usearch.ParseKey("00000000-0000-0000-0000-00000000002a")

Keys satisfy encoding.TextMarshaler and encoding.TextUnmarshaler, so they round-trip through JSON as those same strings.

API

TypeKeyKey is a 128-bit entry identity, most significant byte first, rendered as a lowercase dashed UUID.8
types.go:150 ↗
type Key [16]byte

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

NilKeyNilKey is the all-zero key.
types.go:153 ↗
var NilKey Key
KeyFromUint64KeyFromUint64 parks an integer identity in the low eight bytes, zeroing the rest.
types.go:156 ↗
func KeyFromUint64(value uint64) Key
ParseKeyParseKey reads the rendering String produces.
types.go:187 ↗
func ParseKey(text string) (Key, error)

Dashes may sit anywhere, or nowhere.

AppendTextAppendText implements encoding.TextAppender.
types.go:204 ↗
func (key Key) AppendText(buffer []byte) ([]byte, error)
MarshalTextMarshalText implements encoding.TextMarshaler, so a key inside a struct round-trips through JSON as the dashed UUID String prints.
types.go:201 ↗
func (key Key) MarshalText() ([]byte, error)
StringString renders the key as a lowercase dashed UUID.
types.go:172 ↗
func (key Key) String() string
Uint64Uint64 reports the integer identity in the low eight bytes, and false when the high eight carry anything.
types.go:164 ↗
func (key Key) Uint64() (uint64, bool)
UnmarshalTextUnmarshalText implements encoding.TextUnmarshaler.
types.go:207 ↗
func (key *Key) UnmarshalText(text []byte) error