safediff

package
v0.0.0-...-1b709f2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package safediff computes the difference between two lists.

It is guaranteed to run in O(n), but may not produce an optimal diff. Most diffing algorithms produce optimal diffs but run in O(n²). It is safe to pass in untrusted input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lines

func Lines(x, y string, maxSize int) (out string, truncated bool)

Lines constructs a humanly readable line-by-line diff from x to y. The output (if multiple lines) is guaranteed to be no larger than maxSize, by truncating the output if necessary. A negative maxSize enforces no limit.

Example diff:

… 440 identical lines
  	"ssh": [
… 35 identical lines
  		{
- 			"src":    ["[email protected]"],
- 			"dst":    ["tag:maisem-test"],
- 			"users":  ["maisem", "root"],
- 			"action": "check",
- 			// "recorder": ["100.12.34.56:80"],
+ 			"src":      ["[email protected]"],
+ 			"dst":      ["tag:maisem-test"],
+ 			"users":    ["maisem", "root"],
+ 			"action":   "check",
+ 			"recorder": ["node:recorder-2"],
  		},
… 77 identical lines
  	],
… 345 identical lines

Meaning of each line prefix:

  • '…' precedes a summary statement
  • ' ' precedes an identical line printed for context
  • '-' precedes a line removed from x
  • '+' precedes a line inserted from y

The diffing algorithm runs in O(n) and is safe to use with untrusted inputs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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