Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Replace dictionary proxies with nested dictionaries 17/N #702

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions omniscidb/StringDictionary/StringDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ StringDictionary::StringDictionary(std::shared_ptr<StringDictionary> base_dict,
, payload_file_off_(0)
, strings_cache_(nullptr) {}

bool StringDictionary::operator==(StringDictionary const& rhs) const {
if (base_dict_ != rhs.base_dict_ || base_generation_ != rhs.base_generation_) {
return false;
}

const bool this_dict_is_locked_first = this < &rhs;
mapd_shared_lock<mapd_shared_mutex> first_read_lock(
this_dict_is_locked_first ? rw_mutex_ : rhs.rw_mutex_);
mapd_shared_lock<mapd_shared_mutex> second_read_lock(
this_dict_is_locked_first ? rhs.rw_mutex_ : rw_mutex_);

if (str_count_ != rhs.str_count_) {
return false;
}

for (auto str_id = base_generation_; str_id < static_cast<int64_t>(str_count_);
++str_id) {
if (getOwnedStringChecked(str_id) != rhs.getOwnedStringChecked(str_id)) {
return false;
}
}

return true;
}

bool StringDictionary::operator!=(StringDictionary const& rhs) const {
return !operator==(rhs);
}

namespace {
class MapMaker : public StringDictionary::StringCallback {
std::unordered_map<std::string, int32_t> map_;
Expand Down Expand Up @@ -628,6 +657,16 @@ std::string StringDictionary::getString(int32_t string_id) const {
return getOwnedStringChecked(string_id);
}

std::vector<std::string> StringDictionary::getStrings(
const std::vector<int32_t>& string_ids) const {
std::vector<std::string> strings;
strings.reserve(string_ids.size());
for (auto id : string_ids) {
strings.emplace_back(getString(id));
}
return strings;
}

std::string StringDictionary::getStringUnlocked(int32_t string_id) const noexcept {
if (string_id < base_generation_) {
return base_dict_->getString(string_id);
Expand Down
4 changes: 4 additions & 0 deletions omniscidb/StringDictionary/StringDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class StringDictionary {
StringDictionary* getBaseDictionary() const noexcept { return base_dict_.get(); }
int64_t getBaseGeneration() const noexcept { return base_generation_; }

bool operator==(StringDictionary const&) const;
bool operator!=(StringDictionary const&) const;

class StringCallback {
public:
virtual ~StringCallback() = default;
Expand Down Expand Up @@ -117,6 +120,7 @@ class StringDictionary {
template <class String>
int32_t getIdOfString(const String&) const;
std::string getString(int32_t string_id) const;
std::vector<std::string> getStrings(const std::vector<int32_t>& string_ids) const;
std::pair<char*, size_t> getStringBytes(int32_t string_id) const noexcept;
size_t storageEntryCount() const;
size_t entryCount() const;
Expand Down