YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/common/column_id.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_COMMON_COLUMN_ID_H
15
#define YB_COMMON_COLUMN_ID_H
16
17
#include <stdint.h>
18
19
#include <iosfwd>
20
#include <limits>
21
#include <string>
22
23
#include "yb/util/status_fwd.h"
24
25
namespace yb {
26
27
template<char digit1, char... digits>
28
struct ColumnIdHelper {
29
  typedef ColumnIdHelper<digit1> Current;
30
  typedef ColumnIdHelper<digits...> Next;
31
  static constexpr int mul = Next::mul * 10;
32
  static constexpr int value = Current::value * mul + Next::value;
33
  static_assert(value <= std::numeric_limits<int32_t>::max(), "Too big constant");
34
};
35
36
template<char digit>
37
struct ColumnIdHelper<digit> {
38
  static_assert(digit >= '0' && digit <= '9', "Only digits is allowed");
39
  static constexpr int value = digit - '0';
40
  static constexpr int mul = 1;
41
};
42
43
typedef int32_t ColumnIdRep;
44
45
// The ID of a column. Each column in a table has a unique ID.
46
class ColumnId {
47
 public:
48
  explicit ColumnId(ColumnIdRep t_);
49
50
  template<char... digits>
51
0
  constexpr explicit ColumnId(ColumnIdHelper<digits...>) : t_(ColumnIdHelper<digits...>::value) {}
Unexecuted instantiation: _ZN2yb8ColumnIdC2IJLc49EEEENS_14ColumnIdHelperIXspT_EEE
Unexecuted instantiation: _ZN2yb8ColumnIdC2IJLc48EEEENS_14ColumnIdHelperIXspT_EEE
Unexecuted instantiation: _ZN2yb8ColumnIdC2IJLc50EEEENS_14ColumnIdHelperIXspT_EEE
Unexecuted instantiation: _ZN2yb8ColumnIdC2IJLc49ELc48EEEENS_14ColumnIdHelperIXspT_EEE
Unexecuted instantiation: _ZN2yb8ColumnIdC2IJLc50ELc48EEEENS_14ColumnIdHelperIXspT_EEE
Unexecuted instantiation: _ZN2yb8ColumnIdC2IJLc51ELc48EEEENS_14ColumnIdHelperIXspT_EEE
Unexecuted instantiation: _ZN2yb8ColumnIdC2IJLc52ELc48EEEENS_14ColumnIdHelperIXspT_EEE
Unexecuted instantiation: _ZN2yb8ColumnIdC2IJLc53ELc48EEEENS_14ColumnIdHelperIXspT_EEE
52
53
170M
  ColumnId() : t_() {}
54
2.42G
  constexpr ColumnId(const ColumnId& t) : t_(t.t_) {}
55
279M
  ColumnId& operator=(const ColumnId& rhs) { t_ = rhs.t_; return *this; }
56
  ColumnId& operator=(const ColumnIdRep& rhs);
57
1.39G
  operator ColumnIdRep() const { return t_; }
58
594M
  ColumnIdRep rep() const { return t_; }
59
60
1.14M
  bool operator==(const ColumnId& rhs) const { return t_ == rhs.t_; }
61
0
  bool operator!=(const ColumnId& rhs) const { return t_ != rhs.t_; }
62
4.70G
  bool operator<(const ColumnId& rhs) const { return t_ < rhs.t_; }
63
37.1M
  bool operator>(const ColumnId& rhs) const { return t_ > rhs.t_; }
64
65
710k
  std::string ToString() const {
66
710k
    return std::to_string(t_);
67
710k
  }
68
69
  uint64_t ToUint64() const;
70
71
  static CHECKED_STATUS FromInt64(int64_t value, ColumnId *column_id);
72
73
796k
  size_t hash() const {
74
796k
    return t_;
75
796k
  }
76
77
 private:
78
  ColumnIdRep t_;
79
};
80
81
796k
inline size_t hash_value(ColumnId col) {
82
796k
  return col.hash();
83
796k
}
84
85
std::ostream& operator<<(std::ostream& os, ColumnId column_id);
86
87
88
static const ColumnId kInvalidColumnId = ColumnId(std::numeric_limits<ColumnIdRep>::max());
89
90
// In a new schema, we typically would start assigning column IDs at 0. However, this
91
// makes it likely that in many test cases, the column IDs and the column indexes are
92
// equal to each other, and it's easy to accidentally pass an index where we meant to pass
93
// an ID, without having any issues. So, in DEBUG builds, we start assigning columns at ID
94
// 10, ensuring that if we accidentally mix up IDs and indexes, we're likely to fire an
95
// assertion or bad memory access.
96
#ifdef NDEBUG
97
constexpr ColumnIdRep kFirstColumnIdRep = 0;
98
#else
99
constexpr ColumnIdRep kFirstColumnIdRep = 10;
100
#endif
101
const ColumnId kFirstColumnId(kFirstColumnIdRep);
102
103
template<char... digits>
104
0
ColumnId operator"" _ColId() {
105
0
  return ColumnId(ColumnIdHelper<digits...>());
106
0
}
Unexecuted instantiation: _ZN2ybli6_ColIdIJLc49EEEENS_8ColumnIdEv
Unexecuted instantiation: _ZN2ybli6_ColIdIJLc48EEEENS_8ColumnIdEv
Unexecuted instantiation: _ZN2ybli6_ColIdIJLc50EEEENS_8ColumnIdEv
Unexecuted instantiation: _ZN2ybli6_ColIdIJLc49ELc48EEEENS_8ColumnIdEv
Unexecuted instantiation: _ZN2ybli6_ColIdIJLc50ELc48EEEENS_8ColumnIdEv
Unexecuted instantiation: _ZN2ybli6_ColIdIJLc51ELc48EEEENS_8ColumnIdEv
Unexecuted instantiation: _ZN2ybli6_ColIdIJLc52ELc48EEEENS_8ColumnIdEv
Unexecuted instantiation: _ZN2ybli6_ColIdIJLc53ELc48EEEENS_8ColumnIdEv
107
108
}  // namespace yb
109
110
#endif  // YB_COMMON_COLUMN_ID_H