MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Compare

Method Compare

pkg/util/json/encoded.go:592–616  ·  view source on GitHub ↗
(other JSON)

Source from the content-addressed store, hash-verified

590}
591
592func (j *jsonEncoded) Compare(other JSON) (_ int, err error) {
593 if other == nil {
594 return -1, nil
595 }
596 // We must first check for the special case of empty arrays, which are the
597 // minimum JSON value.
598 switch {
599 case isEmptyArray(j) && isEmptyArray(other):
600 return 0, nil
601 case isEmptyArray(j):
602 return -1, nil
603 case isEmptyArray(other):
604 return 1, nil
605 }
606 if cmp := cmpJSONTypes(j.Type(), other.Type()); cmp != 0 {
607 return cmp, nil
608 }
609 // TODO(justin): this can be optimized in some cases. We don't necessarily
610 // need to decode all of an array or every object key.
611 dec, err := j.shallowDecode()
612 if err != nil {
613 return 0, err
614 }
615 return dec.Compare(other)
616}
617
618func (j *jsonEncoded) Exists(key string) (bool, error) {
619 if dec := j.alreadyDecoded(); dec != nil {

Callers

nothing calls this directly

Calls 6

TypeMethod · 0.95
shallowDecodeMethod · 0.95
isEmptyArrayFunction · 0.85
cmpJSONTypesFunction · 0.85
TypeMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected