Example #1
0
/**
 * Create hashtable container.
 */
_hashtable_t* _create_hashtable(const char* s_typename)
{
    _hashtable_t* pt_hashtable = NULL;

    if ((pt_hashtable = (_hashtable_t*)malloc(sizeof(_hashtable_t))) == NULL) {
        return NULL;
    }

    if (!_create_hashtable_auxiliary(pt_hashtable, s_typename)) {
        free(pt_hashtable);
        return NULL;
    }

    return pt_hashtable;
}
/**
 * Create hash_multimap container auxiliary function.
 */
bool_t _create_hash_multimap_auxiliary(hash_multimap_t* phmmap_map, const char* s_typename)
{
    char s_typenameex[_TYPE_NAME_SIZE + 1];

    assert(phmmap_map != NULL);
    assert(s_typename != NULL);

    if(!_create_pair_auxiliary(&phmmap_map->_pair_temp, s_typename))
    {
        return false;
    }

    memset(s_typenameex, '\0', _TYPE_NAME_SIZE + 1);
    strncpy(s_typenameex, "pair_t", _TYPE_NAME_SIZE);
    strncat(s_typenameex, "<", _TYPE_NAME_SIZE);
    strncat(s_typenameex, s_typename, _TYPE_NAME_SIZE - 8); /* 8 is length of "pair_t<>" */
    strncat(s_typenameex, ">", _TYPE_NAME_SIZE);

    phmmap_map->_bfun_keycompare = NULL;
    phmmap_map->_bfun_valuecompare = NULL;

    return _create_hashtable_auxiliary(&phmmap_map->_t_hashtable, s_typenameex);
}