so I'm trying to make a simple file compressor / decompressor in C++ (I'm not aiming for the best result possible) but I'm really stuck because I'm full of question so here they are :
What kind of dictionary should I use (i'm using map) ? What kind of Data should i store (i'm using String/int as key/value ) ? Should I initialize the dictionary with ASCII in it ? I saw some people uses nodes is it a god way to do it is it hard ?
Here's the code so far this isnt much :
#define MAX = 1024 //2^10 Where the dictionary reset
int main(int argc, char *argv[]){
ifstream in(argv[2], ios_base::binary);
ofstream of(argv[3], ios_base::binary);
string str ;
char c;
int i;
if (string(argv[1]) == "-c" ){
map<string,int> Dic;
while (in.get(c))
{
}
in.close();
}
}
Any comment on the code is welcome !
The answers follow from the algorithm, the description can be taken, for instance, here.
1) You need constantly check, if the input string is already present. You do not need order of the strings as std::map provides, you can use std::unordered_map which uses hash and is more efficient.
2) You can use string / unsigned int, as index is > 0.
3) Yes, from the algorithm description initial dictionary is 256 ASCII chars.
4) What do you mean by "nodes"?
Try to implement what is described in the article. The sample provided can be a unit test.