router

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

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

Graph holds the adjacency list for Dijkstra shortest-path routing.

func Build

func Build() *Graph

Build constructs the format graph from all registered backends.

Edges are filtered by backend.IsAvailable so that capabilities whose underlying binary is missing from $PATH never appear in the graph. This makes Dijkstra prefer cheap routes that can actually run instead of failing at exec time on a backend with the same nominal Cost.

func BuildFromBackends added in v0.1.1

func BuildFromBackends(backends []backend.Backend) *Graph

BuildFromBackends constructs the format graph from the supplied backends. Exposed for testing and for callers that need to scope a graph to a subset of backends (e.g. plugin sandboxing).

func (*Graph) Find

func (g *Graph) Find(src, dst string) (*Route, error)

Find returns the lowest-cost route from src to dst using the default speed policy (max 4 hops, lossy allowed). Preserved for backward compatibility.

func (*Graph) FindWithPolicy added in v0.1.1

func (g *Graph) FindWithPolicy(src, dst string, policy RoutePolicy) (*Route, error)

FindWithPolicy returns the best route from src to dst according to the given RoutePolicy.

In ModeQuality the router maximises the route bottleneck quality (min(step.Quality)), then minimises total cost, then fewer hops. In ModeSpeed the router minimises total cost, then fewer hops.

MaxHops pruning is safe: dist is keyed by (format, hops), so a cheap but hop-exhausted path to an intermediate cannot suppress a costlier shorter path that can still reach the target.

func (*Graph) Nodes

func (g *Graph) Nodes() []string

Nodes returns all format IDs that appear in the graph.

type Route

type Route struct {
	Steps []Step
}

Route is an ordered sequence of steps from source to target format.

func (*Route) Lossy added in v0.1.1

func (r *Route) Lossy() bool

Lossy returns true if any step in the route is lossy.

func (*Route) Quality added in v0.1.1

func (r *Route) Quality() int

Quality returns the minimum quality across all steps (conservative aggregate). Returns 0 for a zero-step route.

func (*Route) TotalCost

func (r *Route) TotalCost() int

TotalCost returns the sum of edge costs across all steps.

type RouteMode added in v0.1.1

type RouteMode int

RouteMode controls the routing optimisation objective.

const (
	// ModeSpeed routes by lowest cost (default, backward-compatible).
	ModeSpeed RouteMode = iota
	// ModeQuality routes by highest quality, using cost as a tiebreaker.
	ModeQuality
)

type RoutePolicy added in v0.1.1

type RoutePolicy struct {
	// Mode selects the optimisation objective: speed (lowest cost) or quality.
	Mode RouteMode
	// AvoidLossy skips edges marked as lossy when true.
	AvoidLossy bool
	// MaxHops constrains the maximum number of steps. Defaults to 4 when <= 0.
	MaxHops int
}

RoutePolicy controls how the router selects and filters paths.

func DefaultPolicy added in v0.1.1

func DefaultPolicy() RoutePolicy

DefaultPolicy returns the backward-compatible default: speed mode, lossy allowed, max 4 hops.

type Step

type Step struct {
	From    string
	To      string
	Backend backend.Backend
	Cost    int
	Quality int
	Lossy   bool
}

Step is a single conversion hop in a route.

Jump to

Keyboard shortcuts

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