OmniSciDB  2e3a973ef4
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 
44 inline bool is_table_key(const ChunkKey& key) {
45  return key.size() == 2;
46 }
47 
48 inline bool has_table_prefix(const ChunkKey& key) {
49  return key.size() >= 2;
50 }
51 
52 inline ChunkKey get_table_key(const ChunkKey& key) {
53  CHECK(has_table_prefix(key));
55 }
56 
57 inline bool is_column_key(const ChunkKey& key) {
58  return key.size() == 3;
59 }
60 
61 inline bool is_varlen_key(const ChunkKey& key) {
62  return key.size() == 5;
63 }
64 
65 inline bool is_varlen_data_key(const ChunkKey& key) {
66  return key.size() == 5 && key[4] == 1;
67 }
68 
69 inline bool is_varlen_index_key(const ChunkKey& key) {
70  return key.size() == 5 && key[4] == 2;
71 }
72 
73 inline std::string show_chunk(const ChunkKey& key) {
74  std::ostringstream tss;
75  for (auto vecIt = key.begin(); vecIt != key.end(); ++vecIt) {
76  tss << *vecIt << ",";
77  }
78  return tss.str();
79 }
80 
81 #endif /* _TYPES_H */
bool is_column_key(const ChunkKey &key)
Definition: types.h:57
#define CHUNK_KEY_TABLE_IDX
Definition: types.h:40
bool is_table_key(const ChunkKey &key)
Definition: types.h:44
bool is_varlen_key(const ChunkKey &key)
Definition: types.h:61
bool is_varlen_index_key(const ChunkKey &key)
Definition: types.h:69
ChunkKey get_table_key(const ChunkKey &key)
Definition: types.h:52
bool has_table_prefix(const ChunkKey &key)
Definition: types.h:48
std::string show_chunk(const ChunkKey &key)
Definition: types.h:73
bool is_varlen_data_key(const ChunkKey &key)
Definition: types.h:65
#define CHECK(condition)
Definition: Logger.h:197
std::vector< int > ChunkKey
Definition: types.h:37
#define CHUNK_KEY_DB_IDX
Definition: types.h:39