| 43 | } |
| 44 | |
| 45 | int parse(string const & filename, map<string, map_entry> & data) { |
| 46 | ifstream fs(filename.c_str()); |
| 47 | |
| 48 | if (!fs.is_open()) { |
| 49 | cout << "Can't open file '" << filename << "'" << endl; |
| 50 | return ENOENT; |
| 51 | } |
| 52 | |
| 53 | string qid; |
| 54 | string tokens[4]; |
| 55 | unsigned cur_token = 0; |
| 56 | |
| 57 | while (!fs.eof()) { |
| 58 | string line; |
| 59 | getline(fs, line); |
| 60 | |
| 61 | if (line.substr(0, prefix_len) == prefix) { |
| 62 | line = trim(line.substr(prefix_len)); |
| 63 | size_t from = 0, ti = 0; |
| 64 | for (size_t inx = line.find(" : ", from); |
| 65 | inx != string::npos; |
| 66 | inx = line.find(" : ", from)) { |
| 67 | tokens[ti] = trim(line.substr(from, inx-from)); |
| 68 | from = inx+3; //3 is the length of " : " |
| 69 | ti++; |
| 70 | } |
| 71 | if (from != line.length() && ti < 4) |
| 72 | tokens[ti] = trim(line.substr(from)); |
| 73 | |
| 74 | qid = tokens[0]; |
| 75 | |
| 76 | if (data.find(qid) == data.end()) { |
| 77 | map_entry & entry = data[qid]; |
| 78 | entry.num_instances = entry.max_generation = entry.max_cost = 0; |
| 79 | } |
| 80 | |
| 81 | // Existing entries represent previous occurrences of quantifiers |
| 82 | // that, at some point, were removed (e.g. backtracked). We sum |
| 83 | // up instances from all occurrences of the same qid. |
| 84 | map_entry & entry = data[qid]; |
| 85 | entry.num_instances += atoi(tokens[1].c_str()); |
| 86 | entry.max_generation = max(entry.max_generation, (unsigned)atoi(tokens[2].c_str())); |
| 87 | entry.max_cost = max(entry.max_cost, (unsigned)atoi(tokens[3].c_str())); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | fs.close(); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | void display_data(map<string, map_entry> & data) { |
| 97 | for (map<string, map_entry>::iterator it = data.begin(); |