Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "HachageSTL.h"
- using namespace std;
- void initialiserHachageSTL(HachageSTL & table)
- {
- for(int i=0; i< table.donnee.size(); i++)
- {
- table.donnee[i].unePersonne.information=" ";
- table.donnee[i].unePersonne.prenom=" ";
- table.donnee[i].libre=true;
- list<PersonneSimple>::iterator it=table.donnee[i].listeCollisions.begin();
- while(it!=table.donnee[i].listeCollisions.end())
- {
- PersonneSimple Buffer=*it;
- Buffer.prenom=" ";
- Buffer.information=" ";
- it++;
- }
- }
- }
- void afficher(const HachageSTL & table)
- {
- for(int i=0; i< table.donnee.size(); i++)
- {
- cout << table.donnee[i].unePersonne.information << "\t" ;
- cout << table.donnee[i].unePersonne.prenom << "\t" ;
- cout << table.donnee[i].libre << "\t" << endl;
- list<PersonneSimple>::const_iterator it;
- it=table.donnee[i].listeCollisions.begin();
- while(it!=table.donnee[i].listeCollisions.end())
- {
- PersonneSimple Buffer=*it;
- cout << Buffer.prenom << "\t";
- cout << Buffer.information << "\t" <<endl;
- it++;
- }
- }
- }
- bool clefPresente(const HachageSTL & table, const string & clef)
- {
- const int hash=hashCode(clef);
- if(table.donnee[hash].libre==true)
- {
- return false;
- }
- else
- {
- if(table.donnee[hash].unePersonne.prenom==clef)
- {
- return true;
- }
- else
- {
- list<PersonneSimple>::const_iterator it;
- it=table.donnee[hash].listeCollisions.begin();
- while(it!=table.donnee[hash].listeCollisions.end())
- {
- PersonneSimple Buffer=*it;
- if(Buffer.prenom==clef)
- {
- return true;
- }
- }
- }
- }
- }
- void chercher(const HachageSTL & table, const string & clef, bool & trouve, string & information)
- {
- trouve=false;
- const int hash=hashCode(clef);
- if(clefPresente(table, clef)==true)
- {
- if(table.donnee[hash].unePersonne.prenom==clef)
- {
- information=table.donnee[hash].unePersonne.information;
- }
- else
- {
- list<PersonneSimple>::const_iterator it;
- it=table.donnee[hash].listeCollisions.begin();
- while(it!=table.donnee[hash].listeCollisions.end())
- {
- PersonneSimple Buffer=*it;
- if(Buffer.prenom==clef)
- {
- information=Buffer.information;
- }
- }
- }
- }
- }
- void inserer(HachageSTL & table, const string & clef, const string & info) throw (logic_error)
- {
- const int hash=hashCode(clef);
- if(clefPresente(table, clef)==true)
- {
- string error="Cle deja presente" + clef;
- throw logic_error(error);
- }
- else
- {
- if(table.donnee[hash].libre==true)
- {
- table.donnee[hash].unePersonne.prenom=clef;
- table.donnee[hash].unePersonne.information=info;
- table.donnee[hash].libre=false;
- }
- else
- {
- PersonneSimple buffer;
- buffer.prenom=clef;
- buffer.information=info;
- table.donnee[hash].listeCollisions.push_back(buffer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement