Documentation ¶
Overview ¶
Package compare implements comparisons between Kythe values.
Index ¶
- Variables
- func EntriesEqual(e1, e2 *spb.Entry) bool
- func ProtoDiff(x, y interface{}, opts ...cmp.Option) string
- func VNamesEqual(v1, v2 *spb.VName) bool
- type By
- type ByEntries
- type Option
- type Order
- func Bytes(s, t []byte) Order
- func Compare(a, b interface{}, opts ...Option) (o Order)
- func Entries(e1, e2 *spb.Entry) Order
- func Ints(a, b int) Order
- func Seq(a, b interface{}, opts ...Option) Order
- func Strings(s, t string) Order
- func ToOrder(c int) Order
- func VNames(v1, v2 *spb.VName) Order
- func ValueEntries(e1, e2 *spb.Entry) Order
- type With
Constants ¶
This section is empty.
Variables ¶
var ( ByVNameSignature = By(func(x interface{}) interface{} { return x.(*spb.VName).GetSignature() }) ByVNameCorpus = By(func(x interface{}) interface{} { return x.(*spb.VName).GetCorpus() }) ByVNameRoot = By(func(x interface{}) interface{} { return x.(*spb.VName).GetRoot() }) ByVNamePath = By(func(x interface{}) interface{} { return x.(*spb.VName).GetPath() }) ByVNameLanguage = By(func(x interface{}) interface{} { return x.(*spb.VName).GetLanguage() }) )
Options for comparing components of *spb.VName protobuf messages.
var ( ByEntrySource = And(By(func(x interface{}) interface{} { return x.(*spb.Entry).GetSource() }), With(func(a, b interface{}) Order { return VNames(a.(*spb.VName), b.(*spb.VName)) })) ByEntryEdgeKind = By(func(x interface{}) interface{} { return x.(*spb.Entry).GetEdgeKind() }) ByEntryFactName = By(func(x interface{}) interface{} { return x.(*spb.Entry).GetFactName() }) ByEntryTarget = And(By(func(x interface{}) interface{} { return x.(*spb.Entry).GetTarget() }), With(func(a, b interface{}) Order { return VNames(a.(*spb.VName), b.(*spb.VName)) })) )
Options for comparing components of *spb.Entry protobuf messages.
Functions ¶
func EntriesEqual ¶
EntriesEqual reports whether e1 and e2 are equivalent, including their fact values (if any).
func ProtoDiff ¶ added in v0.0.30
ProtoDiff returns a human-readable report of the differences between two values, ensuring that any proto.Message values are compared correctly with proto.Equal.
See github.com/google/go-cmp/cmp for more details.
func VNamesEqual ¶
VNamesEqual reports whether v1 and v2 are equal.
Types ¶
type By ¶
type By func(interface{}) interface{}
By is an Option that transforms a value before performing a comparison. It should work on both sides of the comparison equivalently.
type ByEntries ¶
ByEntries is a min-heap of entries, ordered by Entries.
func (*ByEntries) Pop ¶
func (s *ByEntries) Pop() interface{}
Pop implements part of the heap.Interface
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
An Option changes the behavior of the generic comparisons.
type Order ¶
type Order int
An Order represents an ordering relationship between values.
LT, EQ, and GT are the standard values for an Order.
func Compare ¶
Compare returns the Order between two arbitrary values of the same type.
Only the following types are currently supported: {string, int, int32, []byte}.
Options may be provided to change the semantics of the comparison. Other types may be compared if an appropriate By Option transforms the values into a supported type or a With Option is provided for the types given.
Note: this function panics if a and b are different types
func Entries ¶
Entries reports whether e1 is LT, GT, or EQ to e2 in entry order, ignoring fact values (if any).
The ordering for entries is defined by lexicographic comparison of [source, edge kind, fact name, target].
func Seq ¶
Seq sequences comparisons on the same two values over different Options. If len(opts) == 0, Seq merely returns Compare(a, b). For len(opts) > 0, Seq returns Compare(a, b, opts[0]).AndThen(a, b, opts[1])....AndThen(a, b, opts[len(opts)-1]).
func VNames ¶
VNames returns LT if v1 precedes v2, EQ if v1 and v2 are equal, or GT if v1 follows v2, in standard order. The ordering for VNames is defined by lexicographic comparison of [signature, corpus, root, path, language].
func ValueEntries ¶
ValueEntries reports whether e1 is LT, GT, or EQ to e2 in entry order, including fact values (if any).
func (Order) AndThen ¶
AndThen returns o if o != EQ. Otherwise, the Order between a and b is determined and returned. AndThen can be used to chain comparisons.
Examples:
Compare(a, b, By(someField)).AndThen(a, b, By(someOtherField)) Entries(e1, e2).AndThen(e1.FactValue, e2.FactValue)