dtree

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanCompileToTree

func CanCompileToTree(arms []core.MatchArm) bool

CanCompileToTree determines if a match can benefit from decision tree compilation For now, simple heuristic: worth it if there are multiple literal/constructor patterns

Types

type DecisionTree

type DecisionTree interface {
	String() string
	// contains filtered or unexported methods
}

DecisionTree represents a compiled pattern matching decision tree This optimizes pattern matching by avoiding redundant tests

type DecisionTreeCompiler

type DecisionTreeCompiler struct {
	// contains filtered or unexported fields
}

DecisionTreeCompiler compiles match arms into a decision tree

func NewDecisionTreeCompiler

func NewDecisionTreeCompiler(arms []core.MatchArm) *DecisionTreeCompiler

NewDecisionTreeCompiler creates a new compiler

func (*DecisionTreeCompiler) Compile

func (c *DecisionTreeCompiler) Compile() DecisionTree

Compile builds a decision tree from match arms

type FailNode

type FailNode struct{}

FailNode represents no match (non-exhaustive)

func (*FailNode) String

func (f *FailNode) String() string

type LeafNode

type LeafNode struct {
	ArmIndex int // Index of the original match arm
	Body     core.CoreExpr
	Guard    core.CoreExpr // Optional guard
}

LeafNode represents a match with a body to execute

func (*LeafNode) String

func (l *LeafNode) String() string

type SwitchNode

type SwitchNode struct {
	Path    []int                        // Path to the value being tested (e.g., [0, 1] = first field of second field)
	Cases   map[interface{}]DecisionTree // Map from constructor/literal to subtree
	Default DecisionTree                 // Fallback for wildcard/variable patterns
}

SwitchNode represents a choice based on a discriminator

func (*SwitchNode) String

func (s *SwitchNode) String() string

Jump to

Keyboard shortcuts

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