OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
types.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 /*
18  * File: types.h
19  * Author(s): steve@map-d.com
20  *
21  * Created on June 19, 2014, 4:29 PM
22  */
23 
24 #ifndef _TYPES_H
25 #define _TYPES_H
26 
27 #include <sstream>
28 #include <string>
29 #include <thread>
30 #include <vector>
31 
32 #include "Logger/Logger.h"
33 
34 // The ChunkKey is a unique identifier for chunks in the database file.
35 // The first element of the underlying vector for ChunkKey indicates the type of
36 // ChunkKey (also referred to as the keyspace id)
37 using ChunkKey = std::vector<int>;
38 
39 #define CHUNK_KEY_DB_IDX 0
40 #define CHUNK_KEY_TABLE_IDX 1
41 #define CHUNK_KEY_COLUMN_IDX 2
42 #define CHUNK_KEY_FRAGMENT_IDX 3
43 #define CHUNK_KEY_VARLEN_IDX 4
44 
45 inline bool is_table_key(const ChunkKey& key) {
46  return key.size() == 2;
47 }
48 
49 inline bool has_table_prefix(const ChunkKey& key) {
50  return key.size() >= 2;
51 }
52 
53 inline ChunkKey get_table_key(const ChunkKey& key) {
54  CHECK(has_table_prefix(key));
56 }
57 
58 inline std::pair<int, int> get_table_prefix(const ChunkKey& key) {
59  CHECK(has_table_prefix(key));
60  return std::pair<int, int>{key[CHUNK_KEY_DB_IDX], key[CHUNK_KEY_TABLE_IDX]};
61 }
62 
63 inline bool is_column_key(const ChunkKey& key) {
64  return key.size() == 3;
65 }
66 
67 inline bool is_varlen_key(const ChunkKey& key) {
68  return key.size() == 5;
69 }
70 
71 inline bool is_varlen_data_key(const ChunkKey& key) {
72  return key.size() == 5 && key[4] == 1;
73 }
74 
75 inline bool is_varlen_index_key(const ChunkKey& key) {
76  return key.size() == 5 && key[4] == 2;
77 }
78 
79 inline bool in_same_table(const ChunkKey& left_key, const ChunkKey& right_key) {
80  CHECK(has_table_prefix(left_key));
81  CHECK(has_table_prefix(right_key));
82  return (left_key[CHUNK_KEY_DB_IDX] == right_key[CHUNK_KEY_DB_IDX] &&
83  left_key[CHUNK_KEY_TABLE_IDX] == right_key[CHUNK_KEY_TABLE_IDX]);
84 }
85 
86 inline std::string show_chunk(const ChunkKey& key) {
87  std::ostringstream tss;
88  for (auto vecIt = key.begin(); vecIt != key.end(); ++vecIt) {
89  tss << *vecIt << ",";
90  }
91  return tss.str();
92 }
93 
94 #endif /* _TYPES_H */
std::vector< int > ChunkKey
Definition: types.h:37
bool is_table_key(const ChunkKey &key)
Definition: types.h:45
bool is_varlen_data_key(const ChunkKey &key)
Definition: types.h:71
#define CHUNK_KEY_DB_IDX
Definition: types.h:39
ChunkKey get_table_key(const ChunkKey &key)
Definition: types.h:53
std::string show_chunk(const ChunkKey &key)
Definition: types.h:86
bool is_varlen_index_key(const ChunkKey &key)
Definition: types.h:75
#define CHUNK_KEY_TABLE_IDX
Definition: types.h:40
bool has_table_prefix(const ChunkKey &key)
Definition: types.h:49
bool is_column_key(const ChunkKey &key)
Definition: types.h:63
std::pair< int, int > get_table_prefix(const ChunkKey &key)
Definition: types.h:58
#define CHECK(condition)
Definition: Logger.h:209
bool in_same_table(const ChunkKey &left_key, const ChunkKey &right_key)
Definition: types.h:79
bool is_varlen_key(const ChunkKey &key)
Definition: types.h:67