20 #ifndef FST_EXTENSIONS_COMPRESS_ELIAS_H_ 21 #define FST_EXTENSIONS_COMPRESS_ELIAS_H_ 33 static void GammaEncode(
const Var &input, std::vector<bool> *code);
36 static void DeltaEncode(
const Var &input, std::vector<bool> *code);
39 static void BatchDecode(
const std::vector<bool> &input,
40 std::vector<Var> *output);
45 Var input_copy = input;
46 std::stack<bool> reverse_code;
47 while (input_copy > 0) {
48 reverse_code.push(input_copy % 2);
49 input_copy = input_copy / 2;
51 code->resize(reverse_code.size() - 1,
false);
52 while (!reverse_code.empty()) {
53 code->push_back(reverse_code.top());
60 Var input_copy = input + 1;
61 std::stack<bool> reverse_remainder;
63 while (input_copy != 0) {
64 reverse_remainder.push(input_copy % 2);
65 input_copy = input_copy / 2;
69 reverse_remainder.pop();
70 while (!reverse_remainder.empty()) {
71 code->push_back(reverse_remainder.top());
72 reverse_remainder.pop();
78 std::vector<Var> *output) {
80 Var remainder_bits = 0;
83 for (
auto it = input.cbegin(); it != input.cend();) {
93 while (lead_zeros > 0) {
95 current_word = 2 * current_word + *it;
99 while (current_word > 0) {
100 value = 2 * value + *it;
104 output->push_back(value - 1);
110 #endif // FST_EXTENSIONS_COMPRESS_ELIAS_H_ static void GammaEncode(const Var &input, std::vector< bool > *code)
static void BatchDecode(const std::vector< bool > &input, std::vector< Var > *output)
static void DeltaEncode(const Var &input, std::vector< bool > *code)