minimize.h 1.0 KB

1234567891011121314151617181920212223242526272829
  1. #pragma once
  2. #include "leaf_skipper.h"
  3. #include <cstddef>
  4. class IOutputStream;
  5. namespace NCompactTrie {
  6. size_t MeasureOffset(size_t offset);
  7. enum EMinimizeMode {
  8. MM_DEFAULT, // alollocate new memory for minimized tree
  9. MM_NOALLOC, // minimize tree in the same buffer
  10. MM_INPLACE // do not write tree to the stream, but move to the buffer beginning
  11. };
  12. // Return value: size of the minimized trie.
  13. size_t RawCompactTrieMinimizeImpl(IOutputStream& os, TOpaqueTrie& trie, bool verbose, size_t minMergeSize, EMinimizeMode mode);
  14. // Return value: size of the minimized trie.
  15. template <class TPacker>
  16. size_t CompactTrieMinimizeImpl(IOutputStream& os, const char* data, size_t datalength, bool verbose, const TPacker* packer, EMinimizeMode mode) {
  17. TPackerLeafSkipper<TPacker> skipper(packer);
  18. size_t minmerge = MeasureOffset(datalength);
  19. TOpaqueTrie trie(data, datalength, skipper);
  20. return RawCompactTrieMinimizeImpl(os, trie, verbose, minmerge, mode);
  21. }
  22. }