shape

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package shape computes and enumerates the reachable query shapes of a template: guard bitmask × one ordinal per @choose block. See docs/design/03-structural-rules.md §9.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(q *template.QueryTemplate) *big.Int

Count returns the exact number of reachable shapes (PostgreSQL view: @in contributes no dimension).

func CountExpand

func CountExpand(q *template.QueryTemplate, expandIn bool) *big.Int

CountExpand counts shapes; with expandIn each @in contributes the two representative arities (non-empty, empty). The true runtime arity space is unbounded — verification quotients it to these two classes because IN-list growth is parse-invariant.

func EncodeKey

func EncodeKey(guards uint64, choices []uint8, orders [][]uint8) string

EncodeKey is the shared canonical encoding (also used by the runtime mirror): "g=<hex>[;c=<ords>][;o=<seq>|<seq>…][;n=<arities>]" where a sequence is "*" (maximal), "-" (default/omit), or elements like "1a,0d".

Types

type Key

type Key struct {
	Guards  uint64
	Choices []uint8   // one per @choose block, document order
	Orders  [][]uint8 // one per @order-by block: key<<1|desc sequence

	// Ins holds one representative arity per @in construct on
	// expanding dialects: 1 stands for every non-empty list (adding an
	// element to an IN list is parse-invariant), 0 is the distinct
	// empty-list rendering. Empty on PostgreSQL.
	Ins []uint8
}

Key identifies one concrete shape.

func Enumerate

func Enumerate(q *template.QueryTemplate, capN int) (keys []Key, truncated bool)

Enumerate yields every shape key in a deterministic order, stopping after cap keys. truncated reports whether the cap cut enumeration short. cap <= 0 means no cap. @order-by blocks contribute their full selection space (empty, every ordered subset, every direction mix). @in contributes no dimension (the PostgreSQL view); expanding dialects use EnumerateExpand.

func EnumerateExpand

func EnumerateExpand(q *template.QueryTemplate, capN int, expandIn bool) (keys []Key, truncated bool)

EnumerateExpand is Enumerate with an optional @in dimension: with expandIn each @in contributes its two representative arities (1 = any non-empty list, 0 = the empty-list rendering).

func (Key) Arities

func (k Key) Arities() []int32

Arities converts the key's representative arities to the runtime key form.

func (Key) InSelection

func (k Key) InSelection() ast.InSelection

InSelection converts the key's @in arities into the renderer's form.

func (Key) OrderSelection

func (k Key) OrderSelection() ast.OrderSelection

OrderSelection converts the key's order sequences into the renderer's form.

func (Key) Selection

func (k Key) Selection() ast.CaseSelection

Selection converts the key's choices into the renderer's form.

func (Key) String

func (k Key) String() string

String is the canonical, stable encoding used for caches and logs. It must stay byte-identical to runtime.ShapeKey.String.

Jump to

Keyboard shortcuts

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