merging ralentit branch

This commit is contained in:
Hugo LAMY
2019-06-01 14:08:35 +02:00
6 changed files with 59 additions and 25 deletions

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* bonus.c :+: :+: :+: */ /* f_bonus_opti.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */ /* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */ /* Created: 2019/06/01 14:06:37 by hulamy #+# #+# */
/* Updated: 2019/06/01 12:31:29 by hulamy ### ########.fr */ /* Updated: 2019/06/01 14:06:40 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -25,7 +25,6 @@ int check_tetri_memory(t_fillist *list, int pos)
mask = 1 << ((pos % 32) - 1); mask = 1 << ((pos % 32) - 1);
if (tetri->same) if (tetri->same)
{ {
// ft_putstr("tetri->same->memory"); ft_putstr((char *)tetri->same->memory); ft_putstr(" -- "); ft_putnbrendl(pos / 32);
if (!(tetri->same->memory[pos / 32] & mask)) if (!(tetri->same->memory[pos / 32] & mask))
return (tetri->same->memory[pos / 32] |= mask); return (tetri->same->memory[pos / 32] |= mask);
} }
@@ -52,6 +51,21 @@ int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b)
return (1); return (1);
} }
/*
** Function that free the list->memory each time it's malloc
*/
t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp)
{
while (tmp)
{
if (tmp->memory)
free(tmp->memory);
tmp = tmp->next;
}
return (list);
}
/* /*
** Test optimisation for not testing wrong maps when tetri are identical ** Test optimisation for not testing wrong maps when tetri are identical
*/ */
@@ -62,7 +76,7 @@ int check_same_tetri(t_fillist *list, int num)
t_fillist *next_tetri; t_fillist *next_tetri;
int i; int i;
curr_tetri = list; curr_tetri = clean_list_memory(list, list);
while (curr_tetri != NULL) while (curr_tetri != NULL)
{ {
i = 0; i = 0;

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
/* Updated: 2019/05/29 19:08:15 by hulamy ### ########.fr */ /* Updated: 2019/06/01 14:06:07 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */ /* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */ /* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
/* Updated: 2019/05/29 19:10:33 by hulamy ### ########.fr */ /* Updated: 2019/06/01 14:05:45 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -98,8 +98,8 @@ void print_letter_map(t_fillist *list, int size, int flag)
ft_putchar(' '); ft_putchar(' ');
} }
} }
free(map);
ft_putchar('\n'); ft_putchar('\n');
free(map);
} }
/* /*

View File

@@ -6,7 +6,7 @@
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */ /* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */ /* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/05/29 18:28:04 by hulamy ### ########.fr */ /* Updated: 2019/06/01 14:04:53 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 12:27:09 by hulamy ### ########.fr */ /* Updated: 2019/06/01 14:03:45 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -48,20 +48,20 @@
/* /*
** STRUCTURE ** STRUCTURE
** tetribit : tetri ecrit en binaire dans un short de 16 bits ** tetribit : tetri ecrit en binaire dans un short de 16 bits
** width : largeur du tetri ** width : largeur du tetri
** height : hauteur du tetri ** height : hauteur du tetri
** position : memorise la position d tetri bit a bit ** position : memorise la position d tetri bit a bit
** place : position sur l'axe des abscisses de la map (position % size) ** place : position sur l'axe des abscisses de la map (position % size)
** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32) ** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32)
** num : memorise dans quel int du tableau on se trouve (position / 32) ** num : memorise dans quel int du tableau on se trouve (position / 32)
** test : to print the tetri during the backtracking, test is a boolean ** test : to print the tetri during the backtracking, test is a boolean
** letter : letter of the tetrimino for printing final map ** letter : letter of the tetrimino for printing final map
** dope : flags for details, optimisation, printing and error ** dope : flags for details, optimisation, printing and error
** memory : positions already tested by a tetrimino in bitwise ** memory : positions already tested by a tetrimino in bitwise
** same : pointer to previous identical tetrimino ** same : pointer to previous identical tetrimino
** next : pointer to next tetrimino ** next : pointer to next tetrimino
** start : pointer to first tetrimino of input file ** start : pointer to first tetrimino of input file
*/ */
typedef struct s_fillist typedef struct s_fillist
{ {
@@ -94,6 +94,7 @@ int print_flags_usage(void);
*/ */
int check_tetri_memory(t_fillist *list, int pos); int check_tetri_memory(t_fillist *list, int pos);
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b); int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b);
t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp);
int check_same_tetri(t_fillist *list, int num); int check_same_tetri(t_fillist *list, int num);
/* /*
@@ -101,6 +102,7 @@ int check_same_tetri(t_fillist *list, int num);
*/ */
int main(int argc, char **argv); int main(int argc, char **argv);
int *create_dope(char *av, int mdp); int *create_dope(char *av, int mdp);
void clean_list(t_fillist *list, t_fillist *tmp);
int is_mdp(int ac, char **av); int is_mdp(int ac, char **av);
/* /*

20
main.c
View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */ /* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
/* Updated: 2019/05/29 19:09:11 by hulamy ### ########.fr */ /* Updated: 2019/06/01 13:58:49 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -66,6 +66,22 @@ int is_mdp(int ac, char **av)
return (1); return (1);
} }
/*
** Function that free the list
*/
void clean_list(t_fillist *list, t_fillist *tmp)
{
tmp = list;
while (list)
{
list = tmp->next;
free(tmp->memory);
free(tmp);
tmp = list;
}
}
/* /*
** Main function ** Main function
*/ */
@@ -88,8 +104,10 @@ int main(int ac, char **av)
size = parse_input(input, &list, dope); size = parse_input(input, &list, dope);
print_final_map(list, size); print_final_map(list, size);
free(input); free(input);
clean_list(list, list);
} }
else else
print_error("usage: Please submit a file.\n> ./fillit file.fillit\n"); print_error("usage: Please submit a file.\n> ./fillit file.fillit\n");
free(dope);
return (0); return (0);
} }