MCPcopy
hub / github.com/dgraph-io/dgraph / CompareVals

Function CompareVals

types/compare.go:13–36  ·  view source on GitHub ↗

CompareVals compares two values using the given comparison type. Should be used only in filtering arg1 by comparing with arg2. arg2 is reference Val to which arg1 is compared.

(op string, arg1, arg2 Val)

Source from the content-addressed store, hash-verified

11// Should be used only in filtering arg1 by comparing with arg2.
12// arg2 is reference Val to which arg1 is compared.
13func CompareVals(op string, arg1, arg2 Val) bool {
14 negateRes := func(b bool, e error) (bool, error) { // reverses result
15 return !b, e
16 }
17 noError := func(b bool, e error) bool {
18 return b && e == nil
19 }
20 switch op {
21 case "ge":
22 return noError(negateRes(Less(arg1, arg2)))
23 case "gt":
24 return noError(Less(arg2, arg1))
25 case "le":
26 return noError(negateRes(Less(arg2, arg1)))
27 case "lt":
28 return noError(Less(arg1, arg2))
29 case "eq":
30 return noError(Equal(arg1, arg2))
31 default:
32 // should have been checked at query level.
33 x.Fatalf("Unknown ineqType %v", op)
34 }
35 return false
36}
37
38// CompareBetween compares if the dst value lie between
39// two values val1 and val2(both inclusive).

Callers 7

ineqMatchFunction · 0.92
handleValuePostingsMethod · 0.92
handleCompareFunctionMethod · 0.92
applyFacetsTreeFunction · 0.92
applyIneqFuncMethod · 0.92
ProcessGraphFunction · 0.92
CompareBetweenFunction · 0.85

Calls 3

FatalfFunction · 0.92
LessFunction · 0.85
EqualFunction · 0.85

Tested by

no test coverage detected