Skip to content
Snippets Groups Projects
Commit 30e9a436 authored by Victor Perszel's avatar Victor Perszel :top:
Browse files

Pack and unpacking

parent 113a70e9
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <string>
class LZW{
public:
string pack(string &input);
string unpack(int input[]);
};
\ No newline at end of file
// Implementado por Eduardo Machado e Victor Perszel // Implementado por Eduardo Machado e Victor Perszel
#include <iostram> #include "lzw.h"
#include <string>
using namespace std; using namespace std;
class LZW{
private:
int dictionarySize = 256;
string LZW::pack(string &input){
public: map<string, int> dictionary;
compact(const string &input){ string output = "";
DICT dictionary[]; string nextChar, currentChar = "";
int i, cont=0, dictionarySize = 256;
//inicializa o dicionário //inicializa o dicionário
for (i=0; i<dictionarySize; i++){ for(i = 0; i < 256; i++){
dictionary.str[0]=i; dictionary[string(1, i)] = i;
} }
string nextChar, currentChar = "";
int i;
for(i = 0; i < input.size(); i++){ for(i = 0; i < input.size(); i++){
nextChar = input[i]; nextChar = input[i];
if(dictionary[currentChar + nextChar] != 0){
currentChar = currentChar + nextChar;
}else{
output += dictionary[currentChar] + " ";
dictionary[currentChar+nextChar] = dictionarySize;
currentChar = nextChar;
dictionarySize++;
cont++;
}
}
output += dictionary[currentChar] + " ";
cont++;
/* CONVERSAO
int *intOutput;
int temp = n = 0;
intOutput = new int[dictionarySize-1];
for(i = 0; i < cont; i++){
if(output[i] != " "){
temp++;
} else {
for (j = temp-1; j >= 0; j--){
intOutput[n] += output[j] * pow(10,j);
}
n++;
temp = 0;
}
}
*/
return intOutput;
}
string LZW::unpack(int input[]){
map<int, string> dictionary;
string currentChar, nextChar, output = "";
int i, dictionarySize = 256;
int currentWord, nextWord;
//inicializa o dicionário
for (i = 0; i < 256; i++){
dictionary[i] = string(1, i);
}
nextWord = input[0];
output += dictionary[nextWord];
for(i = 0; i < sizeof(input)/sizeof(int); i++){
currentWord = nextWord;
nextWord = input[i+1];
if(dictionary[nextWord] != ""){
output += dictionary[nextWord];
currentChar = dictionary[currentWord];
nextChar = dictionary[nextWord][1];
dictionary[dictionarySize] = currentChar + nextChar;
dictionarySize++;
}else{
currentChar = dictionary[currentWord];
nextChar = dictionary[currentWord][1];
output += currentChar + nextChar;
dictionary[dictionarySize] = currentChar + nextChar;
dictionarySize++;
} }
} }
return output;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment