示例#1
0
static gboolean
stress_test_old_api (gpointer data)
{
  typedef enum {
    ADD_RANDOM,
    REMOVE_RANDOM,
    LAST_ACTION
  } Action;
      
  Info *info = data;
  Action action;
  
  if (info->counter++ == 200)
    {
      gtk_main_quit ();
      return FALSE;
    }

  if (!info->toolbar)
    {
      info->toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
      gtk_container_add (GTK_CONTAINER (info->window),
			 GTK_WIDGET (info->toolbar));
      gtk_widget_show (GTK_WIDGET (info->toolbar));
    }

  if (!info->toolbar->children)
    {
      add_random (info->toolbar, info->counter);
      return TRUE;
    }
  else if (g_list_length (info->toolbar->children) > 50)
    {
      int i;
      for (i = 0; i < 25; i++)
	remove_random (info->toolbar);
      return TRUE;
    }
  
  action = g_random_int_range (0, LAST_ACTION);

  switch (action)
    {
    case ADD_RANDOM:
      add_random (info->toolbar, info->counter);
      break;

    case REMOVE_RANDOM:
      remove_random (info->toolbar);
      break;
      
    default:
      g_assert_not_reached();
      break;
    }
  
  return TRUE;
}
示例#2
0
文件: map.cpp 项目: vkxdk/NoLifeStory
void init_random() {
    if (old_style) {
        for (auto n : map_node) { add_random(n); }
    } else {
        for (auto i = 0; i <= 9; ++i) {
            for (auto n : map_node["Map" + std::to_string(i)]) { add_random(n); }
        }
    }
    if (all_maps.empty()) { throw std::runtime_error{"No maps found!"}; }
}
示例#3
0
/*
 * Initialization:
 * - n = bit size
 * - add m random elements
 */
static void init_test_set(large_bvset_t *s, uint32_t n, uint32_t m) {
  uint32_t mask;

  init_large_bvset(s, n, 0);
  mask = (1<<n) - 1;
  add_random(s, m, mask);
}
示例#4
0
文件: i512_2.c 项目: chocht/2048
int			algo(t_data *data)
{
  if (data->key_func[data->index])
    data->key_func[data->index](data->key);
  if (play(data->grid, data->key) == 0)
    {
      data->key = -1;
      return (0);
    }
  del_rest_of_the_list(data);
  if (add_list(&data->list, data->grid))
    return (1);
  data->current = data->current->next;
  add_random(data->grid);
  blit_this(data);
  if (is_win(data->grid))
    {
      data->play = 0;
      return (0);
    }
  else if (is_lost(data->grid))
    {
      data->play = 0;
      return (0);
    }
  data->key = -1;
  return (0);
}
示例#5
0
文件: test.c 项目: CZinsane/libbloom
/** ***************************************************************************
 * main...
 *
 */
int main(int argc, char **argv)
{
  (void)printf("testing libbloom...\n");

  if (argc == 4 && !strncmp(argv[1], "-p", 2)) {
    perf_loop(atoi(argv[2]), atoi(argv[3]));
    exit(0);
  }

  basic();
  add_random(100, 0.001, 300);

  int i;
  for (i = 0; i < 10; i++) {
    add_random(1000000, 0.001, 1000000);
  }

  perf_loop(10000000, 10000000);
}
示例#6
0
int main(int argc, char *argv[])
{
	int retval = EXIT_FAILURE;
	int opt;
	int fd=-1;
	int val=0;
	int r;

	while ((opt = getopt(argc, argv, "h")) != -1) {
		switch (opt) {
		case 'h':
			usage();
			exit(EXIT_SUCCESS);
			break;
		default: /* '?' */
			usage();
			exit(EXIT_FAILURE);
		}
	}

	if (argc - optind < 1) {
		fprintf(stderr, "Missing action\n");
		usage();
		exit(EXIT_FAILURE);
	}
	const char *action = argv[optind];
	int action_argc = argc - optind;
	char **action_argv = &argv[optind];

	fd = open("/dev/urandom", O_RDWR);
	if (fd == -1) {
		perror("Failed to open /dev/urandom");
		exit(EXIT_FAILURE);
	}

	if (strcmp(action, "get_entropy_cnt") == 0) {
		retval = get_entropy_cnt(fd, action_argc, action_argv);
	} else if (strcmp(action, "add_entropy_cnt") == 0) {
		retval = add_entropy_cnt(fd, action_argc, action_argv);
	} else if (strcmp(action, "add_entropy") == 0) {
		retval = add_entropy(fd, action_argc, action_argv);
	} else if (strcmp(action, "add_random") == 0) {
		retval = add_random(fd, action_argc, action_argv);
	} else if (strcmp(action, "clear_pool") == 0) {
		retval = clear_pool(fd, action_argc, action_argv);
	} else {
		fprintf(stderr, "Unknown action: %s\n", action);
		usage();
		retval = EXIT_FAILURE;
	}

	close(fd);
	return retval;
}
示例#7
0
/*
 * Initialization:
 * - n = bit size
 * - add m random elements
 */
static void init_test_set(rb_bvset_t *s, uint32_t n, uint32_t m) {
  uint32_t mask;

  init_rb_bvset(s, n);
  if (n < 32) {
    mask = (1<<n) - 1;
  } else {
    mask = UINT32_MAX;
  }
  add_random(s, m, mask);
}
示例#8
0
/*
 * First test: size = 64
 */
static void test1(void) {
  uint32_t x;

  printf("\n"
	 "=================\n"
	 "     TEST 1\n"
	 "=================\n\n");

  // 50 initial elements
  init_test_set(&set, 6, 50);
  printf("=== Initial set: 50 additions ===\n");
  print_bvset(&set);
  printf("\n");

  do {
    x = large_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, set.nelems);
  } while (x != 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  reset_large_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  // 40 initial elements
  add_random(&set, 40, 63);
  printf("\n=== After 40 additions ===\n");
  print_bvset(&set);
  printf("\n");

  do {
    x = large_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, set.nelems);
  } while (x != 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");


  // empty initial set
  reset_large_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  do {
    x = large_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, set.nelems);
  } while (x != 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  delete_large_bvset(&set);
}
示例#9
0
/*
 * Size = 2048
 */
static void test3(void) {
  uint32_t x;

  printf("\n"
	 "=================\n"
	 "     TEST 3\n"
	 "=================\n\n");

  // 1000 initial additions
  init_test_set(&set, 11, 1000);
  printf("=== Initial set: 1000 additions ===\n");
  print_bvset(&set);
  printf("\n");

  do {
    x = large_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, set.nelems);
  } while (x != 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  reset_large_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  // 2000 initial additions
  add_random(&set, 2000, 2047);
  printf("\n=== After 2000 additions ===\n");
  print_bvset(&set);
  printf("\n");

  do {
    x = large_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, set.nelems);
  } while (x != 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");


  // empty initial set
  reset_large_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  do {
    x = large_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, set.nelems);
  } while (x != 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  delete_large_bvset(&set);
}
示例#10
0
static gboolean
do_plasma (PlasmaContext *context,
           gint           x1,
           gint           y1,
           gint           x2,
           gint           y2,
           gint           plasma_depth,
           gint           recursion_depth)
{
  gfloat tl[3], ml[3], bl[3], mt[3], mm[3], mb[3], tr[3], mr[3], br[3];
  gfloat tmp[3];
  gint    xm, ym;
  gfloat  ran;

  if (G_UNLIKELY ((!context->using_buffer) &&
                  ((x2 - x1 + 1) <= TILE_SIZE) &&
                  ((y2 - y1 + 1) <= TILE_SIZE)))
    {
      gboolean ret;
      GeglRectangle rect;

      rect.x = x1;
      rect.y = y1;
      rect.width = x2 - x1 + 1;
      rect.height = y2 - y1 + 1;

      gegl_buffer_get (context->output, &rect, 1.0, babl_format ("R'G'B' float"),
                       context->buffer, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);

      context->using_buffer = TRUE;
      context->buffer_x = x1;
      context->buffer_y = y1;
      context->buffer_width = x2 - x1 + 1;

      ret = do_plasma (context, x1, y1, x2, y2, plasma_depth, recursion_depth);

      context->using_buffer = FALSE;

      gegl_buffer_set (context->output, &rect, 0, babl_format ("R'G'B' float"),
                       context->buffer, GEGL_AUTO_ROWSTRIDE);

      return ret;
    }

  xm = (x1 + x2) / 2;
  ym = (y1 + y2) / 2;

  if (plasma_depth == -1)
    {
      random_rgba (context->gr, tl);
      put_pixel (context, tl, x1, y1);

      random_rgba (context->gr, tr);
      put_pixel (context, tr, x2, y1);

      random_rgba (context->gr, bl);
      put_pixel (context, bl, x1, y2);

      random_rgba (context->gr, br);
      put_pixel (context, br, x2, y2);

      random_rgba (context->gr, mm);
      put_pixel (context, mm, xm, ym);

      random_rgba (context->gr, ml);
      put_pixel (context, ml, x1, ym);

      random_rgba (context->gr, mr);
      put_pixel (context, mr, x2, ym);

      random_rgba (context->gr, mt);
      put_pixel (context, mt, xm, y1);

      random_rgba (context->gr, mb);
      put_pixel (context, mb, xm, y2);

      return FALSE;
    }

  if (!plasma_depth)
    {
      if (x1 == x2 && y1 == y2)
        return FALSE;

      gegl_buffer_sample (context->output, x1, y1, NULL, tl,
                          babl_format ("R'G'B' float"),
                          GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
      gegl_buffer_sample (context->output, x1, y2, NULL, bl,
                          babl_format ("R'G'B' float"),
                          GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
      gegl_buffer_sample (context->output, x2, y1, NULL, tr,
                          babl_format ("R'G'B' float"),
                          GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
      gegl_buffer_sample (context->output, x2, y2, NULL, br,
                          babl_format ("R'G'B' float"),
                          GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);

      ran = context->o->turbulence / (2.0 * recursion_depth);

      if (xm != x1 || xm != x2)
        {
          /* Left. */
          average_pixel (ml, tl, bl);
          add_random (context->gr, ml, ran);
          put_pixel (context, ml, x1, ym);

          /* Right. */
          if (x1 != x2)
            {
              average_pixel (mr, tr, br);
              add_random (context->gr, mr, ran);
              put_pixel (context, mr, x2, ym);
            }
        }


      if (ym != y1 || ym != x2)
        {
          /* Bottom. */
          if (x1 != xm || ym != y2)
            {
              average_pixel (mb, bl, br);
              add_random (context->gr, mb, ran);
              put_pixel (context, mb, xm, y2);
            }

          if (y1 != y2)
            {
              /* Top. */
              average_pixel (mt, tl, tr);
              add_random (context->gr, mt, ran);
              put_pixel (context, mt, xm, y1);
            }
        }

      if (y1 != y2 || x1 != x2)
        {
          /* Middle pixel. */
          average_pixel (mm, tl, br);
          average_pixel (tmp, bl, tr);
          average_pixel (mm, mm, tmp);

          add_random (context->gr, mm, ran);
          put_pixel (context, mm, xm, ym);
        }

      return x2 - x1 < 3 && y2 - y1 < 3;
    }

  if (x1 < x2 || y1 < y2)
    {
      /* Top left. */
      do_plasma (context, x1, y1, xm, ym, plasma_depth - 1, recursion_depth + 1);
      /* Bottom left. */
      do_plasma (context, x1, ym, xm, y2, plasma_depth - 1, recursion_depth + 1);
      /* Top right. */
      do_plasma (context, xm, y1, x2, ym, plasma_depth - 1, recursion_depth + 1);
      /* Bottom right. */
      return do_plasma (context, xm, ym, x2, y2,
                        plasma_depth - 1, recursion_depth + 1);
    }

  return TRUE;
}
示例#11
0
bool Plasma::do_plasma(int x1, int y1, int x2, int y2, int depth, int scale_depth)
{
	Color tl, ml, bl, tm, mm, bm, tr, mr, br;
	
	int xm = ( x1 + x2 )/ 2;
	int ym = ( y1 + y2 )/ 2;
	
	if(depth == -1)
	{
		random_rbg(tl);
		random_rbg(ml);
		random_rbg(bl);
		random_rbg(tm);
		random_rbg(mm);
		random_rbg(bm);
		random_rbg(tr);
		random_rbg(mr);
		random_rbg(br);
		
		set_pixel(m_pSurface, x1, y1, tl);
		set_pixel(m_pSurface, x1, ym, ml);
		set_pixel(m_pSurface, x1, y2, bl);
		set_pixel(m_pSurface, xm, y1, tm);
		set_pixel(m_pSurface, xm, ym, mm);
		set_pixel(m_pSurface, xm, y2, bm);
		set_pixel(m_pSurface, x2, y1, tr);
		set_pixel(m_pSurface, x2, ym, mr);
		set_pixel(m_pSurface, x2, y2, br);
		
		return false;
	}
	
	if(depth == 0)
	{
		if(x1 == x2 && y1 == y2)
			return false;
		
		get_pixel(m_pSurface, x1, y1, tl);
		get_pixel(m_pSurface, x1, y2, bl);
		get_pixel(m_pSurface, x2, y1, tr);
		get_pixel(m_pSurface, x2, y2, br);
		
		
		int ran = (int)((256.0 / (2 * scale_depth)) * m_fTurbulance);
		if (xm != x1 || xm != x2)
		{
			// Left
			ml = average_color(tl, bl);
			add_random(ml, ran);
			set_pixel(m_pSurface, x1, ym, ml);

			if (x1 != x2)
			{
				// Right 
				mr  = average_color(tr, br);
				add_random(mr, ran);
				set_pixel(m_pSurface, x2, ym, mr);
			}
		}

		if (ym != y1 || ym != y2)
		{
			if (x1 != xm || ym != y2)
			{
				// Bottom
				Color mb  = average_color(bl, br);
				add_random(mb, ran);
				set_pixel(m_pSurface, xm, y2, mb);
			}

			if (y1 != y2)
			{
				// Top
				Color mt  = average_color(tl, tr);
				add_random(mt, ran);
				set_pixel(m_pSurface, xm, y1, mt);
			}
		}

		if (y1 != y2 || x1 != x2)
		{
			// Middle pixel
			Color tmp;
			mm  = average_color(tl, br);
			tmp = average_color(bl, tr);
			mm  = average_color(mm, tmp);

			add_random(mm, ran);
			set_pixel(m_pSurface, xm, ym, mm);
		}
		
		return x2 - x1 < 3 && y2 - y1 < 3;
	} //depth == 0
	
	if (x1 < x2 || y1 < y2)
	{
		// Top left.
		do_plasma (x1, y1, xm, ym, depth - 1, scale_depth + 1);
		/* Bottom left. */
		do_plasma (x1, ym, xm, y2, depth - 1, scale_depth + 1);
		/* Top right. */
		do_plasma (xm, y1, x2, ym, depth - 1, scale_depth + 1);
		/* Bottom right. */
		return do_plasma (xm, ym, x2, y2, depth - 1, scale_depth + 1);
	}
	
	return true;	
}
示例#12
0
/*
 * First test: size = 64
 */
static void test1(void) {
  uint32_t x;

  printf("\n"
	 "=================\n"
	 "     TEST 1\n"
	 "=================\n\n");

  // 50 initial elements
  init_test_set(&set, 6, 50);
  printf("=== Initial set: 50 additions ===\n");
  print_bvset(&set);
  printf("\n");

  while (! rb_bvset_full(&set)) {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
  }

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  reset_rb_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  // 40 initial elements
  add_random(&set, 40, 63);
  printf("\n=== After 40 additions ===\n");
  print_bvset(&set);
  printf("\n");

  while (! rb_bvset_full(&set)) {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
  }

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");


  // empty initial set
  reset_rb_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  while (! rb_bvset_full(&set)) {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
  }

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  delete_rb_bvset(&set);
}
示例#13
0
/*
 * Size = 2^40
 */
static void test3(void) {
  uint32_t x, n;

  printf("\n"
	 "=================\n"
	 "     TEST 3\n"
	 "=================\n\n");

  // 1000 initial additions
  init_test_set(&set, 40, 1000);
  printf("=== Initial set: 1000 additions ===\n");
  print_bvset(&set);
  printf("\n");

  // 50 calls to get_fresh
  n = 50;
  do {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
    n --;
  } while (n > 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  reset_rb_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  // 2000 initial additions
  add_random(&set, 2000, UINT32_MAX);
  printf("\n=== After 2000 additions ===\n");
  print_bvset(&set);
  printf("\n");

  // 2000000 calls to get fresh
  n = 2000000;
  do {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
    n --;
  } while (n > 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");


  // empty initial set
  reset_rb_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  // 200000 calls to get fresh
  n = 200000;
  do {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
    n --;
  } while (n > 0);

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  delete_rb_bvset(&set);
}
示例#14
0
/*
 * Second test: size = 256
 */
static void test2(void) {
  uint32_t x;

  printf("\n"
	 "=================\n"
	 "     TEST 2\n"
	 "=================\n\n");

  // 200 initial additions
  init_test_set(&set, 8, 200);
  printf("=== Initial set: 200 additions ===\n");
  print_bvset(&set);
  printf("\n");

  while (! rb_bvset_full(&set)) {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
  }

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  reset_rb_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  // 240 initial elements
  add_random(&set, 240, 255);
  printf("\n=== After 240 additions ===\n");
  print_bvset(&set);
  printf("\n");

  while (! rb_bvset_full(&set)) {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
  }

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");


  // empty initial set
  reset_rb_bvset(&set);
  printf("\n=== After reset ===\n");
  print_bvset(&set);
  printf("\n");

  while (! rb_bvset_full(&set)) {
    x = rb_bvset_get_fresh(&set);
    printf("get fresh: %"PRIu32", nelems = %"PRIu32"\n", x, rbtree_card(&set.tree));
  }

  printf("\n=== Final set ===\n");
  print_bvset(&set);
  printf("\n");

  delete_rb_bvset(&set);
}