OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DbObjectKeys.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cstddef>
20 #include <cstdint>
21 
22 #include <ostream>
23 
24 #define TRANSIENT_DICT_ID 0
25 #define TRANSIENT_DICT_DB_ID 0
26 
27 namespace shared {
28 struct StringDictKey {
29  StringDictKey() : db_id(0), dict_id(0) {}
30 
31  StringDictKey(int32_t db_id, int32_t dict_id) : db_id(db_id), dict_id(dict_id) {}
32 
33  bool operator==(const StringDictKey& other) const;
34 
35  bool operator!=(const StringDictKey& other) const;
36 
37  bool operator<(const StringDictKey& other) const;
38 
39  friend std::ostream& operator<<(std::ostream& os, const StringDictKey& dict_key);
40 
41  size_t hash() const;
42 
43  bool isTransientDict() const;
44 
46 
47  int32_t db_id;
48  int32_t dict_id;
49 };
50 
51 struct TableKey {
52  TableKey() : db_id(0), table_id(0) {}
53 
54  TableKey(int32_t db_id, int32_t table_id) : db_id(db_id), table_id(table_id) {}
55 
56  bool operator==(const TableKey& other) const;
57 
58  bool operator!=(const TableKey& other) const;
59 
60  bool operator<(const TableKey& other) const;
61 
62  friend std::ostream& operator<<(std::ostream& os, const TableKey& table_key);
63 
64  size_t hash() const;
65 
66  // Required by boost
67  friend size_t hash_value(const TableKey& table_key);
68 
69  int32_t db_id;
70  int32_t table_id;
71 };
72 
73 struct ColumnKey {
74  ColumnKey(int32_t db_id, int32_t table_id, int32_t column_id)
75  : db_id(db_id), table_id(table_id), column_id(column_id) {}
76 
77  ColumnKey(const TableKey& table_key, int32_t column_id)
78  : ColumnKey(table_key.db_id, table_key.table_id, column_id) {}
79 
80  bool operator==(const ColumnKey& other) const;
81 
82  bool operator!=(const ColumnKey& other) const;
83 
84  bool operator<(const ColumnKey& other) const;
85 
86  friend std::ostream& operator<<(std::ostream& os, const ColumnKey& column_key);
87 
88  size_t hash() const;
89 
90  int32_t db_id;
91  int32_t table_id;
92  int32_t column_id;
93 };
94 } // namespace shared
95 
96 namespace std {
97 template <>
98 struct hash<shared::StringDictKey> {
99  size_t operator()(const shared::StringDictKey& dict_key) const {
100  return dict_key.hash();
101  }
102 };
103 
104 template <>
105 struct hash<shared::TableKey> {
106  size_t operator()(const shared::TableKey& table_key) const { return table_key.hash(); }
107 };
108 
109 template <>
110 struct hash<shared::ColumnKey> {
111  size_t operator()(const shared::ColumnKey& column_key) const {
112  return column_key.hash();
113  }
114 };
115 } // namespace std
friend std::ostream & operator<<(std::ostream &os, const TableKey &table_key)
std::tuple< int, std::string > ColumnKey
Definition: Types.h:37
size_t hash() const
ColumnKey(const TableKey &table_key, int32_t column_id)
Definition: DbObjectKeys.h:77
size_t operator()(const shared::ColumnKey &column_key) const
Definition: DbObjectKeys.h:111
bool operator<(const ColumnKey &other) const
ColumnKey(int32_t db_id, int32_t table_id, int32_t column_id)
Definition: DbObjectKeys.h:74
size_t hash() const
bool operator<(const TableKey &other) const
friend std::ostream & operator<<(std::ostream &os, const ColumnKey &column_key)
bool operator<(const StringDictKey &other) const
bool operator==(const StringDictKey &other) const
StringDictKey(int32_t db_id, int32_t dict_id)
Definition: DbObjectKeys.h:31
friend std::ostream & operator<<(std::ostream &os, const StringDictKey &dict_key)
size_t operator()(const shared::StringDictKey &dict_key) const
Definition: DbObjectKeys.h:99
bool operator==(const ColumnKey &other) const
bool isTransientDict() const
static const StringDictKey kTransientDictKey
Definition: DbObjectKeys.h:45
friend size_t hash_value(const TableKey &table_key)
TableKey(int32_t db_id, int32_t table_id)
Definition: DbObjectKeys.h:54
bool operator==(const TableKey &other) const
size_t operator()(const shared::TableKey &table_key) const
Definition: DbObjectKeys.h:106
bool operator!=(const TableKey &other) const
bool operator!=(const ColumnKey &other) const
bool operator!=(const StringDictKey &other) const
size_t hash() const