From 5b0b83e4352bdb2a9c0fcb78e43eddfd78ea168a Mon Sep 17 00:00:00 2001 From: klmp200 Date: Wed, 20 Jun 2018 17:46:14 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Fonction=20contains,=20j'ai=20pas=20test?= =?UTF-8?q?=C3=A9=20lol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- List/List.c | 23 ++++++++++++++++++++++- List/List.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/List/List.c b/List/List.c index b4553da..2f22f1d 100644 --- a/List/List.c +++ b/List/List.c @@ -140,6 +140,26 @@ void insert_inside_List(THIS(List), void * data, size_t data_size, int index){ } +/** + * Check if data_to_find exist in list + * @param this THIS(List) + * @param data_to_find pointer to data you want to find inside + * @param compare a compare function, return true or false and takes two void * pointers + * @return true or false if the element is within the list or not + */ +int contains_List(THIS(List), void * data_to_find, int (*compare)(void *, void *)){ + Element * current = this->head; + + while (current != NULL){ + if (compare(data_to_find, current->data)){ + return 1; + } + current = current->next; + } + + return 0; +} + void remove_head_List(THIS(List)){ DELETE(this->head); } @@ -170,7 +190,8 @@ List *_init_List(){ clear_custom, clear, remove_head, - remove_tail + remove_tail, + contains ) return l; } diff --git a/List/List.h b/List/List.h index 6af0f0d..0c9511b 100644 --- a/List/List.h +++ b/List/List.h @@ -29,6 +29,7 @@ struct o_List { PUBLIC void* (*get_element_data)(_THIS(List), int index); PUBLIC int (*get_size)(_THIS(List)); + PUBLIC int (*contains)(_THIS(List), void * data_to_find, int (*compare)(void *, void *)); PUBLIC void (*set_custom_free)(_THIS(List), void (*custom_free)(void *)); PUBLIC void (*insert_inside)(_THIS(List), void * data, size_t data_size, int index); From 4f1179bcbebc80e7d23ea1c87aa9a9f1d26d5fdb Mon Sep 17 00:00:00 2001 From: klmp200 Date: Wed, 20 Jun 2018 17:46:14 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Fonction=20contains,=20j'ai=20pas=20test?= =?UTF-8?q?=C3=A9=20lol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- List/List.c | 23 ++++++++++++++++++++++- List/List.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/List/List.c b/List/List.c index b4553da..2f22f1d 100644 --- a/List/List.c +++ b/List/List.c @@ -140,6 +140,26 @@ void insert_inside_List(THIS(List), void * data, size_t data_size, int index){ } +/** + * Check if data_to_find exist in list + * @param this THIS(List) + * @param data_to_find pointer to data you want to find inside + * @param compare a compare function, return true or false and takes two void * pointers + * @return true or false if the element is within the list or not + */ +int contains_List(THIS(List), void * data_to_find, int (*compare)(void *, void *)){ + Element * current = this->head; + + while (current != NULL){ + if (compare(data_to_find, current->data)){ + return 1; + } + current = current->next; + } + + return 0; +} + void remove_head_List(THIS(List)){ DELETE(this->head); } @@ -170,7 +190,8 @@ List *_init_List(){ clear_custom, clear, remove_head, - remove_tail + remove_tail, + contains ) return l; } diff --git a/List/List.h b/List/List.h index 6af0f0d..0c9511b 100644 --- a/List/List.h +++ b/List/List.h @@ -29,6 +29,7 @@ struct o_List { PUBLIC void* (*get_element_data)(_THIS(List), int index); PUBLIC int (*get_size)(_THIS(List)); + PUBLIC int (*contains)(_THIS(List), void * data_to_find, int (*compare)(void *, void *)); PUBLIC void (*set_custom_free)(_THIS(List), void (*custom_free)(void *)); PUBLIC void (*insert_inside)(_THIS(List), void * data, size_t data_size, int index); From 3dbdc47452fcbbead61cb041b90d9b735cc08fc8 Mon Sep 17 00:00:00 2001 From: Aethor Date: Wed, 20 Jun 2018 18:05:37 +0200 Subject: [PATCH 3/3] ~~ --- Building/Building.c | 3 ++- Visitor/Visitor.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Building/Building.c b/Building/Building.c index b2b3735..d859b2d 100644 --- a/Building/Building.c +++ b/Building/Building.c @@ -166,7 +166,8 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger if (origin < 0 || origin >= FLOORS) {CRASH("You are trying to start from a non existing floor\n");} if (destination < 0 || destination >= FLOORS) {CRASH("You are trying to reach a non existing floor\n");} - this->waiting_passengers->insert_tail(this->waiting_passengers, (void*) &passenger, sizeof(passenger)); + //if(this->waiting_passengers->compare(this->waiting_passengers, (void*) &passenger, passenger.compare)) + this->waiting_passengers->insert_tail(this->waiting_passengers, (void*) &passenger, sizeof(passenger));//todo : check if inside list pthread_cond_wait(this->condition_floors[origin], this->mutex_cond_get_inside_elevator); elevator_number = this->get_inside_elevator(this, origin, passenger); diff --git a/Visitor/Visitor.c b/Visitor/Visitor.c index 0cf4ccd..ce93c42 100644 --- a/Visitor/Visitor.c +++ b/Visitor/Visitor.c @@ -14,7 +14,7 @@ void * runnable_Visitor(void * void_this){ SharedData * data = GET_INSTANCE(SharedData); Passenger passenger; - AGENT_OPTIONS + AGENT_OPTIONS; passenger.visitor = this; passenger.type = VISITOR;