graph

package
v6.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package graph holds models whose types can reach themselves: directly, and through every reference kind the generator emits code for — pointers, slices of pointers, slices of values, maps of pointers and maps of values.

Types like these are why generated Clone carries a deep.CloneMemo, generated Equal a deep.VisitSet and generated Diff a deep.DiffMemo. The generator decides that per type by looking for cycles and multiply-reachable references in the package's type graph, so this package also keeps a type where neither is possible: it must still generate the plain, memo-free code.

Code generated by deep-gen. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	Weight int   `json:"weight"`
	To     *Node `json:"to"`
}

Edge reaches a cycle without naming itself: it points at a Node, and a Node holds Edges.

func (*Edge) Clone

func (t *Edge) Clone() *Edge

Clone returns a deep copy of t.

Edge values can hold two references to the same value — through a cycle, or through two routes to one pointer — so the copy keeps track of what it has already copied: a value reached more than once is copied once, every reference to it in the result points at that one copy, and a reference cycle is rebuilt rather than followed forever.

func (*Edge) Diff

func (t *Edge) Diff(other *Edge) deep.Patch[Edge]

Diff compares t with other and returns a Patch.

Edge values can hold two references to the same value, so a pair of values is diffed once, at the first path that reaches it. Every later route to a changed pair becomes one alias operation — "make this path hold the object that path holds" — appended after the rest. That keeps the patch linear where listing every route could be exponential, and applying it rebuilds the sharing whatever the target looked like before.

func (*Edge) Equal

func (t *Edge) Equal(other *Edge) bool

Equal returns true if t and other are deeply equal.

Edge values can hold two references to the same value, so a pair of values is compared once however many routes lead to it, and a cycle is followed only until it repeats.

func (*Edge) Patch

func (t *Edge) Patch(p deep.Patch[Edge], logger *slog.Logger) error

Patch applies p to t using the generated fast path.

type Label

type Label struct {
	Text string `json:"text"`
	Rank int    `json:"rank"`
}

Label cannot reach a cycle: nothing it holds leads back to a Label. Its generated methods take no memo.

func (*Label) Clone

func (t *Label) Clone() *Label

Clone returns a deep copy of t.

func (*Label) Diff

func (t *Label) Diff(other *Label) deep.Patch[Label]

Diff compares t with other and returns a Patch.

func (*Label) Equal

func (t *Label) Equal(other *Label) bool

Equal returns true if t and other are deeply equal.

func (*Label) Patch

func (t *Label) Patch(p deep.Patch[Label], logger *slog.Logger) error

Patch applies p to t using the generated fast path.

type Node

type Node struct {
	Name     string            `json:"name"`
	Label    Label             `json:"label"`    // value struct, not itself recursive
	Next     *Node             `json:"next"`     // directly
	Peers    []*Node           `json:"peers"`    // through a slice of pointers
	Children map[string]*Node  `json:"children"` // through a map of pointers
	Edges    []Edge            `json:"edges"`    // through a slice of values
	Links    map[string]Edge   `json:"links"`    // through a map of values
	Tags     map[string]string `json:"tags"`     // plain reference types, no cycle
	Scores   []int             `json:"scores"`
}

Node reaches itself five different ways, so every reference-handling branch of the generated code has to thread the memo.

func (*Node) Clone

func (t *Node) Clone() *Node

Clone returns a deep copy of t.

Node values can hold two references to the same value — through a cycle, or through two routes to one pointer — so the copy keeps track of what it has already copied: a value reached more than once is copied once, every reference to it in the result points at that one copy, and a reference cycle is rebuilt rather than followed forever.

func (*Node) Diff

func (t *Node) Diff(other *Node) deep.Patch[Node]

Diff compares t with other and returns a Patch.

Node values can hold two references to the same value, so a pair of values is diffed once, at the first path that reaches it. Every later route to a changed pair becomes one alias operation — "make this path hold the object that path holds" — appended after the rest. That keeps the patch linear where listing every route could be exponential, and applying it rebuilds the sharing whatever the target looked like before.

func (*Node) Equal

func (t *Node) Equal(other *Node) bool

Equal returns true if t and other are deeply equal.

Node values can hold two references to the same value, so a pair of values is compared once however many routes lead to it, and a cycle is followed only until it repeats.

func (*Node) Patch

func (t *Node) Patch(p deep.Patch[Node], logger *slog.Logger) error

Patch applies p to t using the generated fast path.

Jump to

Keyboard shortcuts

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