Tfe

Ongi etorri tfe-ren webgunera...

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

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




Deflater::Deflater()
{

  std::string chaine;  
  for(int i=0;i<256;i++)
    {
    chaine=i;
    std::cout << "AJOUT DE " << chaine  << " : " << i+1 << "\n";
      dico[chaine]=i+1;
    }
}




int Deflater::add(std::string s)
{

  dico[s] = dico.size();
  return dico.size();
}



int Deflater::seek(std::string s)
{
    return dico.find(s) != dico.end();
}



int Deflater::deflate()
{
  std::string s;
  std::string precedent;
  std::vector<unsigned int> s2;
  int j=0;
  int longueur=1;
  for(int i=0;i<memoire.length();i++)
    {
	longueur=0;
	std::cout << "Etude de : " << memoire[i] << "\n";
	s=memoire[i];	
	precedent=s;
      while(seek(s))
	{
	  precedent=s;
	  longueur++;
	 s.append(&memoire[i+longueur],1);
	 std::cout << "\tMot en cours: " << s << "\n";
    }	
    add(s);
    sortie.push_back(dico[precedent]);
    std::cout << "longueur: " << longueur << "\n";
    i=i+longueur-1;
    }


    std::cout << "Resultat: ";
    for(int i=0;i<sortie.size();i++)
    {
	std::cout << sortie[i] << "\t";
    }
    std::cout << "\n";
}

void Deflater::setinput(std::string a)
{
    memoire=a;
}