#include "linear_finder.h"
#include <forward_list>
#include <string_view>

using std::string, std::forward_list, std::string_view;

LinearFinder::LinearFinder(const WordList &word_list) : word_list_(word_list) {}

forward_list<const string *>
LinearFinder::find_prefix(string_view search_term) const {
  forward_list<const string *> matching_words;

  for (const auto &current_word : word_list_) {
    if (current_word.starts_with(search_term)) {
      matching_words.push_front(&current_word);
    }
  }

  return matching_words;
}
