Esempio n. 1
0
/**
 * Test the two pair is have the same type.
 */
bool_t _hash_multimap_same_pair_type(const pair_t* cppair_first, const pair_t* cppair_second)
{
    assert(cppair_first != NULL);
    assert(cppair_second != NULL);
    assert(_pair_is_inited(cppair_first) || _pair_is_created(cppair_first));
    assert(_pair_is_inited(cppair_second) || _pair_is_created(cppair_second));

    return (cppair_first->_t_typeinfofirst._pt_type == cppair_second->_t_typeinfofirst._pt_type) &&
           (cppair_first->_t_typeinfofirst._t_style == cppair_second->_t_typeinfofirst._t_style) &&
           (cppair_first->_t_typeinfosecond._pt_type == cppair_second->_t_typeinfosecond._pt_type) &&
           (cppair_first->_t_typeinfosecond._t_style == cppair_second->_t_typeinfosecond._t_style) &&
           _type_is_same(cppair_first->_t_typeinfofirst._s_typename, cppair_second->_t_typeinfofirst._s_typename) &&
           _type_is_same(cppair_first->_t_typeinfosecond._s_typename, cppair_second->_t_typeinfosecond._s_typename);
}
Esempio n. 2
0
/**
 * Initialize pair container with pair.
 */
void pair_init_copy(pair_t* ppair_dest, const pair_t* cppair_src)
{
    bool_t b_result = false;

    assert(ppair_dest != NULL);
    assert(cppair_src != NULL);
    assert(_pair_is_created(ppair_dest));
    assert(_pair_is_inited(cppair_src));
    assert(_pair_same_type(ppair_dest, cppair_src));

    /* initialize dest pair */
    pair_init(ppair_dest);

    /* copy element */
    b_result = _GET_PAIR_FIRST_TYPE_SIZE(ppair_dest);
    _GET_PAIR_FIRST_TYPE_COPY_FUNCTION(ppair_dest)(ppair_dest->_pv_first, cppair_src->_pv_first, &b_result);
    assert(b_result);

    b_result = _GET_PAIR_SECOND_TYPE_SIZE(ppair_dest);
    _GET_PAIR_SECOND_TYPE_COPY_FUNCTION(ppair_dest)(ppair_dest->_pv_second, cppair_src->_pv_second, &b_result);
    assert(b_result);

    ppair_dest->_bfun_mapkeycompare = cppair_src->_bfun_mapkeycompare;
    ppair_dest->_bfun_mapvaluecompare = cppair_src->_bfun_mapvaluecompare;
}
Esempio n. 3
0
/**
 * Destroy pair container auxiliary function.
 */
void _pair_destroy_auxiliary(pair_t* ppair_pair)
{
    assert(ppair_pair != NULL);
    assert(_pair_is_inited(ppair_pair) || _pair_is_created(ppair_pair));

    if (ppair_pair->_pv_first != NULL && ppair_pair->_pv_second != NULL) {
        bool_t b_result = false;

        /* destroy first */
        b_result = _GET_PAIR_FIRST_TYPE_SIZE(ppair_pair);
        _GET_PAIR_FIRST_TYPE_DESTROY_FUNCTION(ppair_pair)(ppair_pair->_pv_first, &b_result);
        assert(b_result);
        free(ppair_pair->_pv_first);
        ppair_pair->_pv_first = NULL;

        /* destroy second */
        b_result = _GET_PAIR_SECOND_TYPE_SIZE(ppair_pair);
        _GET_PAIR_SECOND_TYPE_DESTROY_FUNCTION(ppair_pair)(ppair_pair->_pv_second, &b_result);
        assert(b_result);
        free(ppair_pair->_pv_second);
        ppair_pair->_pv_second = NULL;
    }

    ppair_pair->_bfun_mapkeycompare = NULL;
    ppair_pair->_bfun_mapvaluecompare = NULL;
}
Esempio n. 4
0
/**
 * Test the two pair is have the same type.
 */
bool_t _pair_same_type(const pair_t* cppair_first, const pair_t* cppair_second)
{
    assert(cppair_first != NULL);
    assert(cppair_second != NULL);
    assert(_pair_is_inited(cppair_first) || _pair_is_created(cppair_first));
    assert(_pair_is_inited(cppair_second) || _pair_is_created(cppair_second));

    if (cppair_first == cppair_second) {
        return true;
    }

    return cppair_first->_t_typeinfofirst._pt_type == cppair_second->_t_typeinfofirst._pt_type &&
           cppair_first->_t_typeinfofirst._t_style == cppair_second->_t_typeinfofirst._t_style &&
           cppair_first->_t_typeinfosecond._pt_type == cppair_second->_t_typeinfosecond._pt_type &&
           cppair_first->_t_typeinfosecond._t_style == cppair_second->_t_typeinfosecond._t_style &&
           _type_is_same(cppair_first->_t_typeinfofirst._s_typename, cppair_second->_t_typeinfofirst._s_typename) &&
           _type_is_same(cppair_first->_t_typeinfosecond._s_typename, cppair_second->_t_typeinfosecond._s_typename);
}
Esempio n. 5
0
/**
 * Test the two pair is have the same type.
 */
bool_t _map_same_pair_type_ex(const pair_t* cppair_first, const pair_t* cppair_second)
{
    assert(cppair_first != NULL);
    assert(cppair_second != NULL);
    assert(_pair_is_inited(cppair_first) || _pair_is_created(cppair_first));
    assert(_pair_is_inited(cppair_second) || _pair_is_created(cppair_second));

    if(cppair_first == cppair_second)
    {
        return true;
    }

    return (cppair_first->_t_typeinfofirst._pt_type == cppair_second->_t_typeinfofirst._pt_type) &&
           (cppair_first->_t_typeinfofirst._t_style == cppair_second->_t_typeinfofirst._t_style) &&
           (cppair_first->_t_typeinfosecond._pt_type == cppair_second->_t_typeinfosecond._pt_type) &&
           (cppair_first->_t_typeinfosecond._t_style == cppair_second->_t_typeinfosecond._t_style) &&
           (cppair_first->_bfun_mapkeycompare == cppair_second->_bfun_mapkeycompare) &&
           (cppair_first->_bfun_mapvaluecompare == cppair_second->_bfun_mapvaluecompare) &&
           _type_is_same(cppair_first->_t_typeinfofirst._sz_typename, cppair_second->_t_typeinfofirst._sz_typename) &&
           _type_is_same(cppair_first->_t_typeinfosecond._sz_typename, cppair_second->_t_typeinfosecond._sz_typename);
}
Esempio n. 6
0
/**
 * Initialize hash_multimap container with specific array and compare function.
 */
void hash_multimap_init_copy_array_ex(hash_multimap_t* phmmap_dest, const void* cpv_array, size_t t_count,
    size_t t_bucketcount, ufun_t ufun_hash, bfun_t bfun_compare)
{
    ufun_t ufun_default_hash = NULL;

    assert(phmmap_dest != NULL);
    assert(_pair_is_created(&phmmap_dest->_pair_temp));
    assert(cpv_array != NULL);

    ufun_default_hash = ufun_hash != NULL ? ufun_hash : _hash_multimap_default_hash;
    hash_multimap_init_ex(phmmap_dest, t_bucketcount, ufun_default_hash, bfun_compare);
    hash_multimap_insert_array(phmmap_dest, cpv_array, t_count);
}
Esempio n. 7
0
/**
 * Initialize hash_multimap container with specific range and compare function.
 */
void hash_multimap_init_copy_range_ex(hash_multimap_t* phmmap_dest, iterator_t it_begin, iterator_t it_end,
    size_t t_bucketcount, ufun_t ufun_hash, bfun_t bfun_compare)
{
    ufun_t ufun_default_hash = NULL;

    assert(phmmap_dest != NULL);
    assert(_pair_is_created(&phmmap_dest->_pair_temp));
    assert(iterator_equal(it_begin, it_end) || _iterator_before(it_begin, it_end));

    ufun_default_hash = ufun_hash != NULL ? ufun_hash : _hash_multimap_default_hash;
    hash_multimap_init_ex(phmmap_dest, t_bucketcount, ufun_default_hash, bfun_compare);
    hash_multimap_insert_range(phmmap_dest, it_begin, it_end);
}
Esempio n. 8
0
/**
 * Initialize map container.
 */
void map_init(map_t* pmap_map)
{
    assert(pmap_map != NULL);
    assert(_pair_is_created(&pmap_map->_pair_temp));

    /* initialize the pair */
    pair_init(&pmap_map->_pair_temp);
    /* initialize the tree */
#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_init(&pmap_map->_t_tree, _map_value_compare);
#else
    _rb_tree_init(&pmap_map->_t_tree, _map_value_compare);
#endif
}
Esempio n. 9
0
/**
 * Initialize map container with user define compare function.
 */
void map_init_ex(map_t* pmap_map, binary_function_t bfun_keycompare)
{
    assert(pmap_map != NULL);
    assert(_pair_is_created(&pmap_map->_pair_temp));

    pair_init(&pmap_map->_pair_temp);
    pmap_map->_bfun_keycompare = bfun_keycompare;
    pmap_map->_pair_temp._bfun_mapkeycompare = bfun_keycompare;

#ifdef CSTL_MAP_AVL_TREE
    _avl_tree_init(&pmap_map->_t_tree, _map_value_compare);
#else
    _rb_tree_init(&pmap_map->_t_tree, _map_value_compare);
#endif
}
Esempio n. 10
0
/**
 * Initialize hash_multimap container with user define compare function.
 */
void hash_multimap_init_ex(hash_multimap_t* phmmap_map, size_t t_bucketcount, unary_function_t ufun_hash, binary_function_t bfun_compare)
{
    unary_function_t ufun_default_hash = NULL;

    assert(phmmap_map != NULL);
    assert(_pair_is_created(&phmmap_map->_pair_temp));

    /* initialize the pair */
    pair_init(&phmmap_map->_pair_temp);
    phmmap_map->_bfun_keycompare = bfun_compare;
    phmmap_map->_pair_temp._bfun_mapkeycompare = bfun_compare;
    ufun_default_hash = ufun_hash != NULL ? ufun_hash : _hash_multimap_default_hash;

    /* initialize the hashtable */
    _hashtable_init(&phmmap_map->_t_hashtable, t_bucketcount, ufun_default_hash, _hash_multimap_value_compare);
}
Esempio n. 11
0
/**
 * Initialize hash_multimap container with hash_multimap.
 */
void hash_multimap_init_copy(hash_multimap_t* phmmap_dest, const hash_multimap_t* cphmmap_src)
{
    assert(phmmap_dest != NULL);
    assert(cphmmap_src != NULL);
    assert(_pair_is_created(&phmmap_dest->_pair_temp));
    assert(_pair_is_inited(&cphmmap_src->_pair_temp));

    hash_multimap_init_ex(phmmap_dest, hash_multimap_bucket_count(cphmmap_src), hash_multimap_hash(cphmmap_src), hash_multimap_key_comp(cphmmap_src));
    phmmap_dest->_bfun_keycompare = cphmmap_src->_bfun_keycompare;
    phmmap_dest->_bfun_valuecompare = cphmmap_src->_bfun_valuecompare;
    phmmap_dest->_pair_temp._bfun_mapkeycompare = cphmmap_src->_pair_temp._bfun_mapkeycompare;
    phmmap_dest->_pair_temp._bfun_mapvaluecompare = cphmmap_src->_pair_temp._bfun_mapvaluecompare;
    assert(_hash_multimap_same_pair_type_ex(&phmmap_dest->_pair_temp, &cphmmap_src->_pair_temp));

    if (!hash_multimap_empty(cphmmap_src)) {
        hash_multimap_insert_range(phmmap_dest, hash_multimap_begin(cphmmap_src), hash_multimap_end(cphmmap_src));
    }
}
Esempio n. 12
0
/**
 * Initialize pair container.
 */
void pair_init(pair_t* ppair_pair)
{
    assert(ppair_pair != NULL);
    assert(_pair_is_created(ppair_pair));

    if ((ppair_pair->_pv_first = malloc(_GET_PAIR_FIRST_TYPE_SIZE(ppair_pair))) == NULL) {
        fprintf(stderr, "CSTL FATAL ERROR: memory allocation error!\n");
        exit(EXIT_FAILURE);
    } else {
        memset(ppair_pair->_pv_first, 0x00, _GET_PAIR_FIRST_TYPE_SIZE(ppair_pair));
    }

    if ((ppair_pair->_pv_second = malloc(_GET_PAIR_SECOND_TYPE_SIZE(ppair_pair))) == NULL) {
        fprintf(stderr, "CSTL FATAL ERROR: memory allocation error!\n");
        exit(EXIT_FAILURE);
    } else {
        memset(ppair_pair->_pv_second, 0x00, _GET_PAIR_SECOND_TYPE_SIZE(ppair_pair));
    }

    /* initialize new elements */
    if (_GET_PAIR_FIRST_TYPE_STYLE(ppair_pair) == _TYPE_CSTL_BUILTIN) {
        /* get element type name */
        char s_elemtypename[_TYPE_NAME_SIZE + 1];
        _type_get_elem_typename(_GET_PAIR_FIRST_TYPE_NAME(ppair_pair), s_elemtypename);
        _GET_PAIR_FIRST_TYPE_INIT_FUNCTION(ppair_pair)(ppair_pair->_pv_first, s_elemtypename);
    } else {
        bool_t b_result = _GET_PAIR_FIRST_TYPE_SIZE(ppair_pair);
        _GET_PAIR_FIRST_TYPE_INIT_FUNCTION(ppair_pair)(ppair_pair->_pv_first, &b_result);
        assert(b_result);
    }

    if (_GET_PAIR_SECOND_TYPE_STYLE(ppair_pair) == _TYPE_CSTL_BUILTIN) {
        /* get element type name */
        char s_elemtypename[_TYPE_NAME_SIZE + 1];
        _type_get_elem_typename(_GET_PAIR_SECOND_TYPE_NAME(ppair_pair), s_elemtypename);
        _GET_PAIR_SECOND_TYPE_INIT_FUNCTION(ppair_pair)(ppair_pair->_pv_second, s_elemtypename);
    } else {
        bool_t b_result = _GET_PAIR_SECOND_TYPE_SIZE(ppair_pair);
        _GET_PAIR_SECOND_TYPE_INIT_FUNCTION(ppair_pair)(ppair_pair->_pv_second, &b_result);
        assert(b_result);
    }
}
Esempio n. 13
0
/**
 * Initialize map container with specific range and compare function.
 */
void map_init_copy_range_ex(map_t* pmap_dest, map_iterator_t it_begin, map_iterator_t it_end, binary_function_t bfun_keycompare)
{
    assert(pmap_dest != NULL);
    assert(_pair_is_created(&pmap_dest->_pair_temp));
    assert(_GET_MAP_CONTAINER_TYPE(it_begin) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_begin) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER_TYPE(it_end) == _MAP_CONTAINER);
    assert(_GET_MAP_ITERATOR_TYPE(it_end) == _BIDIRECTIONAL_ITERATOR);
    assert(_GET_MAP_CONTAINER(it_begin) != pmap_dest);
    assert(_GET_MAP_CONTAINER(it_end) != pmap_dest);
    assert(_GET_MAP_CONTAINER(it_begin) == _GET_MAP_CONTAINER(it_end));
    assert(_map_same_pair_type(&pmap_dest->_pair_temp, &_GET_MAP_CONTAINER(it_begin)->_pair_temp));

    /* initialize dest map with src map attribute */
    map_init_ex(pmap_dest, bfun_keycompare);
    /* insert all element from src to dest */
    if(!map_empty(_GET_MAP_CONTAINER(it_begin)))
    {
        map_insert_range(pmap_dest, it_begin, it_end);
    }
}
Esempio n. 14
0
/**
 * Initialize map container with map.
 */
void map_init_copy(map_t* pmap_dest, const map_t* cpmap_src)
{
    assert(pmap_dest != NULL);
    assert(cpmap_src != NULL);
    assert(_pair_is_created(&pmap_dest->_pair_temp));
    assert(_pair_is_inited(&cpmap_src->_pair_temp));

    /* initialize dest map with src map attribute */
    map_init(pmap_dest);
    pmap_dest->_bfun_keycompare = cpmap_src->_bfun_keycompare;
    pmap_dest->_bfun_valuecompare = cpmap_src->_bfun_valuecompare;
    pmap_dest->_pair_temp._bfun_mapkeycompare = cpmap_src->_pair_temp._bfun_mapkeycompare;
    pmap_dest->_pair_temp._bfun_mapvaluecompare = cpmap_src->_pair_temp._bfun_mapvaluecompare;

    assert(_map_same_pair_type_ex(&pmap_dest->_pair_temp, &cpmap_src->_pair_temp));
    /* insert all element from src to dest */
    if(!map_empty(cpmap_src))
    {
        map_insert_range(pmap_dest, map_begin(cpmap_src), map_end(cpmap_src));
    }
}
/**
 * Initialize element auxiliary function
 */
void _hash_multimap_init_elem_auxiliary(hash_multimap_t* phmmap_map, void* pv_elem)
{
    assert(phmmap_map != NULL);
    assert(pv_elem != NULL);
    assert(_pair_is_inited(&phmmap_map->_pair_temp) || _pair_is_created(&phmmap_map->_pair_temp));

    /* initialize new elements */
    if(phmmap_map->_t_hashtable._t_typeinfo._t_style == _TYPE_CSTL_BUILTIN)
    {
        /* get element type name */
        char s_elemtypename[_TYPE_NAME_SIZE + 1];
        _type_get_elem_typename(phmmap_map->_t_hashtable._t_typeinfo._sz_typename, s_elemtypename);

        phmmap_map->_t_hashtable._t_typeinfo._pt_type->_t_typeinit(pv_elem, s_elemtypename);
    }
    else
    {
        bool_t b_result = phmmap_map->_t_hashtable._t_typeinfo._pt_type->_t_typesize;
        phmmap_map->_t_hashtable._t_typeinfo._pt_type->_t_typeinit(pv_elem, &b_result);
        assert(b_result);
    }
}