17 #ifndef STRINGDICTIONARY_STRINGDICTIONARYPROXY_H
18 #define STRINGDICTIONARY_STRINGDICTIONARYPROXY_H
24 #include "ThirdParty/robin_hood/robin_hood.h"
28 #include <shared_mutex>
30 #include <string_view>
34 namespace StringOps_Namespace {
45 const int64_t generation);
52 int32_t
getOrAdd(
const std::string& str) noexcept;
76 std::vector<int32_t>
getTransientBulk(const std::vector<std::
string>& strings) const;
83 const std::
string& str) const;
84 std::
string getString(int32_t string_id) const;
85 std::vector<std::
string>
getStrings(const std::vector<int32_t>& string_ids) const;
86 std::pair<const
char*,
size_t>
getStringBytes(int32_t string_id) const noexcept;
92 int64_t num_untranslated_strings_{-1};
99 : offset_(tran_size + 1), vector_map_(offset_ + dict_size) {}
101 : offset_(tran_size + 1), vector_map_(offset_ + dict_size, init_val) {}
102 TranslationMap(TranslationMap
const&) =
delete;
103 TranslationMap(TranslationMap&&) =
default;
104 bool empty()
const {
return vector_map_.size() == 1; }
105 inline size_t getIndex(int32_t
const id)
const {
return offset_ + id; }
107 size_t size()
const {
return vector_map_.size(); }
110 T*
data() {
return vector_map_.data(); }
111 T const*
data()
const {
return vector_map_.data(); }
112 int32_t
domainStart()
const {
return -
static_cast<int32_t
>(offset_); }
113 int32_t
domainEnd()
const {
return static_cast<int32_t
>(numNonTransients()); }
126 CHECK_GE(num_untranslated_strings_, 0L);
127 return static_cast<size_t>(num_untranslated_strings_);
130 num_untranslated_strings_ =
static_cast<int64_t
>(num_untranslated_strings);
133 T&
operator[](int32_t
const id) {
return vector_map_[getIndex(
id)]; }
134 T operator[](int32_t
const id)
const {
return vector_map_[getIndex(
id)]; }
135 friend std::ostream& operator<<(std::ostream& os, TranslationMap<T>
const& sdp_map) {
136 return os <<
"IdMap(offset_(" << sdp_map.offset_ <<
") vector_map_"
169 const std::vector<StringOps_Namespace::StringOpInfo>& string_op_infos)
const;
173 const std::vector<StringOps_Namespace::StringOpInfo>& string_op_infos)
const;
177 const std::vector<StringOps_Namespace::StringOpInfo>& string_op_types)
const;
210 template <
typename T>
211 std::vector<T>
getLike(
const std::string& pattern,
213 const bool is_simple,
214 const char escape)
const;
216 std::vector<int32_t>
getCompare(
const std::string& pattern,
217 const std::string& comp_operator)
const;
219 std::vector<int32_t>
getRegexpLike(
const std::string& pattern,
const char escape)
const;
225 return robin_hood::hash_bytes(key.data(), key.size());
231 bool operator()(std::string_view
const lhs, std::string_view
const rhs)
const {
240 using TransientMap = robin_hood::unordered_node_map<std::string,
242 HeterogeneousStringHash,
252 constexpr
int max_transient_string_id = -2;
253 return static_cast<unsigned>(max_transient_string_id - id);
257 constexpr
int max_transient_string_id = -2;
258 return static_cast<int32_t
>(max_transient_string_id - index);
273 template <
typename String>
275 template <
typename String>
279 const bool take_read_lock)
const;
280 template <
typename String>
283 const bool take_read_lock)
const;
284 template <
typename String>
286 int32_t* string_ids)
const;
287 template <
typename String>
289 int32_t* string_ids)
const;
293 const std::vector<StringOps_Namespace::StringOpInfo>& string_op_infos)
const;
304 template <
typename String>
306 template <
typename String>
312 #endif // STRINGDICTIONARY_STRINGDICTIONARYPROXY_H
void eachStringSerially(StringDictionary::StringCallback &) const
int32_t getOrAddTransientImpl(String)
void setNumUntranslatedStrings(const size_t num_untranslated_strings)
const shared::StringDictKey string_dict_key_
std::pair< const char *, size_t > getStringBytes(int32_t string_id) const noexcept
size_t transientEntryCountUnlocked() const
const std::vector< std::string const * > & getTransientVector() const
TranslationMap(uint32_t const tran_size, uint32_t const dict_size, const T &init_val)
size_t entryCount() const
Returns the number of total string entries for this proxy, both stored in the underlying dictionary a...
size_t numTransients() const
int32_t getIdOfStringNoGeneration(const std::string &str) const
T & operator[](int32_t const id)
std::string getStringUnlocked(const int32_t string_id) const
int32_t domainStart() const
size_t storageEntryCount() const
Returns the number of string entries in the underlying string dictionary, at this proxy's generation_...
TranslationMap(uint32_t const tran_size, uint32_t const dict_size)
StringDictionary * getDictionary() const noexcept
size_t transientLookupBulkUnlocked(const std::vector< String > &lookup_strings, int32_t *string_ids) const
StringDictionaryProxy const & operator=(StringDictionaryProxy const &)=delete
size_t transientLookupBulk(const std::vector< String > &lookup_strings, int32_t *string_ids, const bool take_read_lock) const
std::string getString(int32_t string_id) const
IdMap buildIntersectionTranslationMapToOtherProxyUnlocked(const StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos) const
size_t numNonTransients() const
size_t transientLookupBulkParallelUnlocked(const std::vector< String > &lookup_strings, int32_t *string_ids) const
int32_t getIdOfStringFromClient(String const &) const
std::vector< int32_t > getTransientBulk(const std::vector< std::string > &strings) const
Executes read-only lookup of a vector of strings and returns a vector of their integer ids...
size_t numUntranslatedStrings() const
TranslationMap< Datum > buildNumericTranslationMap(const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos) const
Builds a vectorized string_id translation map from this proxy to dest_proxy.
std::vector< int32_t > getCompare(const std::string &pattern, const std::string &comp_operator) const
int32_t domainEnd() const
TranslationMap< int32_t > IdMap
static constexpr int32_t INVALID_STR_ID
std::shared_ptr< StringDictionary > string_dict_
IdMap transientUnion(StringDictionaryProxy const &)
std::vector< std::string const * > transient_string_vec_
void setRangeEnd(const int32_t range_end)
int32_t lookupTransientStringUnlocked(const String &lookup_string) const
std::vector< std::string > getStrings(const std::vector< int32_t > &string_ids) const
size_t getTransientBulkImpl(const std::vector< std::string > &strings, int32_t *string_ids, const bool take_read_lock) const
size_t operator()(std::string_view const key) const
static int32_t transientIndexToId(unsigned const index)
void updateGeneration(const int64_t generation) noexcept
size_t transientEntryCount() const
Returns the number of transient string entries for this proxy,.
IdMap buildUnionTranslationMapToOtherProxy(StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_types) const
TransientMap transient_str_to_int_
StringDictionaryProxy(StringDictionaryProxy const &)=delete
void setRangeStart(const int32_t range_start)
int32_t getOrAddTransient(const std::string &)
size_t entryCountUnlocked() const
std::vector< T > getLike(const std::string &pattern, const bool icase, const bool is_simple, const char escape) const
int32_t getOrAddTransientUnlocked(String const &)
bool operator!=(StringDictionaryProxy const &) const
std::vector< int32_t > getRegexpLike(const std::string &pattern, const char escape) const
int32_t getOrAdd(const std::string &str) noexcept
bool operator==(StringDictionaryProxy const &) const
size_t getIndex(int32_t const id) const
std::vector< T > const & getVectorMap() const
std::vector< int32_t > getOrAddTransientBulk(const std::vector< std::string > &strings)
IdMap buildIntersectionTranslationMapToOtherProxy(const StringDictionaryProxy *dest_proxy, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos) const
std::shared_mutex rw_mutex_
robin_hood::unordered_node_map< std::string, int32_t, HeterogeneousStringHash, HeterogeneousStringEqual > TransientMap
nvtxRangeId_t range_start(const char *)
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
T operator[](int32_t const id) const
std::shared_timed_mutex shared_mutex
const shared::StringDictKey & getDictKey() const noexcept
void range_end(nvtxRangeId_t)
bool operator()(std::string_view const lhs, std::string_view const rhs) const
size_t persistedC() const
int32_t getIdOfString(const std::string &str) const
static unsigned transientIdToIndex(int32_t const id)
int64_t getGeneration() const noexcept
std::vector< T > vector_map_