Exemplo n.º 1
0
static void CALLBACK
userlist_remove_unreplied_cb(
	HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	struct userlist_remove_unreplied_info_struct info;
	int i;
	char * r_nickname;
	
	ASSERT_RETURNIFFAIL(VALIDPTR(s_userlistHash));

	/* perform enumeration to find the unreplied ones */
	info.dead_keys = malloc(
			sizeof(void*) * hashtable_count(s_userlistHash));
	info.dead_key_count = 0;
	hashtable_enumerate(
		s_userlistHash,
		userlist_remove_unreplied_enum_fn, (void*)&info);

	/* quietly remove those dead */
	for(i = 0; i < info.dead_key_count; i++) {
		userlist_remove(info.dead_keys[i], 0);
		free(info.dead_keys[i]);
	}

	/* free leftovers */
	free(info.dead_keys);

	/* send another user refresh list request to the network
	 */
	r_nickname = util_utf2vqp(user_codepage(), user_nickname());
	msgloop_send(vqp_msg_refresh_req(s_vqpLink, r_nickname, user_codepage()), 0);
	free(r_nickname);
}
Exemplo n.º 2
0
void userlist_enum(userlist_enum_fn enum_fn, void * enum_fn_data)
{
	void * proxy_data[2];
	
	ASSERT_RETURNIFFAIL(enum_fn);
	
	proxy_data[0] = (void*)enum_fn;
	proxy_data[1] = (void*)enum_fn_data;

	hashtable_enumerate(s_userlistHash,
			userlist_enum_proxy_fn, (void*)proxy_data);
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
  hashtable_t *ht;
  int cbuckets, i;
  unsigned rand1, rand2;
  hashtable_enum_t *s;

  printf("Test size? ");
  scanf("%d", &insertcnt);
  printf("Bucket count? ");
  scanf("%d", &cbuckets);
  ht = hashtable_make(cbuckets, mt_compare, mt_hash, mt_free, NULL);
  
  printf("Control... ");
  timeThis();
  timeThis();
  
  printf("Insertion... ");
  srand(insertcnt);
  timeThis();
  for (i=0; i<insertcnt; i++) {
    hashtable_insert(ht, (void*)((intptr_t)rand()+1), (void*)1);
  }
  timeThis();
  
  printf("Retrieval... ");
  srand(insertcnt);
  timeThis();
  for (i=0; i<insertcnt; i++) {
    hashtable_search(ht, (void*)((intptr_t)rand()+1));
  }
  timeThis();
  
  printf("Enumeration... ");
  srand(insertcnt);
  timeThis();
  s = hashtable_enumerate(NULL, ht, (void**)&rand1, NULL);
  while (s) {
    s = hashtable_enumerate(s, ht, (void**)&rand1, NULL);
  }
  timeThis();
  
  printf("Removal... ");
  srand(insertcnt);
  timeThis();
  for (i=0; i<insertcnt; i++) {
    hashtable_remove(ht, (void*)((intptr_t)rand()+1));
  }
  timeThis();
  
  if (insertcnt != freecnt) {
    printf("Something's wrong. %d %d\n", insertcnt, freecnt);
  }

  printf("Insertion 2... ");
  srand(insertcnt);
  timeThis();
  for (i=0; i<insertcnt; i++) {
    hashtable_insert(ht, (void*)((intptr_t)rand()+1), (void*)1);
  }
  timeThis();
  
  freecnt = 0;
  printf("Free... ");
  timeThis();
  hashtable_free(ht);
  timeThis();
  
  if (insertcnt != freecnt) {
    printf("Something's wrong. %d %d\n", insertcnt, freecnt);
  }
  
  printf("all ok\n");
  return 0;
}