Debian Codegraph @

internal/ptrutil/int64.go

raw symbols SCIP
1 // Copyright (C) MongoDB, Inc. 2023-present.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may
4 // not use this file except in compliance with the License. You may obtain
5 // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7 package ptrutilscip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/ptrutil`/
8
9 // CompareInt64 is a piecewise function with the following return conditions:
10 //
11 // (1) 2, ptr1 != nil AND ptr2 == nil
12 // (2) 1, *ptr1 > *ptr2
13 // (3) 0, ptr1 == ptr2 or *ptr1 == *ptr2
14 // (4) -1, *ptr1 < *ptr2
15 // (5) -2, ptr1 == nil AND ptr2 != nil
16 func CompareInt64scip-go gomod go.mongodb.org/mongo-driver . `go.mongodb.org/mongo-driver/internal/ptrutil`/CompareInt64().(ptr1, ptr2 *int64) int {
17 if ptr1 == ptr2 {
18 // This will catch the double nil or same-pointer cases.
19 return 0
20 }
21
22 if ptr1 == nil && ptr2 != nil {
23 return -2
24 }
25
26 if ptr1 != nil && ptr2 == nil {
27 return 2
28 }
29
30 if *ptr1 > *ptr2 {
31 return 1
32 }
33
34 if *ptr1 < *ptr2 {
35 return -1
36 }
37
38 return 0
39 }