Ejemplo n.º 1
0
/*
 * Test mf_hash_*() functions.
 */
    static void
test_mf_hash()
{
    mf_hashtab_T   ht;
    mf_hashitem_T  *item;
    blocknr_T      key;
    long_u	   i;
    long_u	   num_buckets;

    mf_hash_init(&ht);

    /* insert some items and check invariants */
    for (i = 0; i < TEST_COUNT; i++)
    {
	assert(ht.mht_count == i);

	/* check that number of buckets is a power of 2 */
	num_buckets = ht.mht_mask + 1;
	assert(num_buckets > 0 && (num_buckets & (num_buckets - 1)) == 0);

	/* check load factor */
	assert(ht.mht_count <= (num_buckets << MHT_LOG_LOAD_FACTOR));

	if (i < (MHT_INIT_SIZE << MHT_LOG_LOAD_FACTOR))
	{
	    /* first expansion shouldn't have occurred yet */
	    assert(num_buckets == MHT_INIT_SIZE);
	    assert(ht.mht_buckets == ht.mht_small_buckets);
	}
	else
	{
	    assert(num_buckets > MHT_INIT_SIZE);
	    assert(ht.mht_buckets != ht.mht_small_buckets);
	}

	key = index_to_key(i);
	assert(mf_hash_find(&ht, key) == NULL);

	/* allocate and add new item */
	item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);
	assert(item != NULL);
	item->mhi_key = key;
	mf_hash_add_item(&ht, item);

	assert(mf_hash_find(&ht, key) == item);

	if (ht.mht_mask + 1 != num_buckets)
	{
	    /* hash table was expanded */
	    assert(ht.mht_mask + 1 == num_buckets * MHT_GROWTH_FACTOR);
	    assert(i + 1 == (num_buckets << MHT_LOG_LOAD_FACTOR));
	}
    }

    /* check presence of inserted items */
    for (i = 0; i < TEST_COUNT; i++)
    {
	key = index_to_key(i);
	item = mf_hash_find(&ht, key);
	assert(item != NULL);
	assert(item->mhi_key == key);
    }

    /* delete some items */
    for (i = 0; i < TEST_COUNT; i++)
    {
	if (i % 100 < 70)
	{
	    key = index_to_key(i);
	    item = mf_hash_find(&ht, key);
	    assert(item != NULL);
	    assert(item->mhi_key == key);

	    mf_hash_rem_item(&ht, item);
	    assert(mf_hash_find(&ht, key) == NULL);

	    mf_hash_add_item(&ht, item);
	    assert(mf_hash_find(&ht, key) == item);

	    mf_hash_rem_item(&ht, item);
	    assert(mf_hash_find(&ht, key) == NULL);

	    vim_free(item);
	}
    }

    /* check again */
    for (i = 0; i < TEST_COUNT; i++)
    {
	key = index_to_key(i);
	item = mf_hash_find(&ht, key);

	if (i % 100 < 70)
	{
	    assert(item == NULL);
	}
	else
	{
	    assert(item != NULL);
	    assert(item->mhi_key == key);
	}
    }

    /* free hash table and all remaining items */
    mf_hash_free_all(&ht);
}
Ejemplo n.º 2
0
Archivo: scr.c Proyecto: anylonen/omega
void display_inventory_slot(int slotnum, int topline)
{
  WINDOW *W;
  char usechar = ')', idchar = '-';
  if (Player.possessions[slotnum] != NULL)
    if (Player.possessions[slotnum]->used)
      usechar = '>';
  if (topline) W = Msg3w;
  else {
    W = Showline[slotnum];
    hide_line(slotnum);
  }
  idchar = index_to_key(slotnum);
  touchwin(W);
  wclear(W);
  switch(slotnum) {
  case O_UP_IN_AIR:
    wprintw(W,"-- Object 'up in air':",usechar);
    break;
  case O_READY_HAND:
    wprintw(W,"-- %c%c ready hand: ",idchar,usechar);
    break;
  case O_WEAPON_HAND:
    wprintw(W,"-- %c%c weapon hand: ",idchar,usechar);
    break;
  case O_LEFT_SHOULDER:
    wprintw(W,"-- %c%c left shoulder: ",idchar,usechar);
    break;
  case O_RIGHT_SHOULDER:
    wprintw(W,"-- %c%c right shoulder: ",idchar,usechar);
    break;
  case O_BELT1:
    wprintw(W,"-- %c%c belt: ",idchar,usechar);
    break;
  case O_BELT2:
    wprintw(W,"-- %c%c belt: ",idchar,usechar);
    break;
  case O_BELT3:
    wprintw(W,"-- %c%c belt: ",idchar,usechar);
    break;
  case O_SHIELD:
    wprintw(W,"-- %c%c shield: ",idchar,usechar);
    break;
  case O_ARMOR:
    wprintw(W,"-- %c%c armor: ",idchar,usechar);
    break;
  case O_BOOTS:
    wprintw(W,"-- %c%c boots: ",idchar,usechar);
    break;
  case O_CLOAK:
    wprintw(W,"-- %c%c cloak: ",idchar,usechar);
    break;
  case O_RING1:
    wprintw(W,"-- %c%c finger: ",idchar,usechar);
    break;
  case O_RING2:
    wprintw(W,"-- %c%c finger: ",idchar,usechar);
    break;
  case O_RING3:
    wprintw(W,"-- %c%c finger: ",idchar,usechar);
    break;
  case O_RING4:
    wprintw(W,"-- %c%c finger: ",idchar,usechar);
    break;
  }
  if (Player.possessions[slotnum]== NULL)
    wprintw(W,"(slot vacant)");
  else wprintw(W,itemid(Player.possessions[slotnum]));
  wrefresh(W);
}