Example #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;
}
Example #2
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);
}
Example #3
0
static int print_queue(c_pqueue ps)
{
	c_vector tmpvt;
	__c_vector(&tmpvt, int_comparer);

	printf("queue is : \n");
	while(!c_queue_empty(ps))
	{
		int * tmp = c_queue_front(ps);
		printf("front is : %d, size is : %d, back is : %d\n", 
				*tmp, 
				c_queue_size(ps),
				*(int *)c_queue_back(ps));
		c_queue_pop(ps);
		c_vector_push_back(&tmpvt, tmp);
	}

	// recover queue
	do
	{
		c_iterator iter = c_vector_begin(&tmpvt);
		c_iterator end = c_vector_end(&tmpvt);
		for(; !ITER_EQUAL(iter, end); ITER_INC(iter))
		{
			c_queue_push(ps, ITER_REF(iter));
		}
	} while(0);	

	__c_rotcev(&tmpvt);
	return 0;
}
Example #4
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;
}
Example #5
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);
	}
}
Example #6
0
c_iterator c_vector_erase(c_pvector thiz, c_iterator pos)
{
	c_iterator pos_1 = ITER_POSITIVE_N(pos, 1);
	c_iterator end = c_vector_end(thiz);
	_c_vector_impl * pl = (_c_vector_impl *)thiz->_l;
	if(!ITER_EQUAL(pos_1, end))
		c_copy(pos_1, _A_get_iterator(pl->_finish), pos);
	-- pl->_finish;
	return pos;
}
Example #7
0
static void print_vector2_r(c_reverse_iterator first, c_reverse_iterator last)
{
    c_reverse_iterator iter;
    printf("vector is :\n");
    for(iter = first; 
            !ITER_EQUAL(iter, last); ITER_INC(iter))
    {
        printf("\t%d\n", *((int *)(ITER_REF(iter))));
    }
}
Example #8
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;
}
Example #9
0
void c_vector_insert2(c_pvector thiz, c_iterator pos, c_iterator first, c_iterator last)
{
	if(!ITER_EQUAL(first, last))
	{
		_c_vector_impl * pl = (_c_vector_impl *)thiz->_l;
		difference_type dn = 0;
		size_type n = 0;
		c_distance1(first, last, &dn);
		n = abs(dn);
		if(abs(pl->_end_of_storage - pl->_finish) >= (int)n)
		{
			const size_type elems_after = pl->_finish - (pnode_t)pos._i;
			c_iterator old_finish = c_vector_end(thiz);
			if(elems_after > n)
			{
				c_uninitialized_copy(_A_get_iterator(pl->_finish - n),
							_A_get_iterator(pl->_finish),
							_A_get_iterator(pl->_finish));
				pl->_finish += n;
				c_copy_backward(pos, ITER_NEGATIVE_N(old_finish, n), old_finish);
				c_copy(first, last, pos);
			}
			else
			{
				c_uninitialized_copy(ITER_POSITIVE_N(first, elems_after), 
							last, 
							_A_get_iterator(pl->_finish));
				pl->_finish += n - elems_after;
				c_uninitialized_copy(pos, old_finish, _A_get_iterator(pl->_finish));
				pl->_finish += elems_after;
				c_copy(first, ITER_POSITIVE_N(first, elems_after), pos);
			}
		}
		else
		{
			const size_type old_size = c_vector_size(thiz);
			const size_type len = old_size + C_MAX(old_size, n);
			c_iterator new_start = _A_get_iterator(_A_allocate(thiz, len));
			c_iterator new_finish = new_start;
			new_finish = c_uninitialized_copy(_A_get_iterator(pl->_start), pos, new_start);
			new_finish = c_uninitialized_copy(first, last, new_finish);
			new_finish = c_uninitialized_copy(pos, _A_get_iterator(pl->_finish), new_finish);
			_A_deallocate(thiz, pl->_start, abs(pl->_end_of_storage - pl->_start));
			pl->_start = (pnode_t)new_start._i;
			pl->_finish = (pnode_t)new_finish._i;
			pl->_end_of_storage = (pnode_t)ITER_POSITIVE_N(new_start, len)._i;
		}
	}
}
Example #10
0
c_iterator c_vector_insert(c_pvector thiz, c_iterator pos, const value_type val)
{
	c_iterator begin = c_vector_begin(thiz);
	c_iterator end = c_vector_end(thiz);
	size_type n = abs(ITER_DIFF(pos, begin));
	_c_vector_impl * pl = (_c_vector_impl *)thiz->_l;
	if((pl->_finish != pl->_end_of_storage) && 
		ITER_EQUAL(pos, end))
	{
		*pl->_finish = val;
		++ pl->_finish;
	}
	else
		_A_insert_aux1(thiz, pos, val);
	return ITER_POSITIVE_N(begin, n);
}
Example #11
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;	
}
Example #12
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;
}
Example #13
0
static BOOL __map_hasNext(Map *map, Iterator *iter){
	c_iterator last = c_map_end(&map->values);
	return !ITER_EQUAL(*iter, last);
}