Documentation
¶
Index ¶
Constants ¶
const ( ADD = "+ " DEL = "- " )
Variables ¶
This section is empty.
Functions ¶
func Diff ¶
func Diff(v1, v2 types.Value, dChan chan<- Difference, stopChan chan struct{}, leftRight bool)
Diff traverses two graphs simultaneously looking for differences. It returns two channels: a DiffReceiveChan that the caller can use to iterate over the diffs in the graph and a StopSendChanel that a caller can use to signal the Diff function to stop processing. Diff returns the Differences in depth-first first order. A 'diff' is defined as one of the following conditions:
- a Value is Added or Removed from a node in the graph
- the type of a Value has changed in the graph
- a primitive (i.e. Bool, Number, String, Ref or Blob) Value has changed
A Difference is not returned when a non-primitive value has been modified. For example, a struct field has been changed from one Value of type Employee to another. Those modifications are accounted for by the Differences described above at a lower point in the graph.
If leftRight is true then the left-right diff is used for ordered sequences - see Diff vs DiffLeftRight in Set and Map.
Note: the function sends messages on diffChan and checks whether stopChan has been closed to know if it needs to terminate diffing early. To function properly it needs to be executed concurrently with code that reads values from diffChan. The following is a typical invocation of Diff():
dChan := make(chan Difference) sChan := make(chan struct{}) go func() { d.Diff(s3, s4, dChan, sChan, leftRight) close(dChan) }() for dif := range dChan { <some code> }
Types ¶
type Difference ¶
type Difference struct { // Path to the Value that has changed Path types.Path // ChangeType indicates the type of diff: modified, added, deleted ChangeType types.DiffChangeType // OldValue is Value before the change, can be nil if Value was added OldValue types.Value // NewValue is Value after the change, can be nil if Value was removed NewValue types.Value }
Difference represents a "diff" between two Noms graphs.