Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <boost/filesystem/v3/operations.hpp>
- #include <boost/interprocess/file_mapping.hpp>
- #include <boost/interprocess/mapped_region.hpp>
- #include <boost/chrono.hpp>
- #include <boost/array.hpp>
- #include <fstream>
- int main()
- {
- using namespace std;
- using namespace boost;
- chrono::system_clock::time_point now = chrono::system_clock::now();
- size_t size;
- {
- interprocess::file_mapping mfile("mapped_file.txt", interprocess::read_write);
- interprocess::mapped_region region(mfile, interprocess::read_write);
- array<char, 23> *const addr = (array<char, 23> *)region.get_address();
- size = region.get_size() / 23;
- sort(addr, addr + size, [] (array<char, 23> const &buf1, array<char, 23> const &buf2) {
- return memcmp(&buf1, &buf2, 21) < 0;
- });
- size = unique(addr, addr + size, [] (array<char, 23> const &buf1, array<char, 23> const &buf2) {
- return memcmp(&buf1, &buf2, 21) == 0;
- }) - addr;
- }
- filesystem::resize_file("mapped_file.txt", size * 23);
- cout << chrono::system_clock::now() - now;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement