When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
void decompress(const string& filein, const string& fileout){
map<int16_t, string> dict; int n = 0; string result{}, temp{};
char ch{};
ifstream inp(filein, std::ios::binary);
if (!inp.good()) {
cout << "Wrong "; return;
}
int16_t idx; //int16_t
while (inp.read((char*)&idx, sizeof(idx)) && inp.read(&ch, sizeof(char)))
{
if (n > MAX_DICT) {
dict.clear();
n = 0;
}
if (idx == 0) {
dict[n] = ch;
result += ch;
}
else if (ch == ']') {
result += dict[idx];
}
else {
temp = dict[idx] + ch;
result += temp;
dict[n] = temp;
}
n++;
}
ofstream out(fileout, ios::out);
if (out.good()) {
out << result;
out.close();
}
else {
cout << "wrong";
}
}
And I "code" index using 2 bytes and character using 1 byte MAX dictionary size is 65535 value
But result file is not the same (slices some letters)
I'm not sure whether these ifs checking dictionary size and clearing it are in proper places