Created
June 10, 2014 18:00
-
-
Save carasuca/40ec55e8d694f34d13e0 to your computer and use it in GitHub Desktop.
Find matching lines in file pairs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <map> | |
#include <array> | |
#include <fstream> | |
#include <algorithm> | |
using namespace std; | |
typedef array<char, 32> buf_t; | |
typedef map<buf_t, buf_t> cmap_t; | |
struct cloud : cmap_t | |
{ | |
cloud(const string& name) | |
{ | |
buf_t buf1, buf2; | |
ifstream f1(name + ".txt"), f2(name + ".col"); | |
while (buf1.assign(0), buf2.assign(0), | |
f1.getline(buf1.data(), buf1.size()) && | |
f2.getline(buf2.data(), buf2.size())) | |
insert(value_type(buf1, buf2)); | |
} | |
cloud(const cmap_t& m1, const cmap_t& m2) | |
{ | |
set_intersection( | |
m1.cbegin(), m1.cend(), | |
m2.cbegin(), m2.cend(), | |
inserter<cloud>(*this, begin()), | |
[](const value_type& p1, const value_type& p2) { return p1.first < p2.first; }); | |
} | |
void save(const string& name) | |
{ | |
ofstream f1(name + ".txt"), f2(name + ".col"); | |
for (auto p : *this) | |
{ | |
f1 << p.first.data() << endl; | |
f2 << p.second.data() << endl; | |
} | |
} | |
}; | |
int main() | |
{ | |
const string n1("rgb"), n2("phong"), pref("out\\miska_"); | |
for (string id = "_000"; id.back() != '4'; id.back()++) | |
{ | |
const string name1(n1 + id), name2(n2 + id); | |
const cloud c1(name1), c2(name2); | |
cloud(c1, c2).save(pref + name1); | |
cloud(c2, c1).save(pref + name2); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment