Esempio n. 1
0
Arbre* equilibrer(Arbre *a) {
	afficherArbre(a);
	printf("\n");

	if (a != NULL) {
		a->g = equilibrer(a->g);
		a->d = equilibrer(a->d);

		if (hauteur_max(a->g) > (hauteur_max(a->d) + 1)) {
			a = rotd(a);
		} else if (hauteur_max(a->d) > (hauteur_max(a->g) + 1)) {
			a = rotg(a);
		}

		/*if (abs(hauteur_max(a->g) - hauteur_max(a->d)) > 1) {
				a = equilibrer(a);
			}*/
	}



	return a;

}
Esempio n. 2
0
int main(int argc, char ** argv){
  struct timeval start, end;
  Liste * fichiers = fichiers_reguliers(SHAKESPEARE_DIR);
  Liste * mots;
  char * fichier;
  TrieHybride * t = NULL;
  int i,fd,fd2,arg_fusion,res;
  double res_d;
  char buff[128];
  pthread_t tid[NB_THREADS];
  pthread_attr_t attr; 
  briandais_t * br;

  /****************************************************************************
                      BENCHMARK INSERTION NON MULTITHREADE
  ****************************************************************************/
  printf("Insertion de toutes les pieces de Shakespeare \t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  while((fichier=supprimer_debut(fichiers))){
    t=lire_fichier_th(fichier,t);
    free(fichier);
  }
  temps(&end);
  afficher_res(start,end);
  destroy_liste(fichiers);

  /****************************************************************************
                          SUPPRESSION MOTS HAMLET
  ****************************************************************************/
  printf("Suppression des mots de la piece \"Hamlet\" \t\t: En cours ...");  
  fflush(stdout);

  fd=ouvrir_fichier(SHAKESPEARE_DIR"hamlet.txt");
  if(fd<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  temps(&start);
  while(mot_suivant(fd,buff)>0){
    t=supprimer(t,buff);
  }
  temps(&end);
  afficher_res(start,end);

  if(close(fd)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  }

  /****************************************************************************
                         RECHERCHE ALL'S WELL & HAMLET
  ****************************************************************************/
  printf("Recherche des mots de All's Well et Hamlet \t\t: En cours ...");  
  fflush(stdout);

  fd=ouvrir_fichier(SHAKESPEARE_DIR"hamlet.txt");
  if(fd<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  fd2=ouvrir_fichier(SHAKESPEARE_DIR"allswell.txt");
  if(fd2<0){
    perror("ouverture fichier");
    exit(EXIT_FAILURE);
  }

  temps(&start);
  while(mot_suivant(fd,buff)>0){
    recherche_trie_hybride(t,buff);
  } 
  while(mot_suivant(fd2,buff)>0){
    recherche_trie_hybride(t,buff);
  }
  temps(&end);

  afficher_res(start,end);
  if(close(fd)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  } 

  if(close(fd2)==-1){
    perror("close");
    exit(EXIT_FAILURE);
  }

  /****************************************************************************
                        DESTRUCTION TRIE HYBRIDE
  ****************************************************************************/
  printf("Destruction du trie hybride \t\t\t\t: En cours ...");  
  fflush(stdout);

  temps(&start);
  free_trie_hybride(t);
  temps(&end);

  afficher_res(start,end);

  /****************************************************************************
                       CREATION SHAKESPEARE MULTITHREADE
  ****************************************************************************/
  fics=fichiers_reguliers(SHAKESPEARE_DIR);
  tries=creer_liste();
  sem_init(&sem,1,0);
  arg_fusion=fics->taille;  
  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);

  printf("Insertion multithreade des oeuvres de Shakespeare\t: En cours ...");  
  fflush(stdout);


  temps(&start);
  pthread_mutex_lock(&mutex_fics);
  for(i=0;i<NB_THREADS-1;i++){
    if(pthread_create(&(tid[i]),&attr,creation_trie_thread,NULL)==-1){
      perror("pthread_create");
      exit(EXIT_FAILURE);
    }
  }
  
  if(pthread_create(&(tid[NB_THREADS-1]),&attr,fusion_thread,&arg_fusion)==-1){
    perror("pthread_create");
    exit(EXIT_FAILURE);
  }

  pthread_cond_wait(&cond,&mutex_fics);
  temps(&end);

  afficher_res(start,end);

  destroy_liste(fics);
  t=supprimer_debut(tries);
  destroy_liste(tries);

 /****************************************************************************
                                COMPTAGE MOTS
  ****************************************************************************/
  printf("Comptage des mots \t\t\t\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  res=comptage_mots(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                              POINTEURS VERS NULL
  ****************************************************************************/ 
  printf("Comptage des pointeurs vers NULL\t\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  res=comptage_nil(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                 CREATION ET DESTRUCTION DE LA LISTE DES MOTS
  ****************************************************************************/ 
  printf("Creation et destruction de la liste des mots\t\t: En cours ...");
  fflush(stdout);

  temps(&start);
  mots=liste_mots(t);
  while(mots->taille!=0){
    char * tmp=supprimer_debut(mots);
    free(tmp);
  }
  free(mots);
  temps(&end);
  afficher_res(start,end);

  /****************************************************************************
                                   HAUTEUR
  ****************************************************************************/
  printf("Calcul de la hauteur \t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=hauteur(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);


  /****************************************************************************
                                 EQUILIBRAGE
  ****************************************************************************/
  printf("Equilibrage du trie\t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  t=equilibrer(t);
  temps(&end);
  afficher_res(start,end);

  /****************************************************************************
                              RECALCUL HAUTEUR
  ****************************************************************************/
  printf("Recalcul de la hauteur \t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=hauteur(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  /****************************************************************************
                             PROFONDEUR MOYENNE
  ****************************************************************************/
  printf("Profondeur Moyenne\t\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res_d=profondeur_moyenne(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %f\n",res_d);

  /****************************************************************************
                          CONVERSION VERS BRIANDAIS
  ****************************************************************************/
  printf("Conversion vers arbre de la briandais\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  br=conversion(t);
  temps(&end);
  afficher_res(start,end);
  destroy_briandais(&br);

  /****************************************************************************
                        INSERTION D'UN MOT INEXISTANT
  ****************************************************************************/
  printf("Insertion d'un mot inexistant(anticonstitutionnellement): En cours ...");
  fflush(stdout);
  temps(&start);
  t=ajouter_trie_hybride("anticonstitutionnellement",t);
  temps(&end);
  afficher_res(start,end);
 
 /****************************************************************************
                        INSERTION D'UN MOT INEXISTANT
  ****************************************************************************/
  printf("Usage memoire (en octets)\t\t\t\t: En cours ...");
  fflush(stdout);
  temps(&start);
  res=usage_memoire(t);
  temps(&end);
  afficher_res(start,end);
  printf("\t\t\t\t\t\t\t  %d\n",res);

  free_trie_hybride(t);
  return EXIT_SUCCESS;
}