Tfe

Ongi etorri tfe-ren webgunera...

Old stuff/ecole_etude_fac_de_pau/nico/tad/inflater.cpp

(Deskargatu)
#include "inflater.h"
#include <string>
#include <iostream>
#include <map>
#include <vector>




Inflater::Inflater()
{
std::pair<unsigned int,char> element;
element.first=0;
element.second='\0';


dico.push_back(element);
for(int i=0;i<256;i++)
{
    element.second= i;    
    dico.push_back(element);
}

}







int Inflater::inflate()
{
    unsigned int precedent = memoire[0];
    std::pair<unsigned int,char> paire;
    std::string portion;

    std::cout << dico[memoire[0] ].second;

    for(int i=1;i<memoire.size();i++)
    {
    
    if (dico.size() > memoire[i] )
    {
    paire= dico[memoire[i] ];
    while(paire.first != 0)
    {
    paire= dico[ paire.first] ;
    }
    paire.first =  memoire[i-1];
    dico.push_back(paire);
//    std::cout << " Ajout de " << memoire[i-1] << paire.second << "\n";
    }
    else
    {
//	std::cout << "Mot pas trouve\n";
        paire= dico[memoire[i-1] ];	
        while(paire.first != 0)
        {
        paire= dico[ paire.first] ;
        }
//        std::cout << paire.first << paire.second << "\n";
    
        paire.first =  memoire[i-1];
        dico.push_back(paire);
//        std::cout << " Ajout de " << memoire[i-1] << paire.second << "\n";
	
    }
    
    portion.clear();
    paire = dico[ memoire[i] ];    
    while(paire.first != 0)
    {
	portion.append(&paire.second,1);    
	paire = dico[ paire.first] ;        
    }
    portion.append(&paire.second,1);        
    reverse(portion.begin(),portion.end());
    std::cout << portion;

    
    }
    std::cout << "\n";    
}




void Inflater::setinput(std::vector<unsigned int> a)
{
    memoire=a;
}