Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rag analyzer #2232

Merged
merged 3 commits into from
Nov 15, 2024
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
30 changes: 18 additions & 12 deletions src/common/analyzer/darts_trie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,28 @@ void DartsTrie::Load(const String &file_name) { darts_->open(file_name.c_str());

void DartsTrie::Save(const String &file_name) { darts_->save(file_name.c_str()); }

bool DartsTrie::HasKeysWithPrefix(const String &key) {
std::size_t key_pos = 0;
DartsCore::value_type result = 0;
std::size_t id = 0;
for (std::size_t i = 0; i < key.length(); ++i) {
result = darts_->traverse(key.c_str(), id, key_pos, i + 1);
if (result == -2)
return false;
// string literal "" is null-terminated
constexpr std::string_view empty_null_terminated_sv = "";

bool DartsTrie::HasKeysWithPrefix(std::string_view key) const {
if (key.empty()) [[unlikely]] {
key = empty_null_terminated_sv;
}
std::size_t id = 0;
std::size_t key_pos = 0;
const auto result = darts_->traverse(key.data(), id, key_pos, key.size());
return result != -2;
}

int DartsTrie::Get(const String &key) {
DartsCore::value_type value;
darts_->exactMatchSearch(key.c_str(), value);
return value;
int DartsTrie::Traverse(const char *key, std::size_t &node_pos, std::size_t &key_pos, const std::size_t length) const {
return darts_->traverse(key, node_pos, key_pos, length);
}

int DartsTrie::Get(std::string_view key) const {
if (key.empty()) [[unlikely]] {
key = empty_null_terminated_sv;
}
return darts_->exactMatchSearch<DartsCore::value_type>(key.data(), key.size());
}

} // namespace infinity
6 changes: 4 additions & 2 deletions src/common/analyzer/darts_trie.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ public:

void Save(const String &file_name);

bool HasKeysWithPrefix(const String &key);
bool HasKeysWithPrefix(std::string_view key) const;

int Get(const String &key);
int Traverse(const char *key, SizeT &node_pos, SizeT &key_pos, SizeT length) const;

int Get(std::string_view key) const;
};

} // namespace infinity
Loading