-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/01/10 12:37:54 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/09 23:10:54 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/09 23:13:42 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -37,6 +37,7 @@ typedef struct s_content | |
int sr_cost; | ||
int if_cost; | ||
int ir_cost; | ||
int min_cost; | ||
t_method opt_method; | ||
bool is_opt; | ||
} t_content; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: reasuke <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/02/09 10:23:28 by reasuke #+# #+# */ | ||
/* Updated: 2024/02/09 23:11:44 by reasuke ### ########.fr */ | ||
/* Updated: 2024/02/09 23:20:32 by reasuke ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -34,7 +34,19 @@ static int _calc_cost(t_stack *st_b, t_method method) | |
return (-1); | ||
} | ||
|
||
static void _set_opt_method(t_stack **p_b) | ||
static void _set_opt_method(t_stack *st_b, int *cost) | ||
{ | ||
if (ft_chmin(cost, _calc_cost(st_b, FF))) | ||
get_content(st_b)->opt_method = FF; | ||
if (ft_chmin(cost, _calc_cost(st_b, FR))) | ||
get_content(st_b)->opt_method = FR; | ||
if (ft_chmin(cost, _calc_cost(st_b, RF))) | ||
get_content(st_b)->opt_method = RF; | ||
if (ft_chmin(cost, _calc_cost(st_b, RR))) | ||
get_content(st_b)->opt_method = RR; | ||
} | ||
|
||
static void _set_min_cost_opt_method(t_stack **p_b) | ||
{ | ||
int i; | ||
int size_b; | ||
|
@@ -47,20 +59,14 @@ static void _set_opt_method(t_stack **p_b) | |
while (i < size_b) | ||
{ | ||
cost = INT_MAX; | ||
if (ft_chmin(&cost, _calc_cost(st_b, FF))) | ||
get_content(st_b)->opt_method = FF; | ||
if (ft_chmin(&cost, _calc_cost(st_b, FR))) | ||
get_content(st_b)->opt_method = FR; | ||
if (ft_chmin(&cost, _calc_cost(st_b, RF))) | ||
get_content(st_b)->opt_method = RF; | ||
if (ft_chmin(&cost, _calc_cost(st_b, RR))) | ||
get_content(st_b)->opt_method = RR; | ||
_set_opt_method(st_b, &cost); | ||
get_content(st_b)->min_cost = cost; | ||
st_b = st_b->next; | ||
i++; | ||
} | ||
} | ||
|
||
void set_opt(t_stack **p_b) | ||
{ | ||
_set_opt_method(p_b); | ||
_set_min_cost_opt_method(p_b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters