OmniSciDB  c1a53651b2
 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 
45  int32_t db_id;
46  int32_t dict_id;
47 };
48 
49 struct TableKey {
50  TableKey() : db_id(0), table_id(0) {}
51 
52  TableKey(int32_t db_id, int32_t table_id) : db_id(db_id), table_id(table_id) {}
53 
54  bool operator==(const TableKey& other) const;
55 
56  bool operator!=(const TableKey& other) const;
57 
58  bool operator<(const TableKey& other) const;
59 
60  friend std::ostream& operator<<(std::ostream& os, const TableKey& table_key);
61 
62  size_t hash() const;
63 
64  int32_t db_id;
65  int32_t table_id;
66 };
67 
68 struct ColumnKey {
69  ColumnKey(int32_t db_id, int32_t table_id, int32_t column_id)
70  : db_id(db_id), table_id(table_id), column_id(column_id) {}
71 
72  ColumnKey(const TableKey& table_key, int32_t column_id)
73  : ColumnKey(table_key.db_id, table_key.table_id, column_id) {}
74 
75  bool operator==(const ColumnKey& other) const;
76 
77  bool operator!=(const ColumnKey& other) const;
78 
79  bool operator<(const ColumnKey& other) const;
80 
81  friend std::ostream& operator<<(std::ostream& os, const ColumnKey& column_key);
82 
83  size_t hash() const;
84 
85  int32_t db_id;
86  int32_t table_id;
87  int32_t column_id;
88 };
89 } // namespace shared
90 
91 namespace std {
92 template <>
93 struct hash<shared::StringDictKey> {
94  size_t operator()(const shared::StringDictKey& dict_key) const {
95  return dict_key.hash();
96  }
97 };
98 
99 template <>
100 struct hash<shared::TableKey> {
101  size_t operator()(const shared::TableKey& table_key) const { return table_key.hash(); }
102 };
103 
104 template <>
105 struct hash<shared::ColumnKey> {
106  size_t operator()(const shared::ColumnKey& column_key) const {
107  return column_key.hash();
108  }
109 };
110 } // 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:72
size_t operator()(const shared::ColumnKey &column_key) const
Definition: DbObjectKeys.h:106
bool operator<(const ColumnKey &other) const
ColumnKey(int32_t db_id, int32_t table_id, int32_t column_id)
Definition: DbObjectKeys.h:69
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:94
bool operator==(const ColumnKey &other) const
bool isTransientDict() const
TableKey(int32_t db_id, int32_t table_id)
Definition: DbObjectKeys.h:52
bool operator==(const TableKey &other) const
size_t operator()(const shared::TableKey &table_key) const
Definition: DbObjectKeys.h:101
bool operator!=(const TableKey &other) const
bool operator!=(const ColumnKey &other) const
bool operator!=(const StringDictKey &other) const
size_t hash() const