refactor: add WordRefList from WordList constructor
This commit is contained in:
parent
95cc7223e8
commit
3b1446f049
@ -22,6 +22,8 @@ public:
|
|||||||
|
|
||||||
class WordRefList : public std::vector<const std::string *> {
|
class WordRefList : public std::vector<const std::string *> {
|
||||||
public:
|
public:
|
||||||
|
WordRefList(const WordList &source);
|
||||||
|
|
||||||
static void find_prefix_in_range(
|
static void find_prefix_in_range(
|
||||||
const WordRefList &word_list, const std::string_view &search_prefix,
|
const WordRefList &word_list, const std::string_view &search_prefix,
|
||||||
size_t start_index, size_t end_index,
|
size_t start_index, size_t end_index,
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
#include "sorted_linear_finder.h"
|
#include "sorted_linear_finder.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
|
||||||
|
|
||||||
using std::forward_list, std::string, std::string_view;
|
using std::forward_list, std::string, std::string_view;
|
||||||
|
|
||||||
SortedLinearFinder::SortedLinearFinder(const WordList &word_list) {
|
SortedLinearFinder::SortedLinearFinder(const WordList &word_list)
|
||||||
std::transform(word_list.cbegin(), word_list.cend(),
|
: word_list_(word_list) {
|
||||||
std::back_inserter(word_list_),
|
|
||||||
[](const string &word) { return &word; });
|
|
||||||
|
|
||||||
std::sort(
|
std::sort(
|
||||||
word_list_.begin(), word_list_.end(),
|
word_list_.begin(), word_list_.end(),
|
||||||
[](const string *left, const string *right) { return *left < *right; });
|
[](const string *left, const string *right) { return *left < *right; });
|
||||||
|
@ -77,6 +77,12 @@ void WordList::find_prefix_in_range(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
WordRefList::WordRefList(const WordList &source) {
|
||||||
|
for (const auto &word : source) {
|
||||||
|
push_back(&word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WordRefList::find_prefix_in_range(
|
void WordRefList::find_prefix_in_range(
|
||||||
const WordRefList &word_list, const std::string_view &search_prefix,
|
const WordRefList &word_list, const std::string_view &search_prefix,
|
||||||
size_t start_index, size_t end_index,
|
size_t start_index, size_t end_index,
|
||||||
|
Reference in New Issue
Block a user