equal

package
v0.0.0-...-6fe4f4e Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 3 Imported by: 0

README

Exercise 13.1 (P361)

Define a deep comparison function that considers numbers (of any type) equal if they differ by less than one part in a billion.

Documentation

Overview

Package equal provides a deep equivalence relation for arbitrary values.

Example (Equal)
fmt.Println(Equal([]int{1, 2, 3}, []int{1, 2, 3}))
fmt.Println(Equal([]string{"foo"}, []string{"bar"}))
fmt.Println(Equal([]string(nil), []string{}))
fmt.Println(Equal(map[string]int(nil), map[string]int{}))
Output:

true
false
true
true
Example (EqualCycle)
// Circular linked lists a -> b -> a and c -> c.
type link struct {
	value string
	tail  *link
}
a, b, c := &link{value: "a"}, &link{value: "b"}, &link{value: "c"}
a.tail, b.tail, c.tail = b, a, c
fmt.Println(Equal(a, a))
fmt.Println(Equal(b, b))
fmt.Println(Equal(c, c))
fmt.Println(Equal(a, b))
fmt.Println(Equal(a, c))
Output:

true
true
true
false
false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(x, y interface{}) bool

Equal reports whether x and y are deeply equal. Map keys are always compared with ==, not deeply. (This matters for keys containing pointers or interfaces.)

Types

This section is empty.

Jump to

Keyboard shortcuts

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