aspectcodec

package
v0.0.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package aspectcodec implements the v2 aspect-segment codec (ADR-0182 SD1), shared by the three aspect vocabularies.

A segment is the ascending list of a set's aspect indices, one alphabet char per index at alphabet[i+1]. The empty set is the empty string; the legacy v1 empty marker "0" is accepted on decode but never produced. '0' (alphabet position 0) never occurs in a v2 segment; 'z' (position 61) is an escape prefix, each occurrence adding +60 to the digit it precedes, chainable. Single chars therefore cover indices 0..59. Canonical form is strictly ascending indices; decoders reject anything else, per element.

Index

Constants

View Source
const Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Alphabet is the v2 digit alphabet, ASCII-sorted so alphabet order equals byte order; position 0 is the reserved '0', position 61 the escape. Exported for consumers that mirror the codec outside Go (SQL UDFs).

Variables

View Source
var ErrEmptySet = eh.Errorf("encoding contains empty set")
View Source
var ErrInvalidEncoding = eh.Errorf("encoding is wrong")
View Source
var PackageProps = packageprops.Props{
	WASMWASI:         packageprops.WASMCompiles,
	WASMJS:           packageprops.WASMCompiles,
	WASMFreestanding: packageprops.WASMCompiles,
}

PackageProps records this package's curated properties (ADR-0080). Seeded by `boxer code analysis golang wasmsurvey props generate`; curate by hand. The same group's `props verify` reconciles it.

Functions

func Contains

func Contains[E IndexI](seg string, target E) (has bool)

Contains reports whether the segment's set contains target. It returns false on structurally invalid input.

func Count

func Count(seg string) (n int, err error)

Count returns the number of aspects in the segment's set.

func Decode

func Decode[E IndexI](seg string, maxExcl E) (known []E, unknownCount int, err error)

Decode splits a structurally valid segment into the indices known to a vocabulary of size maxExcl and a count of unknown (too-new) indices. Unknown elements are individually skippable; they never poison the known part.

func Encode

func Encode[E IndexI](indices []E) (seg string)

Encode returns the canonical v2 segment for the given aspects. Input may be unsorted and may contain duplicates; the result is their set. Every value of an ~uint8 index type is encodable, so Encode is total.

func FirstExclusivityViolation

func FirstExclusivityViolation[E IndexI](families []Family[E], contains func(E) bool) (name string)

FirstExclusivityViolation returns the name of the first exclusive family with more than one member present (per contains), or "" when none is violated.

func IsEmpty

func IsEmpty(seg string) (empty bool)

IsEmpty reports whether the segment denotes the empty set ("" or the legacy v1 marker "0").

func KeepFirstPerExclusiveFamily

func KeepFirstPerExclusiveFamily[E IndexI](families []Family[E], aspects []E) (out []E)

KeepFirstPerExclusiveFamily drops all but the first-encountered member of each exclusive family, preserving input order; aspects outside any exclusive family pass through.

func MaxIndex

func MaxIndex(seg string) (max int, err error)

MaxIndex returns the highest index in the segment's set; ErrEmptySet on an empty set.

func Union

func Union(a string, b string) (seg string, err error)

Union merges two segments into one canonical segment. Indices unknown to the running binary are preserved, never dropped.

func Validate

func Validate(seg string) (err error)

Validate checks structural validity and canonicality.

Types

type Family

type Family[E IndexI] struct {
	Name      string
	Members   []E
	Exclusive bool
}

Family groups related aspects for documentation and validation (ADR-0182 SD3). An exclusive family admits at most one member per set.

type IndexI

type IndexI interface {
	~uint8
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL