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

Method Compare

pkg/util/json/json.go:427–456  ·  view source on GitHub ↗
(other JSON)

Source from the content-addressed store, hash-verified

425}
426
427func (j jsonArray) Compare(other JSON) (int, error) {
428 cmp := cmpJSONTypes(j.Type(), other.Type())
429 if cmp != 0 {
430 return cmp, nil
431 }
432 lenJ := j.Len()
433 lenO := other.Len()
434 if lenJ < lenO {
435 return -1, nil
436 }
437 if lenJ > lenO {
438 return 1, nil
439 }
440 // TODO(justin): we should optimize this, we don't have to decode the whole thing.
441 var err error
442 if other, err = decodeIfNeeded(other); err != nil {
443 return 0, err
444 }
445 o := other.(jsonArray)
446 for i := 0; i < lenJ; i++ {
447 cmp, err := j[i].Compare(o[i])
448 if err != nil {
449 return 0, err
450 }
451 if cmp != 0 {
452 return cmp, nil
453 }
454 }
455 return 0, nil
456}
457
458func (j jsonObject) Compare(other JSON) (int, error) {
459 cmp := cmpJSONTypes(j.Type(), other.Type())

Callers

nothing calls this directly

Calls 7

TypeMethod · 0.95
LenMethod · 0.95
cmpJSONTypesFunction · 0.85
decodeIfNeededFunction · 0.85
TypeMethod · 0.65
LenMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected