refactor: remove using from header files

This commit is contained in:
Michael Mandl 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 <forward_list>
#include <string> #include <string>
using std::string, std::string_view, std::forward_list;
class Finder { class Finder {
public: public:
virtual ~Finder() = default; virtual ~Finder() = default;
virtual forward_list<const string *> virtual std::forward_list<const std::string *>
find_prefix(string_view search_term) const = 0; 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_; std::map<char, std::vector<const std::string *>> groups_;
public: public:
GroupedFinder(const std::vector<string> &word_list); GroupedFinder(const std::vector<std::string> &word_list);
virtual std::forward_list<const std::string *> virtual std::forward_list<const std::string *>
find_prefix(std::string_view search_term) const override; find_prefix(std::string_view search_term) const override;

View file

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

View file

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

View file

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

View file

@ -1,10 +1,12 @@
#include "grouped_finder.h" #include "grouped_finder.h"
#include <forward_list>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include <vector> #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) { GroupedFinder::GroupedFinder(const std::vector<string> &word_list) {
for (const auto &word : word_list) { for (const auto &word : word_list) {

View file

@ -1,4 +1,8 @@
#include "linear_finder.h" #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) LinearFinder::LinearFinder(const vector<string> &word_list)
: word_list_(word_list) {} : word_list_(word_list) {}

View file

@ -3,7 +3,8 @@
#include <mutex> #include <mutex>
#include <thread> #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) ParallelFinder::ParallelFinder(const vector<string> &word_list)
: word_list_(word_list) {} : word_list_(word_list) {}

View file

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