Example #1
0
/**
 * Inserts an unique element into a hashtable.
 */
_hashtable_iterator_t _hashtable_insert_unique(_hashtable_t* pt_hashtable, const void* cpv_value)
{
    _hashtable_iterator_t it_iter;

    assert(pt_hashtable != NULL);
    assert(cpv_value != NULL);
    assert(_hashtable_is_inited(pt_hashtable));

    if(_hashtable_empty(pt_hashtable))
    {
        return _hashtable_insert_equal(pt_hashtable, cpv_value);
    }
    else
    {
        it_iter = _hashtable_find(pt_hashtable, cpv_value);
        if(!_hashtable_iterator_equal(it_iter, _hashtable_end(pt_hashtable)))
        {
            return _hashtable_end(pt_hashtable);
        }
        else
        {
            return _hashtable_insert_equal(pt_hashtable, cpv_value);
        }
    }
}
Example #2
0
/**
 * Inserts an range into a hashtable.
 */
void _hashtable_insert_equal_range(_hashtable_t* pt_hashtable, iterator_t it_begin, iterator_t it_end)
{
    iterator_t it_iter;

    assert(pt_hashtable != NULL);
    assert(_hashtable_is_inited(pt_hashtable));
    assert(_hashtable_same_iterator_type(pt_hashtable, it_begin));
    assert(_hashtable_same_iterator_type(pt_hashtable, it_end));
    assert(iterator_equal(it_begin, it_end) || _iterator_before(it_begin, it_end));

    for (it_iter = it_begin; !iterator_equal(it_iter, it_end); it_iter = iterator_next(it_iter)) {
        _hashtable_insert_equal(pt_hashtable, _iterator_get_pointer_ignore_cstr(it_iter));
    }
}
Example #3
0
/**
 * Inserts an array into a hashtable.
 */
void _hashtable_insert_equal_array(_hashtable_t* pt_hashtable, const void* cpv_array, size_t t_count)
{
    size_t i = 0;

    assert(pt_hashtable != NULL);
    assert(_hashtable_is_inited(pt_hashtable));
    assert(cpv_array != NULL);

    /*
     * Copy the elements from src array to dest hashtable
     * The array of c builtin and user define or cstl builtin are different,
     * the elements of c builtin array are element itself, but the elements of 
     * c string, user define or cstl are pointer of element.
     */
    if (strncmp(_GET_HASHTABLE_TYPE_BASENAME(pt_hashtable), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) {
        /*
         * We need built a string_t for c string element.
         */
        string_t* pstr_elem = create_string();
        assert(pstr_elem != NULL);
        string_init(pstr_elem);
        for (i = 0; i < t_count; ++i) {
            string_assign_cstr(pstr_elem, *((const char**)cpv_array + i));
            _hashtable_insert_equal(pt_hashtable, pstr_elem);
        }
        string_destroy(pstr_elem);
    } else if (_GET_HASHTABLE_TYPE_STYLE(pt_hashtable) == _TYPE_C_BUILTIN) {
        for (i = 0; i < t_count; ++i) {
            _hashtable_insert_equal(pt_hashtable, (unsigned char*)cpv_array + i * _GET_HASHTABLE_TYPE_SIZE(pt_hashtable));
        }
    } else {
        for (i = 0; i < t_count; ++i) {
            _hashtable_insert_equal(pt_hashtable, *((void**)cpv_array + i));
        }
    }
}
Example #4
0
/**
 * Inserts an range into a hashtable.
 */
void _hashtable_insert_equal_range(
    _hashtable_t* pt_hashtable, _hashtable_iterator_t it_begin, _hashtable_iterator_t it_end)
{
    _hashtable_iterator_t it_iter;

    assert(pt_hashtable != NULL);
    assert(_hashtable_is_inited(pt_hashtable));
    assert(_hashtable_same_hashtable_iterator_type(pt_hashtable, it_begin));
    assert(_hashtable_same_hashtable_iterator_type(pt_hashtable, it_end));
    assert(_hashtable_iterator_equal(it_begin, it_end) || _hashtable_iterator_before(it_begin, it_end));

    for(it_iter = it_begin; !_hashtable_iterator_equal(it_iter, it_end); it_iter = _hashtable_iterator_next(it_iter))
    {
        _hashtable_insert_equal(pt_hashtable, ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_iter))->_pby_data);
    }
}
Example #5
0
/**
 * Initialize hashtable container with hashtable.
 */
void _hashtable_init_copy(_hashtable_t* pt_dest, const _hashtable_t* cpt_src)
{
    _hashtable_iterator_t it_iter;

    assert(pt_dest != NULL);
    assert(cpt_src != NULL);
    assert(_hashtable_is_created(pt_dest));
    assert(_hashtable_is_inited(cpt_src));
    assert(_hashtable_same_type(pt_dest, cpt_src));

    /* initialize the dest hashtable with src hashtable attribute */
    _hashtable_init(pt_dest, _hashtable_bucket_count(cpt_src), cpt_src->_ufun_hash, cpt_src->_bfun_compare);
    /* insert node from src to dest */
    for (it_iter = _hashtable_begin(cpt_src);
         !_hashtable_iterator_equal(it_iter, _hashtable_end(cpt_src));
         it_iter = _hashtable_iterator_next(it_iter)) {
        _hashtable_insert_equal(pt_dest, _hashtable_iterator_get_pointer_ignore_cstr(it_iter));
    }
}
Example #6
0
/**
 * Assign hashtable container.
 */
void _hashtable_assign(_hashtable_t* pt_dest, const _hashtable_t* cpt_src)
{
    _hashtable_iterator_t it_iter;

    assert(pt_dest != NULL);
    assert(cpt_src != NULL);
    assert(_hashtable_is_inited(pt_dest));
    assert(_hashtable_is_inited(cpt_src));
    assert(_hashtable_same_type_ex(pt_dest, cpt_src));

    /* clear all elements */
    _hashtable_clear(pt_dest);
    /* insert node from src to dest */
    for (it_iter = _hashtable_begin(cpt_src);
         !_hashtable_iterator_equal(it_iter, _hashtable_end(cpt_src));
         it_iter = _hashtable_iterator_next(it_iter)) {
        _hashtable_insert_equal(pt_dest, _hashtable_iterator_get_pointer_ignore_cstr(it_iter));
    }
}
Example #7
0
/**
 * Inserts an unique element into a hash_multimap.
 */
hash_multimap_iterator_t hash_multimap_insert(hash_multimap_t* phmmap_map, const pair_t* cppair_pair)
{
    hash_multimap_iterator_t it_iter;

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

    ((pair_t*)cppair_pair)->_bfun_mapkeycompare = phmmap_map->_bfun_keycompare;
    ((pair_t*)cppair_pair)->_bfun_mapvaluecompare = phmmap_map->_bfun_valuecompare;
    assert(_hash_multimap_same_pair_type_ex(&phmmap_map->_pair_temp, cppair_pair));

    /* insert int hashtable */
    it_iter = _hashtable_insert_equal(&phmmap_map->_t_hashtable, cppair_pair);

    _GET_CONTAINER(it_iter) = phmmap_map;
    _GET_HASH_MULTIMAP_CONTAINER_TYPE(it_iter) = _HASH_MULTIMAP_CONTAINER;
    _GET_HASH_MULTIMAP_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR;

    return it_iter;
}