add the table for the time search

This commit is contained in:
2023-06-12 15:29:58 +02:00
parent e6114096d4
commit 6167f5d84d
4 changed files with 95 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
#define NUMBER_OF_CHAR 100
#define LENGTH 12600
#include "Filmotheque.h"
@@ -29,7 +30,6 @@ void addMovie(struct Filmotheque* filmotheque, char* real, char* movie, char* ti
}
node = node->children[27];
}
//If the character is a space, we put the node in the 28th case of the array
else if (real[i] == ' ') {
if (node->children[28] == NULL) {
node->children[28] = createEmptyNodeTrie();
@@ -139,4 +139,67 @@ char* toLower(char* name) {
}
lower[length] = '\0';
return lower;
}
int stopServer(){
return 8;
}
struct List* createTable(char* nameFile){
FILE* fichier;
fichier = fopen(nameFile, "r");
if (fichier == NULL) {
printf("Erreur lors de l'ouverture du fichier");
exit(1);
}
char* real = malloc(sizeof(char));
if (real == NULL) {
printf("error malloc");
return NULL;
}
char* movie = malloc(sizeof(char));
if (movie == NULL) {
printf("error malloc");
return NULL;
}
char* time = malloc(sizeof(char));
if (time == NULL) {
printf("error malloc");
return NULL;
}
char* category = malloc(sizeof(char));
if (category == NULL) {
printf("error malloc");
return NULL;
}
char line[NUMBER_OF_CHAR];
struct List* tableau[LENGTH];
for(int i = 0; i < LENGTH; i++){
tableau[i] = NULL;
}
while(fgets(line,sizeof(line),fichier) != NULL){
line[strcspn(line, "\r\n")] = '\0';
real = toLower((strtok(line, ";")));
movie = strtok(NULL, ";");
time = strtok(NULL, ";");
category = strtok(NULL, ";");
addMovieInTable(tableau,real,movie,time,category);
}
fclose(fichier);
return tableau;
}
void addMovieInTable(struct List** tableau, char* real, char* movie, char* time, char* category){
int index = atoi(time);
if(tableau[index] == NULL){
tableau[index] = createEmptyList();
}
addFirst(tableau[index],real,movie,time,category);
}

View File

@@ -1,7 +1,7 @@
#ifndef PROJETCGROUPE8_MAIN_FILMOTHEQUE_H
#define PROJETCGROUPE8_MAIN_FILMOTHEQUE_H
#define NUMBER_OF_CHAR 100
#define LENGTH 12600
#include "NodeTrie.h"
#include <stdbool.h>
@@ -21,5 +21,7 @@ struct List* searchByDirector(struct Filmotheque* filmotheque, char* director);
void deleteFilmotheque(struct Filmotheque** filmotheque);
struct Filmotheque* recupInfo(char* nameFile);
char* toLower(char* name);
struct List* createTable(char* nameFile);
void addMovieInTable(struct List** tableau, char* real, char* movie, char* time, char* category);
#endif //PROJETCGROUPE8_MAIN_FILMOTHEQUE_H

View File

@@ -46,6 +46,9 @@ void addFirst(struct List* l, char* director, char* name, char* time, char* cate
}
bool isListEmpty(struct List* l){
if(l == NULL){
return true;
}
return l->size == 0;
}
@@ -67,6 +70,10 @@ void deleteList(struct List** l){
}
void printList(struct List* l){
if(isListEmpty(l)){
printf("List is empty\n");
return;
}
struct Cell* tmp = l->head;
while(tmp != NULL){
printf("%s %s %s %s\n", tmp->director, tmp->name, tmp->time, tmp->category);

View File

@@ -5,15 +5,36 @@
#include "List.h"
#include "Filmotheque.h"
#include <time.h>
int main() {
struct Filmotheque* filmotheque2 = recupInfo("../BD_small.txt");
struct List* test3 = searchByDirector(filmotheque2, "fincher");
printList(test3);
printf("\n");
struct List* test1456 = searchByDirector(filmotheque2, "johnson");
printList(test1456);
deleteList(&test1456);
deleteList(&test3);
struct List* test7854 = createTable("../BD_small.txt");
printList(test7854);
deleteFilmotheque(&filmotheque2);
/*
clock_t t2;
t2 = clock();
struct Filmotheque* filmotheque = recupInfo("../BD_big.txt");
t2 = clock() - t2;
double time_taken2 = ((double)t2)/CLOCKS_PER_SEC;
clock_t t;
t = clock();
struct List* test = searchByDirector(filmotheque, "leonard");
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC;
printList(test);
deleteList(&test);
deleteFilmotheque(&filmotheque);
printf("recupInfo() took %f seconds to execute \n", time_taken2);
printf("searchByDirector() took %f seconds to execute \n", time_taken);
*/
return 0;
}