refactor: clean up
parent
f080d00697
commit
66a54d85cc
|
@ -7,7 +7,7 @@
|
|||
|
||||
class Bucket {
|
||||
private:
|
||||
std::map<const char, WordRefList> groups_;
|
||||
std::map<char, WordRefList> directory_;
|
||||
|
||||
public:
|
||||
void insert(const WordList &word_list, size_t first_index, size_t last_index);
|
||||
|
|
|
@ -6,20 +6,20 @@
|
|||
|
||||
void Bucket::insert(const WordList &word_list, size_t first_index,
|
||||
size_t last_index) {
|
||||
for (size_t index = first_index; index < last_index; ++index) {
|
||||
for (auto index = first_index; index < last_index; ++index) {
|
||||
const auto ¤t_word = word_list[index];
|
||||
groups_[current_word.front()].push_back(¤t_word);
|
||||
directory_[current_word.front()].push_back(¤t_word);
|
||||
}
|
||||
}
|
||||
|
||||
WordRefList Bucket::find_prefix(std::string_view search_term) const {
|
||||
auto group_it = groups_.find(search_term.front());
|
||||
if (group_it == groups_.cend()) {
|
||||
auto directory_it = directory_.find(search_term.front());
|
||||
if (directory_it == directory_.cend()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
WordRefList result;
|
||||
for (const auto *word : group_it->second) {
|
||||
for (const auto *word : directory_it->second) {
|
||||
if (word->starts_with(search_term)) {
|
||||
result.push_back(word);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue