-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqe.cpp
32 lines (27 loc) · 968 Bytes
/
qe.cpp
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
30
31
32
#include "coder.h"
#include "quality_model.h"
#include <array>
#include <iostream>
int main()
{
std::ios_base::sync_with_stdio(false);
const std::string alphabet = "\n !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\0";
QualityModel model(alphabet.size());
std::array<unsigned char, 256> alphabet_map;
{
for (unsigned char& c : alphabet_map) { c = 0x00; }
unsigned char index = 0;
for (char ch : alphabet) {
alphabet_map[static_cast<unsigned char>(ch)] = index++;
}
}
range_code::Encoder coder(std::cout.rdbuf());
std::streambuf* istreambuf = std::cin.rdbuf();
for (int byte = istreambuf->sgetc(); byte != EOF; byte = istreambuf->snextc()) {
const auto symbol = alphabet_map.at(byte);
coder.Put(symbol, model.cdf());
model.Update(symbol);
}
coder.Put(alphabet.size() - 1, model.cdf());
return 0;
}