YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/util/compare_util.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_UTIL_COMPARE_UTIL_H
15
#define YB_UTIL_COMPARE_UTIL_H
16
17
#include <vector>
18
19
#include <boost/preprocessor/config/config.hpp>
20
21
namespace yb {
22
namespace util {
23
24
template<typename T>
25
7.35G
int CompareUsingLessThan(const T& a, const T& b) {
26
7.35G
  if (a < b) return -1;
27
5.13G
  if (b < a) return 1;
28
4.07G
  return 0;
29
4.07G
}
_ZN2yb4util20CompareUsingLessThanIjEEiRKT_S4_
Line
Count
Source
25
252M
int CompareUsingLessThan(const T& a, const T& b) {
26
252M
  if (a < b) return -1;
27
250M
  if (b < a) return 1;
28
250M
  return 0;
29
250M
}
_ZN2yb4util20CompareUsingLessThanINS_4UuidEEEiRKT_S5_
Line
Count
Source
25
1.30k
int CompareUsingLessThan(const T& a, const T& b) {
26
1.30k
  if (a < b) return -1;
27
768
  if (b < a) return 1;
28
234
  return 0;
29
234
}
_ZN2yb4util20CompareUsingLessThanIbEEiRKT_S4_
Line
Count
Source
25
30
int CompareUsingLessThan(const T& a, const T& b) {
26
30
  if (a < b) return -1;
27
30
  if (b < a) return 1;
28
30
  return 0;
29
30
}
Unexecuted instantiation: _ZN2yb4util20CompareUsingLessThanItEEiRKT_S4_
_ZN2yb4util20CompareUsingLessThanINS_5docdb9ValueTypeEEEiRKT_S6_
Line
Count
Source
25
3.66G
int CompareUsingLessThan(const T& a, const T& b) {
26
3.66G
  if (a < b) return -1;
27
3.51G
  if (b < a) return 1;
28
3.43G
  return 0;
29
3.43G
}
_ZN2yb4util20CompareUsingLessThanIxEEiRKT_S4_
Line
Count
Source
25
36.6M
int CompareUsingLessThan(const T& a, const T& b) {
26
36.6M
  if (a < b) return -1;
27
12.3M
  if (b < a) return 1;
28
3.71k
  return 0;
29
3.71k
}
_ZN2yb4util20CompareUsingLessThanIiEEiRKT_S4_
Line
Count
Source
25
35.5M
int CompareUsingLessThan(const T& a, const T& b) {
26
35.5M
  if (a < b) return -1;
27
25.5M
  if (b < a) return 1;
28
489k
  return 0;
29
489k
}
Unexecuted instantiation: _ZN2yb4util20CompareUsingLessThanIyEEiRKT_S4_
_ZN2yb4util20CompareUsingLessThanIdEEiRKT_S4_
Line
Count
Source
25
933
int CompareUsingLessThan(const T& a, const T& b) {
26
933
  if (a < b) return -1;
27
421
  if (b < a) return 1;
28
102
  return 0;
29
102
}
_ZN2yb4util20CompareUsingLessThanIfEEiRKT_S4_
Line
Count
Source
25
393
int CompareUsingLessThan(const T& a, const T& b) {
26
393
  if (a < b) return -1;
27
243
  if (b < a) return 1;
28
96
  return 0;
29
96
}
_ZN2yb4util20CompareUsingLessThanINS_9TimestampEEEiRKT_S5_
Line
Count
Source
25
394
int CompareUsingLessThan(const T& a, const T& b) {
26
394
  if (a < b) return -1;
27
246
  if (b < a) return 1;
28
97
  return 0;
29
97
}
_ZN2yb4util20CompareUsingLessThanINS_11InetAddressEEEiRKT_S5_
Line
Count
Source
25
216
int CompareUsingLessThan(const T& a, const T& b) {
26
216
  if (a < b) return -1;
27
162
  if (b < a) return 1;
28
108
  return 0;
29
108
}
_ZN2yb4util20CompareUsingLessThanImEEiRKT_S4_
Line
Count
Source
25
52
int CompareUsingLessThan(const T& a, const T& b) {
26
52
  if (a < b) return -1;
27
42
  if (b < a) return 1;
28
20
  return 0;
29
20
}
_ZN2yb4util20CompareUsingLessThanINS_8ColumnIdEEEiRKT_S5_
Line
Count
Source
25
3.36G
int CompareUsingLessThan(const T& a, const T& b) {
26
3.36G
  if (a < b) return -1;
27
1.32G
  if (b < a) return 1;
28
384M
  return 0;
29
384M
}
Unexecuted instantiation: _ZN2yb4util20CompareUsingLessThanIhEEiRKT_S4_
30
31
// If the vectors are not equal size, we assume the smaller vector is padded with the last element
32
// An empty vector will always compare less than a bigger vector.
33
template<typename T>
34
60
int CompareVectors(const std::vector<T>& a, const std::vector<T>& b) {
35
60
  auto a_iter = a.begin();
36
60
  auto b_iter = b.begin();
37
64
  while (a_iter != a.end() && b_iter != b.end()) {
38
34
    int result = a_iter->CompareTo(*b_iter);
39
34
    if (result != 0) {
40
30
      return result;
41
30
    }
42
4
    ++a_iter;
43
4
    ++b_iter;
44
4
  }
45
30
  if (a_iter == a.end()) {
46
30
    return b_iter == b.end() ? 0 : -1;
47
30
  }
48
0
  return 1;
49
0
}
50
51
// http://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
52
template <typename T>
53
20.0k
inline int sgn(T val) {
54
20.0k
  return (T(0) < val) - (val < T(0));
55
20.0k
}
56
57
#if BOOST_PP_VARIADICS
58
59
#define YB_FIELD_EQUALS(r, data, elem) \
60
23.7M
    && lhs.BOOST_PP_CAT(elem, BOOST_PP_APPLY(data)) == rhs.BOOST_PP_CAT(elem, BOOST_PP_APPLY(data))
61
#define YB_FIELDS_EQUALS(data, ...) \
62
35.3M
    BOOST_PP_SEQ_FOR_EACH(YB_FIELD_EQUALS, data(), BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
63
64
#define YB_STRUCT_EQUALS(...) \
65
11.5M
    true YB_FIELDS_EQUALS(BOOST_PP_NIL, __VA_ARGS__)
66
67
#define YB_CLASS_EQUALS(...) \
68
    true YB_FIELDS_TO_STRING((BOOST_PP_IDENTITY(_)), __VA_ARGS__)
69
70
#else
71
#error "Compiler not supported -- BOOST_PP_VARIADICS is not set. See https://bit.ly/2ZF7rTu."
72
#endif
73
74
}  // namespace util
75
}  // namespace yb
76
77
#endif  // YB_UTIL_COMPARE_UTIL_H