Skip to content

Commit

Permalink
implement header modularization
Browse files Browse the repository at this point in the history
  • Loading branch information
rask24 committed Feb 11, 2024
1 parent e0b1c3a commit 6594307
Show file tree
Hide file tree
Showing 29 changed files with 214 additions and 80 deletions.
22 changes: 22 additions & 0 deletions include/initialization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* initialization.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 12:30:37 by reasuke #+# #+# */
/* Updated: 2024/02/11 12:33:50 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef INITIALIZATION_H
# define INITIALIZATION_H

# include "push_swap.h"

int check_args(int argc, char **argv);
t_stack *generate_stack(int argc, char **argv);
void exit_with_error(void);

#endif
23 changes: 23 additions & 0 deletions include/large_sort.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* large_sort.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 12:36:38 by reasuke #+# #+# */
/* Updated: 2024/02/11 12:37:50 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef LARGE_SORT_H
# define LARGE_SORT_H

# include "push_swap.h"

void large_sort(t_stack **p_a, t_stack **p_b);
void set_cost(t_stack **p_a, t_stack **p_b);
void set_opt(t_stack **p_b);
void greedy_operation(t_stack **p_a, t_stack **p_b);

#endif
68 changes: 3 additions & 65 deletions include/push_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,19 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 12:37:54 by reasuke #+# #+# */
/* Updated: 2024/02/10 21:18:02 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:58:12 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef PUSH_SWAP_H
# define PUSH_SWAP_H

# include "../libft/libft.h"
# include "types.h"
# include "utils.h"
# include <limits.h>
# include <stdbool.h>
# include <stdlib.h>
# include <unistd.h>

typedef t_list t_stack;

typedef enum e_method
{
INIT,
FF,
FR,
RF,
RR,
} t_method;

typedef struct s_content
{
int index;
int sf_cost;
int sr_cost;
int if_cost;
int ir_cost;
int min_cost;
t_method opt_method;
bool is_opt;
} t_content;

int check_args(int argc, char **argv);
t_stack *generate_stack(int argc, char **argv);
void exit_with_error(void);

void sort(t_stack **p_a, t_stack **p_b);
void nano_sort(t_stack **p_a);
void micro_sort(t_stack **p_a, t_stack **p_b);
void large_sort(t_stack **p_a, t_stack **p_b);
void set_cost(t_stack **p_a, t_stack **p_b);
void set_opt(t_stack **p_b);
void greedy_operation(t_stack **p_a, t_stack **p_b);
bool is_sorted_stack(t_stack *st);

void operate_sa(t_stack **p_a);
void operate_sb(t_stack **p_b);
void operate_ss(t_stack **p_a, t_stack **p_b);
void operate_ra(t_stack **p_a);
void operate_rb(t_stack **p_b);
void operate_rr(t_stack **p_a, t_stack **p_b);
void operate_rra(t_stack **p_a);
void operate_rrb(t_stack **p_a);
void operate_rrr(t_stack **p_a, t_stack **p_b);
void operate_pa(t_stack **p_b, t_stack **p_a);
void operate_pb(t_stack **p_a, t_stack **p_b);
void do_single_n_operations(t_stack **p_st, int n,
void (*operation)(t_stack **));
void do_double_n_operations(t_stack **p_a, t_stack **p_b, int n,
void (*operation)(t_stack **, t_stack **));

void push_stack(t_stack **p_s1, t_stack **p_s2);
void swap_stack(t_stack **p_stack);
void rotate_stack(t_stack **p_stack);
void reverse_rotate_stack(t_stack **p_stack);

void clear_stack(t_stack **p_stack, void (*del)(void *));
t_content *get_content(t_stack *st);
int get_first_index(t_stack **p_stack);
int get_second_index(t_stack **p_stack);
int get_third_index(t_stack **p_stack);
int stack_size(t_stack *stack);

#endif
24 changes: 24 additions & 0 deletions include/sort.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 12:42:03 by reasuke #+# #+# */
/* Updated: 2024/02/11 12:45:45 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef SORT_H
# define SORT_H

# include "push_swap.h"

void sort(t_stack **p_a, t_stack **p_b);
void nano_sort(t_stack **p_a);
void micro_sort(t_stack **p_a, t_stack **p_b);
void large_sort(t_stack **p_a, t_stack **p_b);
bool is_sorted_stack(t_stack *st);

#endif
39 changes: 39 additions & 0 deletions include/stack_operations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack_operations.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 12:41:01 by reasuke #+# #+# */
/* Updated: 2024/02/11 12:41:49 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef STACK_OPERATIONS_H
# define STACK_OPERATIONS_H

# include "push_swap.h"

void operate_sa(t_stack **p_a);

void operate_sb(t_stack **p_b);
void operate_ss(t_stack **p_a, t_stack **p_b);
void operate_ra(t_stack **p_a);
void operate_rb(t_stack **p_b);
void operate_rr(t_stack **p_a, t_stack **p_b);
void operate_rra(t_stack **p_a);
void operate_rrb(t_stack **p_a);
void operate_rrr(t_stack **p_a, t_stack **p_b);
void operate_pa(t_stack **p_b, t_stack **p_a);
void operate_pb(t_stack **p_a, t_stack **p_b);
void do_single_n_operations(t_stack **p_st, int n,
void (*operation)(t_stack **));
void do_double_n_operations(t_stack **p_a, t_stack **p_b, int n,
void (*operation)(t_stack **, t_stack **));

void push_stack(t_stack **p_s1, t_stack **p_s2);
void swap_stack(t_stack **p_stack);
void rotate_stack(t_stack **p_stack);
void reverse_rotate_stack(t_stack **p_stack);
#endif
38 changes: 38 additions & 0 deletions include/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* types.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 12:57:41 by reasuke #+# #+# */
/* Updated: 2024/02/11 12:58:04 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef TYPES_H
# define TYPES_H

typedef t_list t_stack;

typedef enum e_method
{
INIT,
FF,
FR,
RF,
RR,
} t_method;

typedef struct s_content
{
int index;
int sf_cost;
int sr_cost;
int if_cost;
int ir_cost;
int min_cost;
t_method opt_method;
bool is_opt;
} t_content;
#endif
25 changes: 25 additions & 0 deletions include/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 12:39:00 by reasuke #+# #+# */
/* Updated: 2024/02/11 12:39:47 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef UTILS_H
# define UTILS_H

# include "push_swap.h"

void clear_stack(t_stack **p_stack, void (*del)(void *));
t_content *get_content(t_stack *st);
int get_first_index(t_stack **p_stack);
int get_second_index(t_stack **p_stack);
int get_third_index(t_stack **p_stack);
int stack_size(t_stack *stack);

#endif
4 changes: 2 additions & 2 deletions src/initialization/check_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:44:55 by reasuke #+# #+# */
/* Updated: 2024/02/07 15:06:08 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:35:17 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "push_swap.h"
#include "initialization.h"

static bool _has_not_digit(int argc, char **argv)
{
Expand Down
4 changes: 2 additions & 2 deletions src/initialization/exit_with_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:38:17 by reasuke #+# #+# */
/* Updated: 2024/02/07 15:05:34 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:35:14 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "push_swap.h"
#include "initialization.h"

void exit_with_error(void)
{
Expand Down
4 changes: 2 additions & 2 deletions src/initialization/generate_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 19:04:40 by reasuke #+# #+# */
/* Updated: 2024/02/07 15:06:20 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:35:32 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "push_swap.h"
#include "initialization.h"

int *_generate_int_array(int array_size)
{
Expand Down
4 changes: 3 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 12:37:36 by reasuke #+# #+# */
/* Updated: 2024/02/10 21:19:08 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:54:10 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "initialization.h"
#include "push_swap.h"
#include "sort.h"

#ifdef LEAK
# ifdef __APPLE__
Expand Down
3 changes: 2 additions & 1 deletion src/sort/is_sorted_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/10 18:47:11 by reasuke #+# #+# */
/* Updated: 2024/02/10 19:12:48 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:54:04 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "push_swap.h"
#include "sort.h"

bool is_sorted_stack(t_stack *st)
{
Expand Down
4 changes: 3 additions & 1 deletion src/sort/large_sort/greedy_operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/10 10:43:16 by reasuke #+# #+# */
/* Updated: 2024/02/10 20:34:46 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:53:46 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "large_sort.h"
#include "push_swap.h"
#include "stack_operations.h"

static t_stack *_find_opt_st_b(t_stack **p_b)
{
Expand Down
5 changes: 4 additions & 1 deletion src/sort/large_sort/large_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 16:55:10 by reasuke #+# #+# */
/* Updated: 2024/02/10 21:24:58 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:53:49 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "large_sort.h"
#include "push_swap.h"
#include "sort.h"
#include "stack_operations.h"

static void _push_b_n_times(t_stack **p_a, t_stack **p_b, int n)
{
Expand Down
3 changes: 2 additions & 1 deletion src/sort/large_sort/set_cost.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/08 12:17:33 by reasuke #+# #+# */
/* Updated: 2024/02/08 21:47:27 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:53:50 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "large_sort.h"
#include "push_swap.h"

static int _calc_insertion_threshold(t_stack **p_a, t_stack *st_b)
Expand Down
3 changes: 2 additions & 1 deletion src/sort/large_sort/set_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
/* By: reasuke <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 10:23:28 by reasuke #+# #+# */
/* Updated: 2024/02/10 21:08:19 by reasuke ### ########.fr */
/* Updated: 2024/02/11 12:53:55 by reasuke ### ########.fr */
/* */
/* ************************************************************************** */

#include "large_sort.h"
#include "push_swap.h"

static int _calc_cost(t_stack *st_b, t_method method)
Expand Down
Loading

0 comments on commit 6594307

Please sign in to comment.