Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <unordered_map>
- #include <unordered_set>
- using std::vector;
- using std::string;
- using std::unordered_map;
- using std::unordered_set;
- class uniqify {
- unordered_map<char, unordered_set<string>> maps;
- //mutable unsigned long long linecount{ 0 };
- public:
- inline bool exists(const char *filename) const noexcept {
- std::ifstream file(filename);
- bool good = file.good();
- return file.close(), good;
- }
- inline bool exists(const string &filename) const noexcept {
- return exists(filename.c_str());
- }
- vector<string> validate(const vector<string> &wordlists) const noexcept {
- vector<string> available(wordlists.size());
- std::copy_if(wordlists.cbegin(), wordlists.cend(), available.begin(), [this](string file) {return exists(file.c_str()); });
- return available;
- }
- void read(const string &filename) noexcept {
- std::ifstream input(filename);
- string line;
- while (std::getline(input, line)) {
- if (line != "") {
- linecount += 1;
- maps[line.c_str()[0]].insert(line);
- //if (!(linecount % 1000000))
- // std::cout << "Line count: " << linecount << std::endl;
- }
- }
- }
- void read(const vector<string> &wordlists) noexcept{
- for (auto list : wordlists)
- read(list);
- }
- void write(const char *filename) const noexcept {
- std::ofstream fout(filename);
- for (auto m : maps) {
- for (auto s : m.second) {
- fout << s << "\n";
- }
- }
- fout.close();
- }
- void write(const string &filename) const noexcept {
- write(filename.c_str());
- }
- inline void clear() {
- maps.clear();
- }
- };
- int main(int argc, char **argv) {
- uniqify u;
- vector<string> lists;
- for (auto i = 2; i < argc; ++i)
- lists.push_back(argv[i]);
- lists.swap(u.validate(lists));
- if (!lists.size())
- return std::cout << "No valid wordlists provided.\n", 0;
- u.read(lists);
- u.write(argv[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement