aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/containers/comptrie/minimize.h
blob: 246457143703b0a3e3d8be558e3c9d14d9dad9e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once

#include "leaf_skipper.h"
#include <cstddef>

class IOutputStream;

namespace NCompactTrie {
    size_t MeasureOffset(size_t offset); 

    enum EMinimizeMode { 
        MM_DEFAULT, // alollocate new memory for minimized tree 
        MM_NOALLOC, // minimize tree in the same buffer 
        MM_INPLACE  // do not write tree to the stream, but move to the buffer beginning 
    }; 

    // Return value: size of the minimized trie. 
    size_t RawCompactTrieMinimizeImpl(IOutputStream& os, TOpaqueTrie& trie, bool verbose, size_t minMergeSize, EMinimizeMode mode); 

    // Return value: size of the minimized trie. 
    template <class TPacker> 
    size_t CompactTrieMinimizeImpl(IOutputStream& os, const char* data, size_t datalength, bool verbose, const TPacker* packer, EMinimizeMode mode) { 
        TPackerLeafSkipper<TPacker> skipper(packer); 
        size_t minmerge = MeasureOffset(datalength); 
        TOpaqueTrie trie(data, datalength, skipper); 
        return RawCompactTrieMinimizeImpl(os, trie, verbose, minmerge, mode); 
    } 

}