Esempio n. 1
0
/**
 * Test the first vector is less than the second vector.
 */
bool_t vector_less(const vector_t* cpvec_first, const vector_t* cpvec_second)
{
    bool_t b_result = false;
    vector_iterator_t it_first;
    vector_iterator_t it_second;

    assert(cpvec_first != NULL);
    assert(cpvec_second != NULL);
    assert(_vector_is_inited(cpvec_first));
    assert(_vector_is_inited(cpvec_second));
    assert(_vector_same_type(cpvec_first, cpvec_second));

    for(it_first = vector_begin(cpvec_first), it_second = vector_begin(cpvec_second);
        !iterator_equal(it_first, vector_end(cpvec_first)) && !iterator_equal(it_second, vector_end(cpvec_second));
        it_first = iterator_next(it_first), it_second = iterator_next(it_second))
    {
        b_result = _GET_VECTOR_TYPE_SIZE(cpvec_first);
        _GET_VECTOR_TYPE_LESS_FUNCTION(cpvec_first)(_VECTOR_ITERATOR_COREPOS(it_first), _VECTOR_ITERATOR_COREPOS(it_second), &b_result);
        /* if any element in first vector are less then the second return true */
        if(b_result)
        {
            return true;
        }
        b_result = _GET_VECTOR_TYPE_SIZE(cpvec_first);
        _GET_VECTOR_TYPE_LESS_FUNCTION(cpvec_first)(_VECTOR_ITERATOR_COREPOS(it_second), _VECTOR_ITERATOR_COREPOS(it_first), &b_result);
        /* if any element in first vector are greater then the second return false */
        if(b_result)
        {
            return false;
        }
    }

    /* if the first n elements in two vector are equal then compare the vector size */
    return vector_size(cpvec_first) < vector_size(cpvec_second) ? true : false;
}
Esempio n. 2
0
/**
 * Test the type that saved in the vector container and referenced by it_iter are same.
 */
bool_t _vector_same_vector_iterator_type(const vector_t* cpvec_vector, vector_iterator_t it_iter)
{
    assert(cpvec_vector != NULL);
    assert(_VECTOR_ITERATOR_CONTAINER(it_iter) != NULL);
    assert(_VECTOR_ITERATOR_CONTAINER_TYPE(it_iter) == _VECTOR_CONTAINER);
    assert(_VECTOR_ITERATOR_ITERATOR_TYPE(it_iter) == _RANDOM_ACCESS_ITERATOR);

    return _vector_same_type(cpvec_vector, _VECTOR_ITERATOR_CONTAINER(it_iter));
}
Esempio n. 3
0
/**
 * Initialize vector container with an exist vector container.
 */
void vector_init_copy(vector_t* pvec_dest, const vector_t* cpvec_src)
{
    assert(pvec_dest != NULL);
    assert(cpvec_src != NULL);
    assert(_vector_is_created(pvec_dest));
    assert(_vector_is_inited(cpvec_src));
    assert(_vector_same_type(pvec_dest, cpvec_src));

    vector_init_copy_range(pvec_dest, vector_begin(cpvec_src), vector_end(cpvec_src));
}
Esempio n. 4
0
/**
 * Assign vector element with an exist vector container.
 */
void vector_assign(vector_t* pvec_dest, const vector_t* cpvec_src)
{
    assert(pvec_dest != NULL);
    assert(cpvec_src != NULL);
    assert(_vector_is_inited(pvec_dest));
    assert(_vector_is_inited(cpvec_src));
    assert(_vector_same_type(pvec_dest, cpvec_src));

    if(vector_equal(pvec_dest, cpvec_src))
    {
        return;
    }

    vector_assign_range(pvec_dest, vector_begin(cpvec_src), vector_end(cpvec_src));
}
Esempio n. 5
0
/**
 * Test the two vectors are equal.
 */
bool_t vector_equal(const vector_t* cpvec_first, const vector_t* cpvec_second)
{
    vector_iterator_t it_first;
    vector_iterator_t it_second;
    bool_t            b_less = false;
    bool_t            b_greater = false;

    assert(cpvec_first != NULL);
    assert(cpvec_second != NULL);
    assert(_vector_is_inited(cpvec_first));
    assert(_vector_is_inited(cpvec_second));

    /* same vector container */
    if(cpvec_first == cpvec_second)
    {
        return true;
    }
    /* the element type is equal */
    if(!_vector_same_type(cpvec_first, cpvec_second))
    {
        return false;
    }
    /* the element count is equal */
    if(vector_size(cpvec_first) != vector_size(cpvec_second))
    {
        return false;
    }

    /* each element is equal */
    for(it_first = vector_begin(cpvec_first), it_second = vector_begin(cpvec_second);
        !iterator_equal(it_first, vector_end(cpvec_first)) && !iterator_equal(it_second, vector_end(cpvec_second));
        it_first = iterator_next(it_first), it_second = iterator_next(it_second))
    {
        b_less = _GET_VECTOR_TYPE_SIZE(cpvec_first);
        b_greater = _GET_VECTOR_TYPE_SIZE(cpvec_second);
        _GET_VECTOR_TYPE_LESS_FUNCTION(cpvec_first)(_VECTOR_ITERATOR_COREPOS(it_first), _VECTOR_ITERATOR_COREPOS(it_second), &b_less);
        _GET_VECTOR_TYPE_LESS_FUNCTION(cpvec_second)(_VECTOR_ITERATOR_COREPOS(it_second), _VECTOR_ITERATOR_COREPOS(it_first), &b_greater);
        if(b_less || b_greater)
        {
            return false;
        }
    }
    assert(iterator_equal(it_first, vector_end(cpvec_first)) &&
           iterator_equal(it_second, vector_end(cpvec_second)));

    return true;
}
Esempio n. 6
0
/**
 * Swap vector datas.
 */
void vector_swap(vector_t* pvec_first, vector_t* pvec_second)
{
    vector_t vec_swap;  /* the swap temporary vector */

    /* test the two vector has the same type */
    assert(pvec_first != NULL);
    assert(pvec_second != NULL);
    assert(_vector_is_inited(pvec_first));
    assert(_vector_is_inited(pvec_second));
    assert(_vector_same_type(pvec_first, pvec_second));

    if(vector_equal(pvec_first, pvec_second))
    {
        return;
    }

    vec_swap = *pvec_first;
    *pvec_first = *pvec_second;
    *pvec_second = vec_swap;
}