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 ¶
Edge reaches a cycle without naming itself: it points at a Node, and a Node holds Edges.
func (*Edge) Clone ¶
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 ¶
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.
type Label ¶
Label cannot reach a cycle: nothing it holds leads back to a Label. Its generated methods take no memo.
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 ¶
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 ¶
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.