OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DictRef.h
Go to the documentation of this file.
1 #ifndef DICTREF_H
2 #define DICTREF_H
3 
4 #include <cstdint>
5 #include <cstdlib>
6 #include <functional>
7 #include <string>
8 
9 #include "Shared/DbObjectKeys.h"
10 
11 // TODO: Replace DictRef with StringDictKey.
12 struct dict_ref_t {
13  int32_t dbId;
14  int32_t dictId;
15 
16  static constexpr int32_t invalidDbId{-1};
17  static constexpr int32_t invalidDictId{-1};
18  static constexpr int32_t literalsDictId{0};
19 
21  dict_ref_t(int32_t db_id, int32_t dict_id) : dbId(db_id), dictId(dict_id) {}
22 
23  operator shared::StringDictKey() const { return {dbId, dictId}; }
24 
25  inline bool operator==(const struct dict_ref_t& rhs) const {
26  return this->dictId == rhs.dictId && this->dbId == rhs.dbId;
27  }
28 
29  inline struct dict_ref_t& operator=(const struct dict_ref_t& rhs) {
30  this->dbId = rhs.dbId;
31  this->dictId = rhs.dictId;
32  return *this;
33  };
34 
35  inline bool operator<(const struct dict_ref_t& rhs) const {
36  return (this->dbId < rhs.dbId) ? true
37  : (this->dbId == rhs.dbId) ? this->dictId < rhs.dictId
38  : false;
39  }
40 
41  inline size_t operator()(const struct dict_ref_t& ref) const noexcept {
42  std::hash<int32_t> int32_hash;
43  return int32_hash(ref.dictId) ^ (int32_hash(ref.dbId) << 2);
44  }
45 
46  inline std::string toString() const {
47  return "(db_id: " + std::to_string(dbId) + ", dict_id: " + std::to_string(dictId) +
48  ")";
49  }
50 
51  static dict_ref_t InvalidDictRef() { return dict_ref_t(); }
52 };
53 
54 using DictRef = struct dict_ref_t;
55 
56 #endif
dict_ref_t()
Definition: DictRef.h:20
bool operator<(const struct dict_ref_t &rhs) const
Definition: DictRef.h:35
static constexpr int32_t invalidDbId
Definition: DictRef.h:16
struct dict_ref_t & operator=(const struct dict_ref_t &rhs)
Definition: DictRef.h:29
std::string to_string(char const *&&v)
int32_t dictId
Definition: DictRef.h:14
static constexpr int32_t invalidDictId
Definition: DictRef.h:17
dict_ref_t(int32_t db_id, int32_t dict_id)
Definition: DictRef.h:21
int32_t dbId
Definition: DictRef.h:13
std::string toString() const
Definition: DictRef.h:46
static dict_ref_t InvalidDictRef()
Definition: DictRef.h:51
bool operator==(const struct dict_ref_t &rhs) const
Definition: DictRef.h:25
size_t operator()(const struct dict_ref_t &ref) const noexcept
Definition: DictRef.h:41
static constexpr int32_t literalsDictId
Definition: DictRef.h:18