Beispiel #1
0
void	run_sort_algorithms(t_info *info)
{
	t_algo	*best;
	t_algo	*b_sort;
	t_algo	*s_sort;
	t_algo	*d_sort;

	b_sort = new_algo(info);
	s_sort = new_algo(info);
	d_sort = new_algo(info);
	info->in_count = dumb_sort(d_sort, info);
	compress_ops(d_sort->operations, &info->in_count);
	best = d_sort;
	bubble_sort(b_sort, info);
	compress_ops(b_sort->operations, &b_sort->op_count);
	if (b_sort->op_count < best->op_count && stack_sorted(b_sort->stack_a))
		best = b_sort;
	split_sort(s_sort, info);
	print_stacks(s_sort->stack_a, s_sort->stack_b, info);
	print_steps(s_sort->operations);
	compress_ops(s_sort->operations, &s_sort->op_count);
	if (s_sort->op_count < best->op_count && stack_sorted(s_sort->stack_a))
		best = s_sort;
	run_test2(best, info);
	delete_algo(&b_sort);
	delete_algo(&s_sort);
	delete_algo(&d_sort);
}
Beispiel #2
0
int main(int argc, char **argv)
{
	struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
	char filename[256];
	int delay = 1;

	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
	setrlimit(RLIMIT_MEMLOCK, &r);

	signal(SIGINT, int_exit);

	if (load_kallsyms()) {
		printf("failed to process /proc/kallsyms\n");
		return 2;
	}

	if (load_bpf_file(filename)) {
		printf("%s", bpf_log_buf);
		return 1;
	}

	if (argc > 1)
		delay = atoi(argv[1]);
	sleep(delay);
	print_stacks(map_fd[0]);

	return 0;
}
Beispiel #3
0
int main(int, char**)
{

   diskStack stacks[STACK_COUNT];
   
   init_stacks(stacks);
   
   std::cout << "Init: \n";
   print_stacks(stacks);
   
   std::cout << std::endl;
   move_disks(stacks,DISK_MAX , 0, 1, 2);
   std::cout << std::endl<< "Final: " << std::endl;

   print_stacks(stacks);


   return 0;
}
Beispiel #4
0
static void		init_imode(t_ps *ps)
{
	push_stack(ps);
	if (OPT(OPT_GRAPHIC))
		mlx_redraw(ps, "WELCOME");
	ft_putendl("\033[33m::Interactive mode::\033[0m");
	if (OPT(OPT_VERBOSE))
		print_stacks(ps);
	print_prompt();
}
Beispiel #5
0
static void	handle_opts(t_stack *a, t_stack *b, char *s)
{
	if (!g_interactive_opt)
	{
		ft_printf("%s", s);
		if (!is_sort(a) || !empty(b))
			ft_printf(" ");
		else
			ft_printf("\n");
	}
	if (g_count_opt >= 0)
		g_count_opt++;
	if (!g_interactive_opt && g_v_opt)
		print_stacks(a, b);
}
Beispiel #6
0
void	sort_stack(t_stack *a, t_stack *b)
{
	int		min_max[2];

	if (g_v_opt)
		print_stacks(a, b);
	check_bottom(a, b);
	while (!check_top(a, b) || !check_last_push(a, b) || !empty(b))
	{
		if (get_min_max(a, min_max, min_max + 1) == 1)
			rot_to_min(a, b, min_max, 0);
		else
			rot_to_min(a, b, min_max, 1);
	}
}
Beispiel #7
0
static void test_perf_event_task(struct perf_event_attr *attr)
{
	int pmu_fd;

	/* open task bound event */
	pmu_fd = sys_perf_event_open(attr, 0, -1, -1, 0);
	if (pmu_fd < 0) {
		printf("sys_perf_event_open failed\n");
		return;
	}
	assert(ioctl(pmu_fd, PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0);
	assert(ioctl(pmu_fd, PERF_EVENT_IOC_ENABLE, 0) == 0);
	system("dd if=/dev/zero of=/dev/null count=5000k");
	print_stacks();
	close(pmu_fd);
}
Beispiel #8
0
static void		print_op(t_ps *ps, int op)
{
	if (OPT(OPT_EXEC))
	{
		if (OPT(OPT_VERBOSE))
		{
			if (!(OPT(OPT_INTERACTIVE)))
				ft_putendl(g_ops[op].name);
			print_stacks(ps);
		}
		else if (!OPT(OPT_INTERACTIVE) && !(OPT(OPT_GRAPHIC)))
			ft_printf("%s ", g_ops[op].name);
		if (OPT(OPT_GRAPHIC))
		{
			if ((G_MODE(0)
			|| (G_MODE(1) && !(ps->total_ops % (ps->total_elem / 30 + 1)))
			|| (G_MODE(2) && CURR_VAL(FIRST(ps->stack_a)) == ps->range_min)))
				mlx_redraw(ps, g_ops[op].name);
		}
	}
}
Beispiel #9
0
static void test_perf_event_all_cpu(struct perf_event_attr *attr)
{
	int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
	int *pmu_fd = malloc(nr_cpus * sizeof(int));
	int i;

	/* open perf_event on all cpus */
	for (i = 0; i < nr_cpus; i++) {
		pmu_fd[i] = sys_perf_event_open(attr, -1, i, -1, 0);
		if (pmu_fd[i] < 0) {
			printf("sys_perf_event_open failed\n");
			goto all_cpu_err;
		}
		assert(ioctl(pmu_fd[i], PERF_EVENT_IOC_SET_BPF, prog_fd[0]) == 0);
		assert(ioctl(pmu_fd[i], PERF_EVENT_IOC_ENABLE, 0) == 0);
	}
	system("dd if=/dev/zero of=/dev/null count=5000k");
	print_stacks();
all_cpu_err:
	for (i--; i >= 0; i--)
		close(pmu_fd[i]);
	free(pmu_fd);
}
Beispiel #10
0
int main( int argc, char ** argv )
{
  stk f, s, t;
  int i;

  if( argc == 2 )
    n = atoi(argv[1]);
  else
    n = 3;

  init_stack( &f );
  init_stack( &s );
  init_stack( &t );

  for( i = n; i > 0; --i )
    push( &f, i );

#ifdef __DEBUG__
  printf("\n");
  p( f, s, t ); 
#endif 

  i = 0;
  while( ( !is_empty( f ) || !is_empty( s ) ) )
    {
      i++; // counter to keep from inf loops
      int moved;
      if( ( moved = move( &f, &s ) ) > 0 )
	{
#ifdef __DEBUG__
	  printf("moved %d first to second\n", moved );
#endif
	}
      else if( ( moved = move( &f, &t ) ) > 0 )
	{
#ifdef __DEBUG__
	  printf("moved %d first to third\n", moved );
#endif
	}
      else if( ( moved = move( &s, &t ) ) > 0 )
	{
#ifdef __DEBUG__
	  printf("moved %d second to third\n", moved );
#endif
	}
      else if( ( moved = move( &t, &f ) ) > 0 )
	{
#ifdef __DEBUG__
	  printf("moved %d third to first\n", moved );
#endif
	}
      else if( ( moved = move( &t, &s ) ) > 0 )
	{
#ifdef __DEBUG__
	  printf("moved %d third to second\n", moved );
#endif
	}
      else if( ( moved = move( &s, &f ) ) > 0 )
	{
#ifdef __DEBUG__
	  printf("moved %d second to first\n", moved );
#endif
	}
      else
	{
#ifdef __DEBUG__
	printf("NOP\n");
#endif
	}

      last_moved = moved;
      p( f, s, t );
    }
  

  print_stacks( f, s, t );

  printf("\n\nTook %d moves\n", i );
  return 0;
}
Beispiel #11
0
static void int_exit(int sig)
{
	print_stacks(map_fd[0]);
	exit(0);
}