Exemplo n.º 1
0
c_pvector c_vector_assign(c_pvector thiz, const c_pvector V)
{
	if(V != thiz)
	{
		_c_vector_impl * pl = (_c_vector_impl *)thiz->_l;
		const size_type vlen = c_vector_size(V);
		if(vlen > c_vector_capacity(thiz))
		{
			c_iterator tmp = _A_allocate_and_copy(thiz,
								vlen,
								c_vector_begin(V),
								c_vector_end(V));
			_A_deallocate(thiz, 
					pl->_start, 
					abs(pl->_end_of_storage - pl->_start));
			pl->_start = (pnode_t)tmp._i;
			pl->_end_of_storage = pl->_start + vlen;
		}
		else if(c_vector_size(thiz) >= vlen)
		{
			c_copy(c_vector_begin(V), c_vector_end(V), c_vector_begin(thiz));
		}
		else
		{
			c_iterator bg = c_vector_begin(thiz);
			c_copy(bg, ITER_POSITIVE_N(bg, c_vector_size(thiz)), _A_get_iterator(pl->_start));
			c_uninitialized_copy(ITER_POSITIVE_N(bg, c_vector_size(thiz)),
						c_vector_end(thiz),
						_A_get_iterator(pl->_finish));
		}
		pl->_finish = pl->_start + vlen;
	}
	return thiz;
}
Exemplo n.º 2
0
c_bool c_vector_less(c_pvector thiz, const c_pvector V)
{
	return c_lexicographical_compare(c_vector_begin(thiz),
						c_vector_end(thiz),
						c_vector_begin(V),
						c_vector_end(V),
						thiz->_cmp);
}
Exemplo n.º 3
0
c_bool c_vector_equal(c_pvector thiz, const c_pvector V)
{
	c_binary_predicate bp =  c_binary_negate(thiz->_cmp);
	return (c_vector_size(thiz) == c_vector_size(V)) &&
			c_equal2(c_vector_begin(thiz),
					c_vector_end(thiz),
					c_vector_begin(V),
					bp);
}
Exemplo n.º 4
0
static void vector_insert2(c_vector * p)
{
    c_vector vt;
    __c_vector(&vt, int_comparer);
    
    c_vector_insert2(&vt, 
                    c_vector_begin(&vt), 
                    c_vector_begin(p),
                    c_vector_end(p));
    printf("after insert2\n");
    print_vector(&vt);
    __c_rotcev(&vt);    
}
Exemplo n.º 5
0
static void print_vector(c_vector * p)
{
    c_iterator first, last;
    first = c_vector_begin(p);
    last = c_vector_end(p);
    print_vector2(first, last);
}
Exemplo n.º 6
0
static void vector_equal(c_vector * p)
{
    c_iterator iter;
    int * old;
    c_vector vt;
    __c_vector(&vt, int_comparer);
    
    print_vector(&vt);
    print_vector(p);
    printf(c_vector_equal(&vt, p) ? "IS equal\n" : "NOT equal\n");
    
    create_with_push_back(&vt);
    print_vector(&vt);
    print_vector(p);
    printf(c_vector_equal(&vt, p) ? "IS equal\n" : "NOT equal\n");
    
    iter = c_vector_begin(&vt);
    old = (int*)ITER_REF(iter); 
    ITER_REF_ASSIGN(iter, &array[5]);
    print_vector(&vt);
    print_vector(p);
    printf(c_vector_equal(&vt, p) ? "IS equal\n" : "NOT equal\n");       
    ITER_REF_ASSIGN(iter, old);
    
    c_vector_clear(&vt);
    c_vector_clear(p);
    print_vector(&vt);
    print_vector(p);
    printf(c_vector_equal(&vt, p) ? "IS equal\n" : "NOT equal\n");
    __c_rotcev(&vt);
}
Exemplo n.º 7
0
static void vector_insert(c_vector * p)
{
    c_iterator iter;
    c_vector_insert(p, c_vector_end(p), &array[0]);
    c_vector_insert(p, c_vector_begin(p), &array[2]);
    c_vector_insert(p, c_vector_end(p), &array[4]);
    c_vector_insert(p, c_vector_end(p), &array[6]);
    c_vector_insert(p, c_vector_begin(p), &array[8]);
    
    iter = c_vector_begin(p);
    iter = ITER_POSITIVE_N(iter, 3);
    c_vector_insert(p, iter, &array[5]);   
    
    printf("vector after insertion\n");
    print_vector(p);
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
void c_vector_resize(c_pvector thiz, size_t n)
{
	c_iterator begin = c_vector_begin(thiz);
	if(n < c_vector_size(thiz))
		c_vector_erase2(thiz, ITER_POSITIVE_N(begin, n), c_vector_end(thiz));
	else
		c_vector_fill_insert(thiz, c_vector_end(thiz), n, NULL);
}
Exemplo n.º 10
0
static void vector_fill_insert(c_vector * p)
{
    c_iterator iter = c_vector_begin(p);
    
    c_vector_fill_insert(p, ITER_INC(iter), 10, &array[8]);
    printf("after fill insert middle\n");
    print_vector(p);    
    
    c_vector_fill_insert(p, c_vector_begin(p), 10, &array[6]);
    printf("after fill insert begin\n");
    print_vector(p);    
    
    c_vector_fill_insert(p, c_vector_end(p), 10, &array[4]);
    printf("after fill insert end\n");
    print_vector(p);
    
}
Exemplo n.º 11
0
void c_vector_reserve(c_pvector thiz, size_t n)
{
	if(c_vector_capacity(thiz) < n)
	{
		_c_vector_impl * pl = (_c_vector_impl *)thiz->_l;
		const size_type old_size = c_vector_size(thiz);
		c_iterator tmp = _A_allocate_and_copy(thiz, n, c_vector_begin(thiz), c_vector_end(thiz));
		_A_deallocate(thiz, pl->_start, abs(pl->_end_of_storage - pl->_start));
		pl->_start = (pnode_t)tmp._i;
		pl->_finish = pl->_start + old_size;
		pl->_end_of_storage = pl->_start + n;
	}    
}
Exemplo n.º 12
0
static void erase_vector()
{
    c_vector vt;
    c_vector * p = &vt;
    c_iterator i1, i3, i4, i6, i10;
    
    __c_vector(&vt, int_comparer);
    
    create_with_push_back(&vt);
    i1 = c_vector_begin(p);
    print_vector(p);
    
    printf("erase last :\n");
    i10 = ITER_POSITIVE_N(i1, 10);
    c_vector_erase(p, i10);
    print_vector(p);
    
    printf("erase middle 1 : \n");
    i4 = ITER_POSITIVE_N(i1, 4);
    c_vector_erase(p, i4);
    print_vector(p);
    
    printf("erase middle n : \n");
    i3 = ITER_POSITIVE_N(i1, 3);
    i6 = ITER_POSITIVE_N(i1, 6);
    c_vector_erase2(p, i3, i6);
    print_vector(p);
    
    printf("erase first :\n");
    c_vector_erase(p, i1);
    print_vector(p);   
    
    printf("erase all :\n");
    c_vector_erase2(p, c_vector_begin(p), c_vector_end(p));
    print_vector(p); 
    
    __c_rotcev(&vt);
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
0
static int create_with_insert_unique2(c_pmap thiz)
{
	c_vector vt;
	int i = 0;
	c_vector_create(&vt, int_comparer);
	for(i = 0; i < sizeof(values) / sizeof(int); ++ i)
	{
		c_iterator v_beg, v_end;
		c_vector_push_back(&vt, &pairs[i]);

		v_beg = c_vector_begin(&vt);
		v_end = c_vector_end(&vt);
		c_map_insert2(thiz, v_beg, v_end);

		assert(__c_rb_tree_verify(thiz->_l));
	}

	c_vector_destroy(&vt);
	return 0;
}
Exemplo n.º 15
0
void c_vector_clear(c_pvector thiz)
{
	c_vector_erase2(thiz, c_vector_begin(thiz), c_vector_end(thiz));
}
Exemplo n.º 16
0
size_type c_vector_size(c_pvector thiz)
{
	c_iterator b = c_vector_begin(thiz), e = c_vector_end(thiz);
	return abs(ITER_DIFF(e, b));
}