Skip to content

Commit

Permalink
fix: make sure suggestions are unique before attempting matching
Browse files Browse the repository at this point in the history
  • Loading branch information
rustyconover committed Aug 30, 2024
1 parent 491c135 commit 199420f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/fuzzycomplete_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,27 @@ namespace duckdb
std::vector<const char *> candidate_pool_pointers;
std::vector<const char *> suggestion_results(max_results);

candidate_pool_pointers.reserve(available_suggestions.size());
// Make sure all of the suggestions are unique.

// Fill the c_str_pointers vector with the addresses of the C-strings
std::set<shared_ptr<std::string>> unique_suggestions;
for (const auto &str : available_suggestions)
{
candidate_pool_pointers.push_back(str.candidate.c_str());
unique_suggestions.insert(make_shared_ptr<string>(str.candidate));
}

candidate_pool_pointers.reserve(unique_suggestions.size());

for (const auto &str : unique_suggestions)
{
candidate_pool_pointers.push_back(str->c_str());
}

// Get the suggestions from rust
size_t actual_matches;

perform_matches(
candidate_pool_pointers.data(),
available_suggestions.size(),
candidate_pool_pointers.size(),
prefix.c_str(),
prefix.size(),
max_results,
Expand Down

0 comments on commit 199420f

Please sign in to comment.