package limits

Import Path
	github.com/pancsta/d2/d2layouts/d2talalayout/internal/limits (on go.dev)

Dependency Relation
	imports 6 packages, and imported by 12 packages

Involved Source Files arithmetic.go optimization.go Package limits provides the engine's topology ceilings and reusable work accounting primitives. It deliberately has no dependency on graph, layout, or routing types so every layout domain can consume the same limits without introducing package cycles.
Package-Level Type Names (total 2)
/* sort by: | */
OptimizationWorkGuard accounts one complete hierarchy or placement optimization. The limit is an explicit ceiling; zero permits cancellation checks but no charged work. Add charges amount optimization work units. AddProduct multiplies two work dimensions without allowing arithmetic overflow. AddSort charges the comparison bound for sorting length values. Check observes optimization cancellation immediately. Finish observes cancellation at an optimization boundary. Location returns the operation name used in diagnostics. Step charges one optimization work unit. Used returns the accepted work units. *OptimizationWorkGuard : github.com/pancsta/d2/d2layouts/d2talalayout/internal/graphbounds.WorkStepper *OptimizationWorkGuard : github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.SharedWorkStepper func NewOptimizationWorkGuard(ctx context.Context, location string, limit uint64) (*OptimizationWorkGuard, error) func Shuffle[T](values []T, random *rand.Rand, guard *OptimizationWorkGuard) error
WorkGuard accounts a complete operation's signed work units and polls its context at a fixed stride. The limit is an explicit non-negative ceiling; zero permits cancellation checks but no charged work. Add records multiple work units as one accounting operation. It enforces Step's work limit and polls cancellation when the accepted charge reaches or crosses a Step polling boundary. On a positive-limit overflow, Used reports the first rejected unit even when a crossed boundary observes cancellation. Check observes cancellation immediately. Step and Add use a bounded stride in hot loops, while callers use Check at explicit cancellation boundaries. Finish observes cancellation regardless of the current work count. SetLimit changes the ceiling without resetting already consumed work. Step charges one work unit. Used returns the number of charged or first-rejected work units. *WorkGuard : github.com/pancsta/d2/d2layouts/d2talalayout/internal/graphbounds.WorkStepper *WorkGuard : github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.SharedWorkStepper func NewWorkGuard(ctx context.Context, location string, limit int64) (*WorkGuard, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.EnsureTransactionWorkGuard(ctx context.Context, location string) (context.Context, *WorkGuard, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.ExistingTransactionWorkGuard(ctx context.Context, location string) (*WorkGuard, bool, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.BuildNodeToTreeForDeserialization(trees map[*layoutgraph.Node][]*layoutgraph.Tree, guard *WorkGuard) (map[*layoutgraph.Node]*layoutgraph.Tree, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.ContainerOrderForSerialization(graph *layoutgraph.Graph, guard *WorkGuard) ([]*layoutgraph.Node, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.ContextWithTransactionWorkGuard(ctx context.Context, guard *WorkGuard) context.Context func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*Graph).AllDescendantNodesWithWorkGuard(node *layoutgraph.Node, includeClusterNodes bool, guard *WorkGuard) ([]*layoutgraph.Node, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*Graph).ContainerRDFSOrder(root *layoutgraph.Node, guard *WorkGuard) ([]*layoutgraph.Node, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*Graph).IsBadStateWithWorkGuard(node *layoutgraph.Node, graphState *layoutgraph.GraphState, ignoreContainerEscape bool, guard *WorkGuard) (bool, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*Graph).NewRequestTransactionWithWorkGuard(ctx context.Context, guard *WorkGuard, options layoutgraph.TransactionOptions) (*layoutgraph.Transaction, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*Graph).WouldOverlapWithWorkGuard(node *layoutgraph.Node, point *geo.Point, exceptions []*layoutgraph.Node, pairwiseExceptions map[*layoutgraph.Node]map[*layoutgraph.Node]struct{}, guard *WorkGuard) (bool, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*GraphState).OwnedNodes(g *layoutgraph.Graph, guard *WorkGuard) (map[*layoutgraph.Node]struct{}, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*GraphState).UpdateWithWorkGuard(g *layoutgraph.Graph, guard *WorkGuard) error func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*Node).AllReachableNodesContext(includeContainers, includeNears, traverseTrees bool, ignore map[*layoutgraph.Node]struct{}, guard *WorkGuard) ([]*layoutgraph.Node, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.(*Node).ReachableNodesContext(shouldVisit func(*layoutgraph.Node) bool, includeContainers, includeNears, traverseTrees bool, ignore map[*layoutgraph.Node]struct{}, guard *WorkGuard) ([]*layoutgraph.Node, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.Nodes.BoundingBoxWithWorkGuard(guard *WorkGuard) (*geo.Point, *geo.Point, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.Nodes.CenterWithWorkGuard(guard *WorkGuard) (*geo.Point, error) func github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph.Nodes.DistanceClustersWithWorkGuard(threshold float64, guard *WorkGuard) ([][]*layoutgraph.Node, error)
Package-Level Functions (total 5)
CheckedAddUint64 returns a+b and whether the sum fits in uint64.
CheckedMulUint64 returns a*b and whether the product fits in uint64.
NewOptimizationWorkGuard constructs a guard and observes cancellation before any optimization work begins.
NewWorkGuard constructs a work guard and observes cancellation before any operation work begins.
Type Parameters: T: any Shuffle is math/rand.Shuffle's Fisher-Yates implementation with a guard check before every random draw. Its reduction algorithm and draw order are intentionally identical so seeded layout output remains stable.
Package-Level Variables (only one)
ErrOptimizationResourceLimit reports exhausted or overflowing optimization work accounting.
Package-Level Constants (total 12)
MaxBinPackWorkUnits spans the complete recursive bin-packing operation, including speculative transactions and route scans.
MaxEngineEdges is the largest edge count the engine processes in one attempt.
MaxEngineNodes is the largest node count the engine processes in one attempt.
MaxEngineRoutePoints bounds aggregate route storage throughout the engine.
MaxEngineTreeDepth bounds recursive topology throughout the engine.
MaxEngineWorkUnits is the default aggregate work budget for a graph.
MaxGraphSize is the maximum supported width or height at a pipeline stage boundary.
MaxLabelPlacementWorkUnits bounds the quadratic overlap and candidate search performed while positioning labels and icons.
MaxOptimizationWorkUnits bounds one hierarchy or placement optimization.
MaxPlaceTreesWorkUnits is calibrated for the superlinear candidate and obstacle work performed by tree placement.
MaxTransactionOverlapReferences bounds retained existing-overlap references. Exceptions are retained in both directions because hot placement checks key by the moved node.
MaxTransactionWorkUnits allows a complete layout transaction to compare many nearby placements without resetting the ordinary engine budget for every candidate.