@@ -595,7 +595,7 @@ void DlProofEnumerator::generateDProofRepresentativeFiles(uint32_t limit, bool r
595595 }
596596 }
597597 else
598- for (const string& s : allRepresentatives.back ()) {
598+ for (const string& s : allRepresentatives.back ())
599599 if (first) {
600600 bytes += s.length ();
601601 fout << s;
@@ -604,7 +604,6 @@ void DlProofEnumerator::generateDProofRepresentativeFiles(uint32_t limit, bool r
604604 bytes += s.length () + 1 ;
605605 fout << " \n " << s;
606606 }
607- }
608607 }
609608 cout << FctHelper::durationStringMs (chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime)) << " taken to print and save " << bytes << " bytes of representative condensed detachment proof strings to " << file.string () << " ." << endl;
610609 }
@@ -648,12 +647,31 @@ void DlProofEnumerator::createGeneratorFilesWithConclusions(const string& inputF
648647 // #cout << FctHelper::mapStringF(result, [](const pair<const string, string>& p) { return p.first + ":" + p.second; }, { }, { }, "\n");
649648 }
650649
651- // 3. Store generated D-proofs together with their conclusions permanently.
650+ // 3. Store generated D-proofs together with their conclusions permanently. Not using FctHelper::writeToFile() in order to write huge files without huge string acquisition.
652651 startTime = chrono::steady_clock::now ();
653- string file = outputFilePrefix + to_string (wordLengthLimit) + (wordLengthLimit < filteredMissing ? " .txt" : filePostfix);
654- string content = FctHelper::mapStringF (result, [](const pair<const string, string>& p) { return p.first + " :" + p.second ; }, { }, { }, " \n " );
655- FctHelper::writeToFile (file, content);
656- cout << FctHelper::durationStringMs (chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime)) << " taken to print and save " << content.length () << " bytes of representative condensed detachment proof strings to " << file << " ." << endl;
652+ filesystem::path file = filesystem::u8path (outputFilePrefix + to_string (wordLengthLimit) + (wordLengthLimit < filteredMissing ? " .txt" : filePostfix));
653+ string::size_type bytes = 0 ;
654+ {
655+ while (!filesystem::exists (file) && !FctHelper::ensureDirExists (file.string ()))
656+ cerr << " Failed to create file at \" " << file.string () << " \" , trying again." << endl;
657+ time_t time = chrono::system_clock::to_time_t (chrono::system_clock::now ());
658+ cout << strtok (ctime (&time), " \n " ) << " : Starting to write " << result.size () << " entries to " << file.string () << " ." << endl;
659+ ofstream fout (file, fstream::out | fstream::binary);
660+ bool first = true ;
661+ for (const pair<const string, string>& p : result) {
662+ const string& dProof = p.first ;
663+ const string& conclusion = p.second ;
664+ if (first) {
665+ bytes += dProof.length () + conclusion.length () + 1 ;
666+ fout << dProof << " :" << conclusion;
667+ first = false ;
668+ } else {
669+ bytes += dProof.length () + conclusion.length () + 2 ;
670+ fout << " \n " << dProof << " :" << conclusion;
671+ }
672+ }
673+ }
674+ cout << FctHelper::durationStringMs (chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime)) << " taken to print and save " << bytes << " bytes of representative condensed detachment proof strings to " << file.string () << " ." << endl;
657675
658676 // #if (wordLengthLimit <= 15)
659677 // # cout << "const vector<string> Resources::dProofConclusions" << wordLengthLimit << " = " << FctHelper::mapStringF(result, [](const pair<const string, string>& p) { return p.second; }, "{ \"", "\" };", "\", \"") << endl;
@@ -681,13 +699,29 @@ void DlProofEnumerator::createGeneratorFilesWithoutConclusions(const string& inp
681699 return ;
682700 }
683701
684- // 2. Store generated D-proofs without their conclusions permanently.
702+ // 2. Store generated D-proofs without their conclusions permanently. Not using FctHelper::writeToFile() in order to write huge files without huge string acquisition.
685703 for (uint32_t wordLengthLimit = 1 ; wordLengthLimit < allRepresentatives.size (); wordLengthLimit += 2 ) {
686704 startTime = chrono::steady_clock::now ();
687- string file = outputFilePrefix + to_string (wordLengthLimit) + (wordLengthLimit < filteredMissing ? " .txt" : filePostfix);
688- string content = FctHelper::vectorString (allRepresentatives[wordLengthLimit], { }, { }, " \n " );
689- FctHelper::writeToFile (file, content);
690- cout << FctHelper::durationStringMs (chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime)) << " taken to print and save " << content.length () << " bytes of representative condensed detachment proof strings to " << file << " ." << endl;
705+ filesystem::path file = filesystem::u8path (outputFilePrefix + to_string (wordLengthLimit) + (wordLengthLimit < filteredMissing ? " .txt" : filePostfix));
706+ string::size_type bytes = 0 ;
707+ {
708+ while (!filesystem::exists (file) && !FctHelper::ensureDirExists (file.string ()))
709+ cerr << " Failed to create file at \" " << file.string () << " \" , trying again." << endl;
710+ time_t time = chrono::system_clock::to_time_t (chrono::system_clock::now ());
711+ cout << strtok (ctime (&time), " \n " ) << " : Starting to write " << allRepresentatives[wordLengthLimit].size () << " entries to " << file.string () << " ." << endl;
712+ ofstream fout (file, fstream::out | fstream::binary);
713+ bool first = true ;
714+ for (const string& s : allRepresentatives[wordLengthLimit])
715+ if (first) {
716+ bytes += s.length ();
717+ fout << s;
718+ first = false ;
719+ } else {
720+ bytes += s.length () + 1 ;
721+ fout << " \n " << s;
722+ }
723+ }
724+ cout << FctHelper::durationStringMs (chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now () - startTime)) << " taken to print and save " << bytes << " bytes of representative condensed detachment proof strings to " << file.string () << " ." << endl;
691725 }
692726}
693727
0 commit comments