OmniSciDB  04ee39c94c
StringDictionaryProxy.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 #ifndef STRINGDICTIONARY_STRINGDICTIONARYPROXY_H
18 #define STRINGDICTIONARY_STRINGDICTIONARYPROXY_H
19 
20 #include <sys/mman.h>
21 #include <sys/stat.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include "../Shared/mapd_shared_mutex.h"
25 #include "StringDictionary.h"
26 
27 #include <map>
28 #include <string>
29 #include <tuple>
30 #include <vector>
31 
32 // used to access a StringDictionary when transient strings are involved
34  public:
35  StringDictionaryProxy(std::shared_ptr<StringDictionary> sd, const ssize_t generation);
36 
37  int32_t getOrAdd(const std::string& str) noexcept;
38  StringDictionary* getDictionary() noexcept;
39  ssize_t getGeneration() const noexcept;
40  int32_t getOrAddTransient(const std::string& str);
41  int32_t getIdOfString(const std::string& str) const;
43  const std::string& str) const; // disregard generation, only used by QueryRenderer
44  std::string getString(int32_t string_id) const;
45  std::pair<char*, size_t> getStringBytes(int32_t string_id) const noexcept;
46  size_t storageEntryCount() const;
47  void updateGeneration(const ssize_t generation) noexcept;
48 
49  std::vector<int32_t> getLike(const std::string& pattern,
50  const bool icase,
51  const bool is_simple,
52  const char escape) const;
53 
54  std::vector<int32_t> getCompare(const std::string& pattern,
55  const std::string& comp_operator) const;
56 
57  std::vector<int32_t> getRegexpLike(const std::string& pattern, const char escape) const;
58 
59  const std::map<int32_t, std::string> getTransientMapping() const {
60  return transient_int_to_str_;
61  }
62 
63  private:
64  std::shared_ptr<StringDictionary> string_dict_;
65  std::map<int32_t, std::string> transient_int_to_str_;
66  std::map<std::string, int32_t> transient_str_to_int_;
67  ssize_t generation_;
69 };
70 #endif // STRINGDICTIONARY_STRINGDICTIONARYPROXY_H
int32_t getIdOfString(const std::string &str) const
std::pair< char *, size_t > getStringBytes(int32_t string_id) const noexcept
std::map< int32_t, std::string > transient_int_to_str_
std::vector< int32_t > getLike(const std::string &pattern, const bool icase, const bool is_simple, const char escape) const
StringDictionary * getDictionary() noexcept
void updateGeneration(const ssize_t generation) noexcept
ssize_t getGeneration() const noexcept
const std::map< int32_t, std::string > getTransientMapping() const
std::shared_ptr< StringDictionary > string_dict_
std::string getString(int32_t string_id) const
std::shared_timed_mutex mapd_shared_mutex
std::map< std::string, int32_t > transient_str_to_int_
StringDictionaryProxy(std::shared_ptr< StringDictionary > sd, const ssize_t generation)
int32_t getOrAdd(const std::string &str) noexcept
int32_t getOrAddTransient(const std::string &str)
std::vector< int32_t > getRegexpLike(const std::string &pattern, const char escape) const
std::vector< int32_t > getCompare(const std::string &pattern, const std::string &comp_operator) const
int32_t getIdOfStringNoGeneration(const std::string &str) const
mapd_shared_mutex rw_mutex_