compare

package standard library
go1.19beta1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package compare contains code for generating comparison routines for structs, strings and interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqCanPanic

func EqCanPanic(t *types.Type) bool

EqCanPanic reports whether == on type t could panic (has an interface somewhere). t must be comparable.

func EqInterface

func EqInterface(s, t ir.Node) (eqtab *ir.BinaryExpr, eqdata *ir.CallExpr)

EqInterface returns the nodes

s.tab == t.tab (or s.typ == t.typ, as appropriate)

and

ifaceeq(s.tab, s.data, t.data) (or efaceeq(s.typ, s.data, t.data), as appropriate)

which can be used to construct interface equality comparison. eqtab must be evaluated before eqdata, and shortcircuiting is required.

func EqString

func EqString(s, t ir.Node) (eqlen *ir.BinaryExpr, eqmem *ir.CallExpr)

EqString returns the nodes

len(s) == len(t)

and

memequal(s.ptr, t.ptr, len(s))

which can be used to construct string equality comparison. eqlen must be evaluated before eqmem, and shortcircuiting is required.

func EqStruct

func EqStruct(t *types.Type, np, nq ir.Node) []ir.Node

EqStruct compares two structs np and nq for equality. It works by building a list of boolean conditions to satisfy. Conditions must be evaluated in the returned order and properly short circuited by the caller.

func IsRegularMemory

func IsRegularMemory(t *types.Type) bool

IsRegularMemory reports whether t can be compared/hashed as regular memory.

func Memrun

func Memrun(t *types.Type, start int) (size int64, next int)

Memrun finds runs of struct fields for which memory-only algs are appropriate. t is the parent struct type, and start is the field index at which to start the run. size is the length in bytes of the memory included in the run. next is the index just after the end of the memory run.

Types

This section is empty.

Jump to

Keyboard shortcuts

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