YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/compare_util.h
Line
Count
Source
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
21.7G
int CompareUsingLessThan(const T& a, const T& b) {
26
21.7G
  if (a < b) 
return -16.57G
;
27
15.1G
  if (b < a) 
return 13.08G
;
28
12.0G
  return 0;
29
15.1G
}
int yb::util::CompareUsingLessThan<unsigned int>(unsigned int const&, unsigned int const&)
Line
Count
Source
25
713M
int CompareUsingLessThan(const T& a, const T& b) {
26
713M
  if (a < b) 
return -15.67M
;
27
707M
  if (b < a) 
return 14.30M
;
28
703M
  return 0;
29
707M
}
int yb::util::CompareUsingLessThan<yb::Uuid>(yb::Uuid const&, yb::Uuid const&)
Line
Count
Source
25
88.5k
int CompareUsingLessThan(const T& a, const T& b) {
26
88.5k
  if (a < b) 
return -1480
;
27
88.0k
  if (b < a) 
return 1481
;
28
87.5k
  return 0;
29
88.0k
}
int yb::util::CompareUsingLessThan<bool>(bool const&, bool const&)
Line
Count
Source
25
87.3k
int CompareUsingLessThan(const T& a, const T& b) {
26
87.3k
  if (a < b) 
return -1648
;
27
86.7k
  if (b < a) 
return 172
;
28
86.6k
  return 0;
29
86.7k
}
int yb::util::CompareUsingLessThan<unsigned short>(unsigned short const&, unsigned short const&)
Line
Count
Source
25
45.0k
int CompareUsingLessThan(const T& a, const T& b) {
26
45.0k
  if (a < b) 
return -119.9k
;
27
25.0k
  if (b < a) 
return 119.9k
;
28
5.06k
  return 0;
29
25.0k
}
int yb::util::CompareUsingLessThan<yb::docdb::ValueType>(yb::docdb::ValueType const&, yb::docdb::ValueType const&)
Line
Count
Source
25
10.7G
int CompareUsingLessThan(const T& a, const T& b) {
26
10.7G
  if (a < b) 
return -1350M
;
27
10.4G
  if (b < a) 
return 1170M
;
28
10.2G
  return 0;
29
10.4G
}
int yb::util::CompareUsingLessThan<long long>(long long const&, long long const&)
Line
Count
Source
25
70.7M
int CompareUsingLessThan(const T& a, const T& b) {
26
70.7M
  if (a < b) 
return -146.9M
;
27
23.7M
  if (b < a) 
return 123.7M
;
28
55.3k
  return 0;
29
23.7M
}
int yb::util::CompareUsingLessThan<int>(int const&, int const&)
Line
Count
Source
25
36.3M
int CompareUsingLessThan(const T& a, const T& b) {
26
36.3M
  if (a < b) 
return -110.0M
;
27
26.2M
  if (b < a) 
return 125.1M
;
28
1.13M
  return 0;
29
26.2M
}
Unexecuted instantiation: int yb::util::CompareUsingLessThan<unsigned long long>(unsigned long long const&, unsigned long long const&)
int yb::util::CompareUsingLessThan<double>(double const&, double const&)
Line
Count
Source
25
1.54k
int CompareUsingLessThan(const T& a, const T& b) {
26
1.54k
  if (a < b) 
return -1892
;
27
648
  if (b < a) 
return 1533
;
28
115
  return 0;
29
648
}
int yb::util::CompareUsingLessThan<float>(float const&, float const&)
Line
Count
Source
25
391
int CompareUsingLessThan(const T& a, const T& b) {
26
391
  if (a < b) 
return -1149
;
27
242
  if (b < a) 
return 1146
;
28
96
  return 0;
29
242
}
int yb::util::CompareUsingLessThan<yb::Timestamp>(yb::Timestamp const&, yb::Timestamp const&)
Line
Count
Source
25
395
int CompareUsingLessThan(const T& a, const T& b) {
26
395
  if (a < b) 
return -1149
;
27
246
  if (b < a) 
return 1149
;
28
97
  return 0;
29
246
}
int yb::util::CompareUsingLessThan<yb::InetAddress>(yb::InetAddress const&, yb::InetAddress const&)
Line
Count
Source
25
193
int CompareUsingLessThan(const T& a, const T& b) {
26
193
  if (a < b) 
return -148
;
27
145
  if (b < a) 
return 149
;
28
96
  return 0;
29
145
}
int yb::util::CompareUsingLessThan<unsigned long>(unsigned long const&, unsigned long const&)
Line
Count
Source
25
52
int CompareUsingLessThan(const T& a, const T& b) {
26
52
  if (a < b) 
return -110
;
27
42
  if (b < a) 
return 122
;
28
20
  return 0;
29
42
}
int yb::util::CompareUsingLessThan<yb::ColumnId>(yb::ColumnId const&, yb::ColumnId const&)
Line
Count
Source
25
10.1G
int CompareUsingLessThan(const T& a, const T& b) {
26
10.1G
  if (a < b) 
return -16.16G
;
27
3.96G
  if (b < a) 
return 12.85G
;
28
1.10G
  return 0;
29
3.96G
}
Unexecuted instantiation: int yb::util::CompareUsingLessThan<unsigned char>(unsigned char const&, unsigned char const&)
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
97.9k
int CompareVectors(const std::vector<T>& a, const std::vector<T>& b) {
35
97.9k
  auto a_iter = a.begin();
36
97.9k
  auto b_iter = b.begin();
37
117k
  while (a_iter != a.end() && 
b_iter != b.end()55.8k
) {
38
51.2k
    int result = a_iter->CompareTo(*b_iter);
39
51.2k
    if (result != 0) {
40
31.7k
      return result;
41
31.7k
    }
42
19.4k
    ++a_iter;
43
19.4k
    ++b_iter;
44
19.4k
  }
45
66.1k
  if (a_iter == a.end()) {
46
61.5k
    return b_iter == b.end() ? 
054.6k
:
-16.89k
;
47
61.5k
  }
48
4.61k
  return 1;
49
66.1k
}
50
51
// http://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
52
template <typename T>
53
inline int sgn(T val) {
54
  return (T(0) < val) - (val < T(0));
55
}
56
57
#if BOOST_PP_VARIADICS
58
59
#define YB_FIELD_EQUALS(r, data, elem) \
60
45.0M
    && 
lhs.BOOST_PP_CAT(elem, BOOST_PP_APPLY(data)) == rhs.BOOST_PP_CAT34.7M
(elem, BOOST_PP_APPLY(data))
61
#define YB_FIELDS_EQUALS(data, ...) \
62
66.4M
    
BOOST_PP_SEQ_FOR_EACH21.3M
(YB_FIELD_EQUALS, data(), BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
63
64
#define YB_STRUCT_EQUALS(...) \
65
21.3M
    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