Exemple #1
0
static int test_clear(c_pmap thiz)
{
	c_iterator begin, end;
	c_reverse_iterator rbegin, rend;
	c_map_clear(thiz);
	begin = c_map_begin(thiz);
	end = c_map_end(thiz);
	rbegin = c_map_rbegin(thiz);
	rend = c_map_rend(thiz);
	
	if(c_map_size(thiz) == 0)
		printf("ok, size is 0\n");
	else
		printf("error, size is not 0\n");
	
	if(ITER_EQUAL(begin, end))
		printf("ok, begin == end\n");
	else
		printf("error, begin != end\n");
	
	if(ITER_EQUAL(rbegin, rend))
		printf("ok, rbegin == rend\n");
	else
		printf("error, rbegin != rend\n");
	return 0;
}
Exemple #2
0
static BOOL __map_containsKey(Map *map, void *key){
	Iterator target, map_end;
	target = c_map_find(&map->values, key);
	map_end = c_map_end(&map->values);
	if( !ITER_EQUAL(map_end ,target ))
		return TRUE;
	else return FALSE;
}
Exemple #3
0
static void __map_remove(Map *map, void *key){
	Iterator target, map_end;
	target = c_map_find(&map->values, key);
	map_end = c_map_end(&map->values);
	if(!ITER_EQUAL(map_end, target))
	{
		c_map_erase(&map->values, target);
	}
}
Exemple #4
0
static void assert_valid_iter(c_pmap thiz, c_iterator val)
{
	c_iterator end = c_map_end(thiz);
	c_iterator iter = c_map_begin(thiz);
	for(; !ITER_EQUAL(iter, end); ITER_INC(iter))
	{
		if(ITER_EQUAL(iter, val))
			return;
	}
	assert(false);
}
Exemple #5
0
static int test_erase(c_pmap thiz)
{
	c_iterator iter = c_map_begin(thiz);
	c_iterator end = c_map_end(thiz);
	assert(__c_rb_tree_verify(thiz->_l));
	//c_map_erase(thiz, end);  // erasing end results in error
	assert(__c_rb_tree_verify(thiz->_l));
	while(!ITER_EQUAL(iter, end))
	{
		c_iterator to_erase = iter;
		assert_valid_iter(thiz, to_erase);
		c_map_erase(thiz, to_erase);
		assert(__c_rb_tree_verify(thiz->_l));
		
		iter = c_map_begin(thiz);
		end = c_map_end(thiz);
	}
	assert(__c_rb_tree_verify(thiz->_l));
	assert(c_map_empty(thiz));
	return 0;
}
Exemple #6
0
static int print_map(c_pmap pt)
{
	c_iterator iter = c_map_begin(pt);
	c_iterator end = c_map_end(pt);
	printf("map is:\n");
	for(; !ITER_EQUAL(iter, end); ITER_INC(iter))
	{
		printf("key = %d, value = %d\n",
			*(int*)((c_ppair)ITER_REF(iter))->first,
			*(int*)((c_ppair)ITER_REF(iter))->second);
	}
	return 0;
}
Exemple #7
0
static int test_reverse_find_erase(c_pmap thiz)
{
	int j = 0;
	for(j = sizeof(keys) / sizeof(int) - 1; j >= 0; -- j)
	{
		c_iterator target, map_end;	
		printf("j = %d\n", j);

		target = c_map_find(thiz, &keys[j]); // set same as map
		
		map_end = c_map_end(thiz);
		if(!ITER_EQUAL(map_end, target))
		{			
			printf("to erase : %d\n", *(int*)(((c_ppair)ITER_REF(target))->first));
			assert_valid_iter(thiz, target);
			c_map_erase(thiz, target);
			assert(__c_rb_tree_verify(thiz->_l));
		}			
	}
	return 0;	
}
Exemple #8
0
static BOOL __map_hasNext(Map *map, Iterator *iter){
	c_iterator last = c_map_end(&map->values);
	return !ITER_EQUAL(*iter, last);
}