v.io: v.io/x/ref/internal/reflectutil Index | Files

package reflectutil

import "v.io/x/ref/internal/reflectutil"

Package reflectutil provides reflection-based utilities.

Index

Package Files

deepequal.go doc.go sort.go

func AreComparable Uses

func AreComparable(a, b interface{}) bool

AreComparable is a helper to call AreComparableTypes.

func AreComparableTypes Uses

func AreComparableTypes(a, b reflect.Type) bool

AreComparableTypes returns true iff a and b are comparable types: bools, strings and numbers, and composites using arrays, slices, structs or pointers.

func Compare Uses

func Compare(a, b interface{}) int

Compare is a helper to call CompareValues.

func CompareValues Uses

func CompareValues(a, b reflect.Value) int

CompareValues returns an integer comparing two values. If a and b are comparable, the result is 0 if a == b, -1 if a < b and +1 if a > b. If a and b are incomparable an arbitrary value is returned. Arrays, slices and structs use lexicographic ordering, and complex numbers compare real before imaginary.

func DeepEqual Uses

func DeepEqual(a, b interface{}, options *DeepEqualOpts) bool

Equal is similar to reflect.DeepEqual, except that it also considers the sharing structure for pointers. When reflect.DeepEqual encounters pointers it just compares the dereferenced values; we also keep track of the pointers themselves and require that if a pointer appears multiple places in a, it appears in the same places in b.

func Less Uses

func Less(a, b interface{}) bool

Less is a helper to call LessValues.

func LessValues Uses

func LessValues(a, b reflect.Value) bool

LessValues returns true iff a and b are comparable and a < b. If a and b are incomparable an arbitrary value is returned. Cyclic values are not handled; if a and b are cyclic and equal, this will infinite loop. Arrays, slices and structs use lexicographic ordering, and complex numbers compare real before imaginary.

func TrySortValues Uses

func TrySortValues(v []reflect.Value) []reflect.Value

TrySortValues sorts a slice of reflect.Value if the value kind is supported. Supported kinds are bools, strings and numbers, and composites using arrays, slices, structs or pointers. Arrays, slices and structs use lexicographic ordering, and complex numbers compare real before imaginary. If the values in the slice aren't comparable or supported, the resulting ordering is arbitrary.

type DeepEqualOpts Uses

type DeepEqualOpts struct {
    SliceEqNilEmpty bool
}

DeepEqualOpts represents the options configuration for DeepEqual.

Package reflectutil imports 3 packages (graph). Updated 2020-09-08. Refresh now. Tools for package owners.