MCPcopy Create free account
hub / github.com/catboost/catboost / DoGenAndWrite

Function DoGenAndWrite

util/stream/buffered_ut.cpp:77–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75
76 template <class TOut>
77 inline void DoGenAndWrite(TOut&& output, TString& str) {
78 TMersenne<ui64> r;
79 for (size_t i = 0; i < 43210; ++i) {
80 str.append('A' + (r.GenRand() % 10));
81 }
82 size_t written = 0;
83 void* ptr = nullptr;
84 while (written < str.size()) {
85 size_t bufferSize = output.Next(&ptr);
86 UNIT_ASSERT(ptr && bufferSize > 0);
87 size_t toWrite = Min(bufferSize, str.size() - written);
88 memcpy(ptr, str.begin() + written, toWrite);
89 written += toWrite;
90 if (toWrite < bufferSize) {
91 output.Undo(bufferSize - toWrite);
92 }
93 }
94 }
95
96 Y_UNIT_TEST(TestWriteViaNextAndUndo) {
97 TString str1, str2;

Callers 1

Y_UNIT_TESTFunction · 0.85

Calls 7

MinFunction · 0.50
appendMethod · 0.45
GenRandMethod · 0.45
sizeMethod · 0.45
NextMethod · 0.45
beginMethod · 0.45
UndoMethod · 0.45

Tested by

no test coverage detected