Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.47 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.     const int hash=hashCode(clef);
  46.      if(table.donnee[hash].libre==true)
  47.      {
  48.           return false;
  49.      }
  50.      else
  51.      {
  52.          if(table.donnee[hash].unePersonne.prenom==clef)
  53.          {
  54.              return true;
  55.          }
  56.          else
  57.          {
  58.             list<PersonneSimple>::const_iterator it;
  59.             it=table.donnee[hash].listeCollisions.begin();
  60.              while(it!=table.donnee[hash].listeCollisions.end())
  61.              {
  62.                 PersonneSimple Buffer=*it;
  63.                 if(Buffer.prenom==clef)
  64.                 {
  65.                    return true;
  66.                 }
  67.              }
  68.          }
  69.      }
  70. }
  71.  
  72. void chercher(const HachageSTL & table, const string & clef, bool & trouve, string & information)
  73. {
  74.      trouve=false;
  75.      const int hash=hashCode(clef);
  76.      if(clefPresente(table, clef)==true)
  77.      {
  78.          if(table.donnee[hash].unePersonne.prenom==clef)
  79.          {
  80.              information=table.donnee[hash].unePersonne.information;
  81.          }
  82.          else
  83.          {
  84.             list<PersonneSimple>::const_iterator it;
  85.             it=table.donnee[hash].listeCollisions.begin();
  86.              while(it!=table.donnee[hash].listeCollisions.end())
  87.              {
  88.                 PersonneSimple Buffer=*it;
  89.                 if(Buffer.prenom==clef)
  90.                 {
  91.                     information=Buffer.information;
  92.                 }
  93.              }
  94.          }
  95.      }
  96. }
  97.  
  98. void inserer(HachageSTL & table, const string & clef, const string & info) throw (logic_error)
  99. {
  100.     const int hash=hashCode(clef);
  101.      if(clefPresente(table, clef)==true)
  102.      {
  103.          string error="Cle deja presente" + clef;
  104.          throw logic_error(error);
  105.      }
  106.      else
  107.      {
  108.          if(table.donnee[hash].libre==true)
  109.          {
  110.              table.donnee[hash].unePersonne.prenom=clef;
  111.              table.donnee[hash].unePersonne.information=info;
  112.              table.donnee[hash].libre=false;
  113.          }
  114.          else
  115.          {
  116.              PersonneSimple buffer;
  117.              buffer.prenom=clef;
  118.              buffer.information=info;
  119.              table.donnee[hash].listeCollisions.push_back(buffer);
  120.          }
  121.      }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement