diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/containers/comptrie/comptrie_impl.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/containers/comptrie/comptrie_impl.cpp')
-rw-r--r-- | library/cpp/containers/comptrie/comptrie_impl.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/library/cpp/containers/comptrie/comptrie_impl.cpp b/library/cpp/containers/comptrie/comptrie_impl.cpp new file mode 100644 index 0000000000..a116ab6d1e --- /dev/null +++ b/library/cpp/containers/comptrie/comptrie_impl.cpp @@ -0,0 +1,39 @@ +#include "comptrie_impl.h" + +#include <util/system/rusage.h> +#include <util/stream/output.h> + +// Unpack the leaf value. The algorithm can store up to 8 full bytes in leafs. + +namespace NCompactTrie { + size_t MeasureOffset(size_t offset) { + int n = 0; + + while (offset) { + offset >>= 8; + ++n; + } + + return n; + } + + size_t PackOffset(char* buffer, size_t offset) { + size_t len = MeasureOffset(offset); + size_t i = len; + + while (i--) { + buffer[i] = (char)(offset & 0xFF); + offset >>= 8; + } + + return len; + } + + void ShowProgress(size_t n) { + if (n % 1000000 == 0) + Cerr << n << ", RSS=" << (TRusage::Get().MaxRss >> 20) << "mb" << Endl; + else if (n % 20000 == 0) + Cerr << "."; + } + +} |