2 Commits

Author SHA1 Message Date
lucas 3e924de64f Téléverser les fichiers vers "/" 2026-05-11 15:58:43 +00:00
lucas 485d289e95 correction null toolbox.c 2026-04-13 00:38:39 +02:00
3 changed files with 3487 additions and 3 deletions
File diff suppressed because one or more lines are too long
BIN
View File
Binary file not shown.
+13 -3
View File
@@ -5,8 +5,11 @@
#include <stdlib.h> #include <stdlib.h>
struct array *sort(struct array *arr, comparator f) struct array *sort(struct array *arr, comparator f)
{ {
if(!arr || !f) return NULL;
void *temp = malloc(arr->elem_size); void *temp = malloc(arr->elem_size);
if(!temp) return NULL;
if (arr->len > 0) { if (arr->len > 0) {
for(size_t index1 = 0; index1 < arr->len - 1; index1 ++ ){ for(size_t index1 = 0; index1 < arr->len - 1; index1 ++ ){
@@ -30,7 +33,9 @@ struct array *sort(struct array *arr, comparator f)
} }
struct array *map(struct array *arr, size_t output_size, mapper f) struct array *map(struct array *arr, size_t output_size, mapper f)
{ {
if(!arr || !f)return NULL;
void *data = calloc(arr->len, output_size); void *data = calloc(arr->len, output_size);
if(!data) return NULL; if(!data) return NULL;
@@ -52,6 +57,8 @@ struct array *map(struct array *arr, size_t output_size, mapper f)
struct array *filter(struct array *arr, predicate f) struct array *filter(struct array *arr, predicate f)
{ {
if(!arr || !f) return NULL;
size_t index = 0; size_t index = 0;
int flon = 0; int flon = 0;
while(index != arr->len){ while(index != arr->len){
@@ -66,8 +73,8 @@ struct array *filter(struct array *arr, predicate f)
index = 0; index = 0;
void *data1 = calloc(flon, arr->elem_size); void *data1 = calloc(flon, arr->elem_size);
if(!data1 && flon > 0) return NULL; if(!data1 && flon > 0) return NULL;
size_t index2 = 0; size_t index2 = 0;
while(index != arr->len){ while(index != arr->len){
void *cur = arr->data + index * arr->elem_size; void *cur = arr->data + index * arr->elem_size;
@@ -88,6 +95,8 @@ struct array *filter(struct array *arr, predicate f)
void *reduce(struct array *arr, void *start_value, reducer f) void *reduce(struct array *arr, void *start_value, reducer f)
{ {
if(!arr || !start_value || !f) return NULL;
void *rslt = start_value; void *rslt = start_value;
size_t index = 0; size_t index = 0;
@@ -103,6 +112,7 @@ void *reduce(struct array *arr, void *start_value, reducer f)
void foreach(struct array *arr, acceptor f) void foreach(struct array *arr, acceptor f)
{ {
if(!arr || !f) return;
// arr.data est un array de x valeurs // arr.data est un array de x valeurs
size_t index = 0; size_t index = 0;