Skip to content

Commit

Permalink
optimize number_of_segments
Browse files Browse the repository at this point in the history
  • Loading branch information
rask24 committed Feb 12, 2024
1 parent bf3f021 commit 0d2c821
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/sort/large_sort/large_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 16:55:10 by reasuke #+# #+# */
/* Updated: 2024/02/12 20:54:48 by reasuke ### ########.fr */
/* Updated: 2024/02/12 23:57:46 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -15,10 +15,21 @@
#include "sort.h"
#include "stack_operations.h"

static void _push_b_n_times(t_stack **p_a, t_stack **p_b, int n)
// 0...200: 1
// 200...300: 3
// 300...400: 5
// 400...500: 7
// 450...550: 5
// 550...650: 6

static int _calc_number_of_segments(int size_a)
{
while (n--)
operate_pb(p_a, p_b);
int a;

if (size_a <= 200)
return (1);
a = (size_a - 200) / 100;
return (2 * a + 3);
}

static void _sort_stack_a(t_stack **p_a, int num_a)
Expand All @@ -42,10 +53,7 @@ void large_sort(t_stack **p_a, t_stack **p_b)

size_a = stack_size(*p_a);
size_b = size_a - 3;
if (size_a < 200)
_push_b_n_times(p_a, p_b, size_b);
else
push_b_segmented(p_a, p_b, size_b, 7);
push_b_segmented(p_a, p_b, size_b, _calc_number_of_segments(size_a));
nano_sort(p_a);
while (size_b--)
{
Expand Down

0 comments on commit 0d2c821

Please sign in to comment.