Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. #include "HachageSTL.h"
  2. using namespace std;
  3.  
  4. void initialiserHachageSTL(HachageSTL & table)
  5. {
  6.      for(int i=0; i< table.donnee.size(); i++)
  7.      {
  8.          table.donnee[i].unePersonne.information=" ";
  9.          table.donnee[i].unePersonne.prenom=" ";
  10.          table.donnee[i].libre=true;
  11.          
  12.          list<PersonneSimple>::iterator it=table.donnee[i].listeCollisions.begin();
  13.          while(it!=table.donnee[i].listeCollisions.end())
  14.          {
  15.              PersonneSimple Buffer=*it;
  16.              Buffer.prenom=" ";
  17.              Buffer.information=" ";  
  18.              it++;  
  19.          }
  20.      }
  21. }
  22.  
  23. void afficher(const HachageSTL & table)
  24. {
  25.     for(int i=0; i< table.donnee.size(); i++)
  26.      {
  27.          cout << table.donnee[i].unePersonne.information << "\t" ;
  28.          cout << table.donnee[i].unePersonne.prenom << "\t" ;
  29.          cout << table.donnee[i].libre << "\t" << endl;
  30.          
  31.          list<PersonneSimple>::const_iterator it;
  32.          it=table.donnee[i].listeCollisions.begin();
  33.          while(it!=table.donnee[i].listeCollisions.end())
  34.          {
  35.              PersonneSimple Buffer=*it;
  36.              cout << Buffer.prenom << "\t";
  37.              cout << Buffer.information << "\t" <<endl;
  38.              it++;  
  39.          }
  40.      }
  41. }
  42.  
  43. bool clefPresente(const HachageSTL & table, const string & clef)
  44. {
  45.      if(table.donnee[hashCode(clef)].libre==true)
  46.      {
  47.           return false;
  48.      }
  49.      else
  50.      {
  51.          if(table.donnee[hashCode(clef)].unePersonne.prenom==clef)
  52.          {
  53.              return true;
  54.          }
  55.          else
  56.          {
  57.             list<PersonneSimple>::const_iterator it;
  58.             it=table.donnee[hashCode(clef)].listeCollisions.begin();
  59.              while(it!=table.donnee[hashCode(clef)].listeCollisions.end())
  60.              {
  61.                 PersonneSimple Buffer=*it;
  62.                 if(Buffer.prenom==clef)
  63.                 {
  64.                    return true;
  65.                 }
  66.              }
  67.          }
  68.      }
  69. }
  70.  
  71. void chercher(const HachageSTL & table, const string & clef, bool & trouve, string & information)
  72. {
  73.      trouve=false;
  74.      if(clefPresente(clef)==true)
  75.      {
  76.          if(table.donnee[hashCode(clef)].unePersonne.prenom==clef)
  77.          {
  78.              information=table.donnee[hashCode(clef)].unePersonne.information;
  79.          }
  80.          else
  81.          {
  82.             list<PersonneSimple>::const_iterator it;
  83.             it=table.donnee[hashCode(clef)].listeCollisions.begin();
  84.              while(it!=table.donnee[hashCode(clef)].listeCollisions.end())
  85.              {
  86.                 PersonneSimple Buffer=*it;
  87.                 if(Buffer.prenom==clef)
  88.                 {
  89.                     information=Buffer.information;
  90.                 }
  91.              }
  92.          }
  93.      }
  94. }
  95.  
  96. void inserer(HachageSTL & table, const string & clef, const string & info) throw (logic_error)
  97. {
  98.      if(clefPresente(clef)==true)
  99.      {
  100.          string error="Cle deja presente" + clef;
  101.          throw logic_error(error);
  102.      }
  103.      else
  104.      {
  105.          if(table.donnee[hashCode(clef)].libre==true)
  106.          {
  107.              table.donnee[hashCode(clef)].unePersonne.prenom=clef;
  108.              table.donnee[hashCode(clef)].unePersonne.information=info;
  109.              table.donnee[hashCode(clef)].libre=false;
  110.          }
  111.          else
  112.          {
  113.              PersonneSimple buffer;
  114.              buffer.prenom=clef;
  115.              buffer.information=info;
  116.              table.donnee[hashCode(clef)].listeCollisions.push_back(buffer);
  117.          }
  118.      }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement