diff options
author | grig <grig@yandex-team.ru> | 2022-02-10 16:50:24 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:24 +0300 |
commit | beb63ece3a6872dfbe113104f524ab6fdbec0adc (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/containers/comptrie/write_trie_backwards.cpp | |
parent | da383a4f674027527827ad076134241fc5da0cbf (diff) | |
download | ydb-beb63ece3a6872dfbe113104f524ab6fdbec0adc.tar.gz |
Restoring authorship annotation for <grig@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/containers/comptrie/write_trie_backwards.cpp')
-rw-r--r-- | library/cpp/containers/comptrie/write_trie_backwards.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/library/cpp/containers/comptrie/write_trie_backwards.cpp b/library/cpp/containers/comptrie/write_trie_backwards.cpp index 3109e342a7..fd8c28b0ed 100644 --- a/library/cpp/containers/comptrie/write_trie_backwards.cpp +++ b/library/cpp/containers/comptrie/write_trie_backwards.cpp @@ -11,23 +11,23 @@ namespace NCompactTrie { if (verbose) { Cerr << "Writing down the trie..." << Endl; } - + // Rewrite everything from the back, removing unused pieces. const size_t chunksize = 0x10000; TVector<char*> resultData; - + resultData.push_back(new char[chunksize]); char* chunkend = resultData.back() + chunksize; - + size_t resultLength = 0; size_t chunkLength = 0; - + size_t counter = 0; TBuffer bufferHolder; while (enumerator.Move()) { if (verbose) ShowProgress(++counter); - + size_t bufferLength = 64 + enumerator.GetLeafLength(); // never know how big leaf data can be bufferHolder.Clear(); bufferHolder.Resize(bufferLength); @@ -35,7 +35,7 @@ namespace NCompactTrie { size_t nodelength = enumerator.RecreateNode(buffer, resultLength); Y_ASSERT(nodelength <= bufferLength); - + resultLength += nodelength; if (chunkLength + nodelength <= chunksize) { @@ -44,14 +44,14 @@ namespace NCompactTrie { } else { // allocate a new chunk memcpy(chunkend - chunksize, buffer + nodelength - (chunksize - chunkLength), chunksize - chunkLength); chunkLength = chunkLength + nodelength - chunksize; - + resultData.push_back(new char[chunksize]); chunkend = resultData.back() + chunksize; - + while (chunkLength > chunksize) { // allocate a new chunks chunkLength -= chunksize; memcpy(chunkend - chunksize, buffer + chunkLength, chunksize); - + resultData.push_back(new char[chunksize]); chunkend = resultData.back() + chunksize; } @@ -70,11 +70,11 @@ namespace NCompactTrie { chunkLength = chunksize; delete[] chunk; resultData.pop_back(); - } + } return resultLength; - } - + } + size_t WriteTrieBackwardsNoAlloc(IOutputStream& os, TReverseNodeEnumerator& enumerator, TOpaqueTrie& trie, EMinimizeMode mode) { char* data = const_cast<char*>(trie.Data); char* end = data + trie.Length; |