OmniSciDB  04ee39c94c
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 
20  const size_t generation) {
21  id_to_generation_.emplace(id, generation);
22 }
23 
24 ssize_t StringDictionaryGenerations::getGeneration(const uint32_t id) const {
25  const auto it = id_to_generation_.find(id);
26  if (it != id_to_generation_.end()) {
27  return it->second;
28  }
29  // This happens when the query didn't need to do any translation from string
30  // to id. Return an invalid generation and StringDictionaryProxy will assert
31  // the methods which require a generation (the ones which go from string to id)
32  // are called on it if it has an invalid generation, only the id from string
33  // direction is allowed in such cases. Once a query finishes its effective
34  // execution, the generations are cleared and the string to id direction
35  // isn't needed anymore, only the opposite for the returned result set.
36  return -1;
37 }
38 
39 const std::unordered_map<uint32_t, size_t>& StringDictionaryGenerations::asMap() const {
40  return id_to_generation_;
41 }
42 
44  decltype(id_to_generation_)().swap(id_to_generation_);
45 }
ssize_t getGeneration(const uint32_t id) const
std::unordered_map< uint32_t, size_t > id_to_generation_
void setGeneration(const uint32_t id, const size_t generation)
const std::unordered_map< uint32_t, size_t > & asMap() const