refactor: remove using from header files

main
mandlm 2024-03-20 20:51:16 +01:00
parent 26d3839832
commit ad8a9ada83
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
9 changed files with 32 additions and 25 deletions

View File

@ -3,12 +3,10 @@
#include <forward_list>
#include <string>
using std::string, std::string_view, std::forward_list;
class Finder {
public:
virtual ~Finder() = default;
virtual forward_list<const string *>
find_prefix(string_view search_term) const = 0;
virtual std::forward_list<const std::string *>
find_prefix(std::string_view search_term) const = 0;
};

View File

@ -10,7 +10,7 @@ private:
std::map<char, std::vector<const std::string *>> groups_;
public:
GroupedFinder(const std::vector<string> &word_list);
GroupedFinder(const std::vector<std::string> &word_list);
virtual std::forward_list<const std::string *>
find_prefix(std::string_view search_term) const override;

View File

@ -8,10 +8,10 @@ using std::vector;
class LinearFinder : public Finder {
private:
const vector<string> &word_list_;
const vector<std::string> &word_list_;
public:
LinearFinder(const vector<string> &word_list);
forward_list<const string *>
find_prefix(string_view search_term) const override;
LinearFinder(const vector<std::string> &word_list);
std::forward_list<const std::string *>
find_prefix(std::string_view search_term) const override;
};

View File

@ -6,10 +6,10 @@
class ParallelFinder : public Finder {
private:
const std::vector<string> &word_list_;
const std::vector<std::string> &word_list_;
public:
ParallelFinder(const std::vector<string> &word_list);
ParallelFinder(const std::vector<std::string> &word_list);
std::forward_list<const std::string *>
find_prefix(std::string_view search_term) const override;

View File

@ -11,7 +11,7 @@ private:
std::map<const char, SearchTreeNode> children_;
public:
void insert(std::string_view partial_word, const string *original_word);
void insert(std::string_view partial_word, const std::string *original_word);
const SearchTreeNode *find(std::string_view search_term) const;
std::forward_list<const std::string *> words() const;
@ -27,7 +27,7 @@ private:
SearchTree search_tree_;
public:
TreeFinder(const std::vector<string> &word_list);
TreeFinder(const std::vector<std::string> &word_list);
virtual std::forward_list<const std::string *>
find_prefix(std::string_view search_term) const override;

View File

@ -1,10 +1,12 @@
#include "grouped_finder.h"
#include <forward_list>
#include <mutex>
#include <thread>
#include <vector>
using std::mutex, std::vector, std::thread, std::lock_guard;
using std::mutex, std::vector, std::thread, std::lock_guard, std::string,
std::forward_list, std::string_view;
GroupedFinder::GroupedFinder(const std::vector<string> &word_list) {
for (const auto &word : word_list) {

View File

@ -1,4 +1,8 @@
#include "linear_finder.h"
#include <forward_list>
#include <string_view>
using std::string, std::forward_list, std::string_view;
LinearFinder::LinearFinder(const vector<string> &word_list)
: word_list_(word_list) {}

View File

@ -3,7 +3,8 @@
#include <mutex>
#include <thread>
using std::mutex, std::thread, std::lock_guard, std::vector, std::forward_list;
using std::mutex, std::thread, std::lock_guard, std::vector, std::forward_list,
std::string, std::string_view;
ParallelFinder::ParallelFinder(const vector<string> &word_list)
: word_list_(word_list) {}

View File

@ -1,17 +1,19 @@
#include "tree_finder.h"
void SearchTreeNode::insert(std::string_view partial_word,
using std::string, std::string_view, std::forward_list, std::vector;
void SearchTreeNode::insert(string_view partial_word,
const string *original_word) {
if (partial_word.empty()) {
words_.push_front(original_word);
} else {
children_[partial_word.front()].insert(
std::string_view(partial_word).substr(1, partial_word.length()),
string_view(partial_word).substr(1, partial_word.length()),
original_word);
}
}
const SearchTreeNode *SearchTreeNode::find(std::string_view search_term) const {
const SearchTreeNode *SearchTreeNode::find(string_view search_term) const {
if (search_term.empty()) {
return this;
}
@ -24,8 +26,8 @@ const SearchTreeNode *SearchTreeNode::find(std::string_view search_term) const {
return nullptr;
}
std::forward_list<const std::string *> SearchTreeNode::words() const {
std::forward_list<const std::string *> results(words_);
forward_list<const string *> SearchTreeNode::words() const {
forward_list<const string *> results(words_);
for (const auto &child : children_) {
results.merge(child.second.words());
}
@ -33,17 +35,17 @@ std::forward_list<const std::string *> SearchTreeNode::words() const {
return results;
};
SearchTree::SearchTree(const std::vector<std::string> &word_list) {
SearchTree::SearchTree(const vector<string> &word_list) {
for (const auto &word : word_list) {
insert(std::string_view(word), &word);
insert(string_view(word), &word);
}
}
TreeFinder::TreeFinder(const std::vector<string> &word_list)
TreeFinder::TreeFinder(const vector<string> &word_list)
: search_tree_(word_list) {}
std::forward_list<const std::string *>
TreeFinder::find_prefix(std::string_view search_term) const {
forward_list<const string *>
TreeFinder::find_prefix(string_view search_term) const {
const auto *result_node = search_tree_.find(search_term);
if (result_node == nullptr) {
return {};