示例#1
0
int hadlock_algo(Pair* source, Pair* target){
  int i, j, v1, v2, res;
  Pair p, v, step[4] = {{1,0},{0,1},{-1,0},{0,-1}};
  /* initialize all cells like unvisited */
  for(i=0; i<sz.r; ++i){
    for(j=0; j<sz.c; ++j){
      W[i][j] = -1;
    }
  }
  q_clear();
  p_set(W,source,0);
  q_push(source);
  while(!q_empty()){
    p = q_pop();
    for(i=0; i<4; ++i){
      v = p_sum(step+i,&p);
      v1 = p_get(Z,&p); 
      v2 = p_get(Z,&v);
      if(p_in(&v) && (p_get(W,&v)==-1 || (p_get(W,&v)>p_get(W,&p))) && (v1-v2 <= 3) && (v1-v2 >= -1) && can_go(&v)){
        if(p_mhtn_norm(&v,target) < p_mhtn_norm(&p,target)){
          p_set(W,&v,p_get(W,&p));
          q_push_back(&v);
        }else{ /* > */
          /*if(!(p_get(W,&v)!=-1 || (p_get(W,&v)==p_get(W,&p)+1))){ */
          p_set(W,&v,p_get(W,&p)+1);
          q_push_front(&v);  
        }
        if(p_eq(&v,target)){
          break;
        }
      }
    }
    if(p_eq(&v,target)) break;
  }
  res = p_get(W,target);
  if(res != -1) res = 2*res+p_mhtn_norm(source,target); 
  return res;
}
static struct entry *update_hotspot_queue(struct smq_policy *mq, dm_oblock_t b, struct bio *bio)
{
	unsigned hi;
	dm_oblock_t hb = to_hblock(mq, b);
	struct entry *e = h_lookup(&mq->hotspot_table, hb);

	if (e) {
		stats_level_accessed(&mq->hotspot_stats, e->level);

		hi = get_index(&mq->hotspot_alloc, e);
		q_requeue(&mq->hotspot, e,
			  test_and_set_bit(hi, mq->hotspot_hit_bits) ?
			  0u : mq->hotspot_level_jump);

	} else {
		stats_miss(&mq->hotspot_stats);

		e = alloc_entry(&mq->hotspot_alloc);
		if (!e) {
			e = q_pop(&mq->hotspot);
			if (e) {
				h_remove(&mq->hotspot_table, e);
				hi = get_index(&mq->hotspot_alloc, e);
				clear_bit(hi, mq->hotspot_hit_bits);
			}

		}

		if (e) {
			e->oblock = hb;
			q_push(&mq->hotspot, e);
			h_insert(&mq->hotspot_table, e);
		}
	}

	return e;
}
示例#3
0
void q_push_front(const Pair*p){
  q_push(p);
}
/*
 * These methods tie together the dirty queue, clean queue and hash table.
 */
static void push_new(struct smq_policy *mq, struct entry *e)
{
	struct queue *q = e->dirty ? &mq->dirty : &mq->clean;
	h_insert(&mq->table, e);
	q_push(q, e);
}
示例#5
0
void timer_startOneShot(void* handle, uint32_t dt)
{
	DEBUGOUT("timer_startOneShot(%p, ...)", handle);
	ctx.handle = handle;
	q_push(firedHandler);
}
示例#6
0
void timer_startPeriodic(void* handle, uint32_t dt)
{
	ctx.handle = handle;
	q_push(firedHandler);
}
int main(int argc, char *argv[])
{
  size_t s = sizeof(int);
  int foo;
  {
    /*#Test_0*/
    queue q; q_init(&q, s);
    test(q_size(&q) == 0 && q_is_empty(&q));
  }
  {
    /*#Test_1*/
    queue q; q_init(&q, s);
    foo = 1; q_push(&q, &foo);
    test(q_size(&q) == 1 && !q_is_empty(&q) && *(int *)q_front(&q) == 1);
  }
  {
    /*#Test_2*/
    queue q; q_init(&q, s);
    foo = 2; q_push(&q, &foo);
    foo = 1; q_push(&q, &foo);
    test(
        q_size(&q) == 2 && 
        *(int *)q_front(&q) == 1 && 
        *(int *)q_back(&q) == 2);
  }
  {
    /*#Test_3*/
    queue q; q_init(&q, s);

    foo = 3; q_push(&q, &foo);
    foo = 2; q_push(&q, &foo);
    foo = 1; q_push(&q, &foo);

    q_pop(&q);
    BOOL bar = *(int *)q_front(&q) == 1 && *(int *)q_back(&q) == 2;

    q_pop(&q);
    bar &= *(int *)q_front(&q) == 1 && *(int *)q_back(&q) == 1;

    q_pop(&q);
    test(
        bar &&
        q_is_empty(&q));
  }
  {
    /*#Test_4*/
    queue q; q_init(&q, s);
    BOOL bar = TRUE;

    for (uint i = 0; i < N; ++i)
    {
      foo = i; q_push(&q, &foo);
    }

    for (uint i = 0; i < N; ++i)
    {
      bar &= *(int *)q_back(&q) == i;
      if (!bar) break;
      q_pop(&q);
    }

    test(
        bar&
        q_is_empty(&q));
  }

  return EXIT_SUCCESS;
}
示例#8
0
int main( /* int argc, char const *argv[] */ )
{
	printf("Projet Monoplan, Lenouvel Baptiste\n\n");

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

	lifo_t stack;

	init_lifo(&stack, STACK_SIZE);
	
	printf("Push 42\n");
	push(&stack, 42.0);

	printf("Push 1337\n");
	push(&stack, 1337.0);

	printf("Push 31137\n");
	push(&stack, 31337.0);
	
	printf("pop : %lf \n", pop(&stack));
	printf("pop : %lf \n", pop(&stack));
	printf("pop : %lf \n", pop(&stack));
	printf("pop : %lf \n", pop(&stack));
	printf("pop : %lf \n", pop(&stack));

	free_lifo(&stack);

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

	queue_t * queue;

	int test = 1337;
	char * str = "apprenti";
	char * str1 = "loick_et_ses_poules";
	char * str2 = "limousin";
	char * str3 = "ZZtop";

	printf("Init queue : ");
	init_queue(&queue);
	printf("ok\n\n");

	printf("Push %s \n", str);
	q_push(&queue, str);

	printf("Push %s \n", str1);
	q_push(&queue, str1);

	printf("Push in head : %d \n", test);
	q_push_head(&queue, &test);

	printf("Push in head : %s \n\n", str2);
	q_push_head(&queue, str2);


	printf("Removing %s ... %s \n\n", str2, q_remove(&queue, str2) ? "ok" : "ko");

	// printf("Pop head : %s \n", (char *)(q_pop_head(&queue)) );
	printf("Pop head : %d \n", *(int *)(q_pop_head(&queue)) );
	printf("Pop head : %s \n", (char *)(q_pop_head(&queue)) );
	printf("Pop head : %s \n\n", (char *)(q_pop_head(&queue)) );

	printf("Push %s with q_operation \n\n", str3);
	q_operation(&q_push, &queue, str3);

	q_free(&queue);

	return 0;
}