OmniSciDB  2b310ab3b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StringDictionaryGenerations.cpp
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 
18 
19 #include "Logger/Logger.h"
20 
22  const uint64_t generation) {
23  id_to_generation_.emplace(id, generation);
24 }
25 
27  const uint64_t generation) {
28  CHECK(id_to_generation_.count(id));
29  id_to_generation_[id] = generation;
30 }
31 
32 int64_t StringDictionaryGenerations::getGeneration(const uint32_t id) const {
33  const auto it = id_to_generation_.find(id);
34  if (it != id_to_generation_.end()) {
35  return it->second;
36  }
37  // This happens when the query didn't need to do any translation from string
38  // to id. Return an invalid generation and StringDictionaryProxy will assert
39  // the methods which require a generation (the ones which go from string to id)
40  // are called on it if it has an invalid generation, only the id from string
41  // direction is allowed in such cases. Once a query finishes its effective
42  // execution, the generations are cleared and the string to id direction
43  // isn't needed anymore, only the opposite for the returned result set.
44  return -1;
45 }
46 
47 const std::unordered_map<uint32_t, uint64_t>& StringDictionaryGenerations::asMap() const {
48  return id_to_generation_;
49 }
50 
52  decltype(id_to_generation_)().swap(id_to_generation_);
53 }
void updateGeneration(const uint32_t id, const uint64_t generation)
int64_t getGeneration(const uint32_t id) const
std::unordered_map< uint32_t, uint64_t > id_to_generation_
const std::unordered_map< uint32_t, uint64_t > & asMap() const
CHECK(cgen_state)
void setGeneration(const uint32_t id, const uint64_t generation)