Skip to content

Commit

Permalink
Merge pull request #12 from JustinShetty/master
Browse files Browse the repository at this point in the history
Chunkify regex_search
  • Loading branch information
Kei18 authored May 21, 2024
2 parents 12ef8d1 + 9ad52de commit 6bffc95
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "../include/ofApp.hpp"
#include "ofMain.h"

const std::regex r_config = std::regex(R"(^\d+:(.+))");
const std::regex r_pos = std::regex(R"(\((\d+),(\d+)\),)");

int main(int argc, char *argv[])
Expand All @@ -22,24 +21,26 @@ int main(int argc, char *argv[])
// load graph
Graph G(argv[1]);

// // load plan
// load plan
auto solution_file = std::ifstream(argv[2]);
Solution solution;
std::string line;
std::smatch m, results;
while (getline(solution_file, line)) {
if (std::regex_match(line, results, r_config)) {
auto s = results[1].str();
Config c;
auto iter = s.cbegin();
while (std::regex_search(iter, s.cend(), m, r_pos)) {
iter = m[0].second;
auto iter = line.cbegin();
Config c;
while (iter < line.cend()) {
auto search_end = std::min(iter + 128, line.cend());
if (std::regex_search(iter, search_end, m, r_pos)) {
auto x = std::stoi(m[1].str());
auto y = std::stoi(m[2].str());
c.push_back(G.U[G.width * y + x]);
iter += m[0].length();
} else {
break;
}
solution.push_back(c);
}
solution.push_back(c);
}
solution_file.close();

Expand Down

0 comments on commit 6bffc95

Please sign in to comment.