comptrie_impl.cpp 834 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "comptrie_impl.h"
  2. #include <util/system/rusage.h>
  3. #include <util/stream/output.h>
  4. // Unpack the leaf value. The algorithm can store up to 8 full bytes in leafs.
  5. namespace NCompactTrie {
  6. size_t MeasureOffset(size_t offset) {
  7. int n = 0;
  8. while (offset) {
  9. offset >>= 8;
  10. ++n;
  11. }
  12. return n;
  13. }
  14. size_t PackOffset(char* buffer, size_t offset) {
  15. size_t len = MeasureOffset(offset);
  16. size_t i = len;
  17. while (i--) {
  18. buffer[i] = (char)(offset & 0xFF);
  19. offset >>= 8;
  20. }
  21. return len;
  22. }
  23. void ShowProgress(size_t n) {
  24. if (n % 1000000 == 0)
  25. Cerr << n << ", RSS=" << (TRusage::Get().MaxRss >> 20) << "mb" << Endl;
  26. else if (n % 20000 == 0)
  27. Cerr << ".";
  28. }
  29. }