/** * Tests if the two pair are equal. */ bool_t pair_equal(const pair_t* cppair_first, const pair_t* cppair_second) { bool_t b_less = false; bool_t b_greater = false; assert(cppair_first != NULL); assert(cppair_second != NULL); assert(_pair_is_inited(cppair_first)); assert(_pair_is_inited(cppair_second)); assert(_pair_same_type(cppair_first, cppair_second)); if (cppair_first == cppair_second) { return true; } /* compare first */ b_less = b_greater = _GET_PAIR_FIRST_TYPE_SIZE(cppair_first); _GET_PAIR_FIRST_TYPE_LESS_FUNCTION(cppair_first)(cppair_first->_pv_first, cppair_second->_pv_first, &b_less); _GET_PAIR_FIRST_TYPE_LESS_FUNCTION(cppair_first)(cppair_second->_pv_first, cppair_first->_pv_first, &b_greater); if (b_less || b_greater) { return false; } /* compare second */ b_less = b_greater = _GET_PAIR_SECOND_TYPE_SIZE(cppair_first); _GET_PAIR_SECOND_TYPE_LESS_FUNCTION(cppair_first)(cppair_first->_pv_second, cppair_second->_pv_second, &b_less); _GET_PAIR_SECOND_TYPE_LESS_FUNCTION(cppair_first)(cppair_second->_pv_second, cppair_first->_pv_second, &b_greater); if (b_less || b_greater) { return false; } return true; }
/** * Inserts an unique element into a map with hint position. */ map_iterator_t map_insert_hint(map_t* pmap_map, map_iterator_t it_hint, const pair_t* cppair_pair) { assert(pmap_map != NULL); assert(cppair_pair != NULL); assert(_pair_is_inited(&pmap_map->_pair_temp)); assert(_pair_is_inited(cppair_pair)); assert(_GET_MAP_CONTAINER_TYPE(it_hint) == _MAP_CONTAINER); assert(_GET_MAP_ITERATOR_TYPE(it_hint) == _BIDIRECTIONAL_ITERATOR); assert(_GET_MAP_CONTAINER(it_hint) == pmap_map); /* set key less function and value less function */ ((pair_t*)cppair_pair)->_bfun_mapkeycompare = pmap_map->_bfun_keycompare; ((pair_t*)cppair_pair)->_bfun_mapvaluecompare = pmap_map->_bfun_valuecompare; assert(_map_same_pair_type_ex(&pmap_map->_pair_temp, cppair_pair)); #ifdef CSTL_MAP_AVL_TREE it_hint = _avl_tree_insert_unique(&pmap_map->_t_tree, cppair_pair); #else it_hint = _rb_tree_insert_unique(&pmap_map->_t_tree, cppair_pair); #endif _GET_CONTAINER(it_hint) = pmap_map; _GET_MAP_CONTAINER_TYPE(it_hint) = _MAP_CONTAINER; _GET_MAP_ITERATOR_TYPE(it_hint) = _BIDIRECTIONAL_ITERATOR; return it_hint; }
/** * Swap the datas of first hash_multimap and second hash_multimap. */ void hash_multimap_swap(hash_multimap_t* phmmap_first, hash_multimap_t* phmmap_second) { assert(phmmap_first != NULL); assert(phmmap_second != NULL); assert(_pair_is_inited(&phmmap_first->_pair_temp)); assert(_pair_is_inited(&phmmap_second->_pair_temp)); assert(_hash_multimap_same_pair_type_ex(&phmmap_first->_pair_temp, &phmmap_second->_pair_temp)); _hashtable_swap(&phmmap_first->_t_hashtable, &phmmap_second->_t_hashtable); }
/** * Tests if the first hash_multimap is greater than or equal to the second hash_multimap. */ bool_t hash_multimap_greater_equal(const hash_multimap_t* cphmmap_first, const hash_multimap_t* cphmmap_second) { assert(cphmmap_first != NULL); assert(cphmmap_second != NULL); assert(_pair_is_inited(&cphmmap_first->_pair_temp)); assert(_pair_is_inited(&cphmmap_second->_pair_temp)); assert(_hash_multimap_same_pair_type_ex(&cphmmap_first->_pair_temp, &cphmmap_second->_pair_temp)); return _hashtable_greater_equal(&cphmmap_first->_t_hashtable, &cphmmap_second->_t_hashtable); }
/** * Assign hash_multimap container. */ void hash_multimap_assign(hash_multimap_t* phmmap_dest, const hash_multimap_t* cphmmap_src) { assert(phmmap_dest != NULL); assert(cphmmap_src != NULL); assert(_pair_is_inited(&phmmap_dest->_pair_temp)); assert(_pair_is_inited(&cphmmap_src->_pair_temp)); assert(_hash_multimap_same_pair_type_ex(&phmmap_dest->_pair_temp, &cphmmap_src->_pair_temp)); hash_multimap_clear(phmmap_dest); if (!hash_multimap_empty(cphmmap_src)) { hash_multimap_insert_range(phmmap_dest, hash_multimap_begin(cphmmap_src), hash_multimap_end(cphmmap_src)); } }
/** * Tests if the two hash_multimap are not equal. */ bool_t hash_multimap_not_equal(const hash_multimap_t* cphmmap_first, const hash_multimap_t* cphmmap_second) { assert(cphmmap_first != NULL); assert(cphmmap_second != NULL); assert(_pair_is_inited(&cphmmap_first->_pair_temp)); assert(_pair_is_inited(&cphmmap_second->_pair_temp)); if (cphmmap_first->_bfun_keycompare != cphmmap_second->_bfun_keycompare) { return true; } return _hashtable_not_equal(&cphmmap_first->_t_hashtable, &cphmmap_second->_t_hashtable); }
/** * Tests if the first map is greater than or equal to the second map. */ bool_t map_greater_equal(const map_t* cpmap_first, const map_t* cpmap_second) { assert(cpmap_first != NULL); assert(cpmap_second != NULL); assert(_pair_is_inited(&cpmap_first->_pair_temp)); assert(_pair_is_inited(&cpmap_second->_pair_temp)); assert(_map_same_pair_type_ex(&cpmap_first->_pair_temp, &cpmap_second->_pair_temp)); #ifdef CSTL_MAP_AVL_TREE return _avl_tree_greater_equal(&cpmap_first->_t_tree, &cpmap_second->_t_tree); #else return _rb_tree_greater_equal(&cpmap_first->_t_tree, &cpmap_second->_t_tree); #endif }
/** * Swap the datas of first map and second map. */ void map_swap(map_t* pmap_first, map_t* pmap_second) { assert(pmap_first != NULL); assert(pmap_second != NULL); assert(_pair_is_inited(&pmap_first->_pair_temp)); assert(_pair_is_inited(&pmap_second->_pair_temp)); assert(_map_same_pair_type_ex(&pmap_first->_pair_temp, &pmap_second->_pair_temp)); #ifdef CSTL_MAP_AVL_TREE _avl_tree_swap(&pmap_first->_t_tree, &pmap_second->_t_tree); #else _rb_tree_swap(&pmap_first->_t_tree, &pmap_second->_t_tree); #endif }
/** * 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); }
/** * Assign map container. */ void map_assign(map_t* pmap_dest, const map_t* cpmap_src) { assert(pmap_dest != NULL); assert(cpmap_src != NULL); assert(_pair_is_inited(&pmap_dest->_pair_temp)); assert(_pair_is_inited(&cpmap_src->_pair_temp)); assert(_map_same_pair_type_ex(&pmap_dest->_pair_temp, &cpmap_src->_pair_temp)); /* clear */ map_clear(pmap_dest); /* 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)); } }
/** * Return the hash function of value. */ unary_function_t hash_multimap_hash(const hash_multimap_t* cphmmap_map) { assert(cphmmap_map != NULL); assert(_pair_is_inited(&cphmmap_map->_pair_temp)); return _hashtable_hash(&cphmmap_map->_t_hashtable); }
/** * 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; }
/** * 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; }
/** * Resize bucket count of hash map. */ void hash_multimap_resize(hash_multimap_t* phmmap_map, size_t t_resize) { assert(phmmap_map != NULL); assert(_pair_is_inited(&phmmap_map->_pair_temp)); _hashtable_resize(&phmmap_map->_t_hashtable, t_resize); }
/** * Get the bucket count of elements int the hash_multimap. */ size_t hash_multimap_bucket_count(const hash_multimap_t* cphmmap_map) { assert(cphmmap_map != NULL); assert(_pair_is_inited(&cphmmap_map->_pair_temp)); return _hashtable_bucket_count(&cphmmap_map->_t_hashtable); }
/** * Test if an hash_multimap is empty. */ bool_t hash_multimap_empty(const hash_multimap_t* cphmmap_map) { assert(cphmmap_map != NULL); assert(_pair_is_inited(&cphmmap_map->_pair_temp)); return _hashtable_empty(&cphmmap_map->_t_hashtable); }
/** * Erases all the elements of an hash_multimap. */ void hash_multimap_clear(hash_multimap_t* phmmap_map) { assert(phmmap_map != NULL); assert(_pair_is_inited(&phmmap_map->_pair_temp)); _hashtable_clear(&phmmap_map->_t_hashtable); }
/** * Tests if the two map are not equal. */ bool_t map_not_equal(const map_t* cpmap_first, const map_t* cpmap_second) { assert(cpmap_first != NULL); assert(cpmap_second != NULL); assert(_pair_is_inited(&cpmap_first->_pair_temp)); assert(_pair_is_inited(&cpmap_second->_pair_temp)); if(cpmap_first->_bfun_keycompare != cpmap_second->_bfun_keycompare) { return true; } #ifdef CSTL_MAP_AVL_TREE return _avl_tree_not_equal(&cpmap_first->_t_tree, &cpmap_second->_t_tree); #else return _rb_tree_not_equal(&cpmap_first->_t_tree, &cpmap_second->_t_tree); #endif }
/** * 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); }
/** * Erase an element in an hash_multimap from specificed position. */ void hash_multimap_erase_pos(hash_multimap_t* phmmap_map, hash_multimap_iterator_t it_pos) { assert(phmmap_map != NULL); assert(_pair_is_inited(&phmmap_map->_pair_temp)); assert(_GET_HASH_MULTIMAP_CONTAINER_TYPE(it_pos) == _HASH_MULTIMAP_CONTAINER); assert(_GET_HASH_MULTIMAP_ITERATOR_TYPE(it_pos) == _BIDIRECTIONAL_ITERATOR); assert(_GET_HASH_MULTIMAP_CONTAINER(it_pos) == phmmap_map); _hashtable_erase_pos(&phmmap_map->_t_hashtable, it_pos); }
/** * Erases all the elements of an map. */ void map_clear(map_t* pmap_map) { assert(pmap_map != NULL); assert(_pair_is_inited(&pmap_map->_pair_temp)); #ifdef CSTL_MAP_AVL_TREE _avl_tree_clear(&pmap_map->_t_tree); #else _rb_tree_clear(&pmap_map->_t_tree); #endif }
/** * Return the compare function of value. */ binary_function_t hash_multimap_value_comp(const hash_multimap_t* cphmmap_map) { #ifdef NDEBUG void* pv_avoidwarning = (void*)cphmmap_map; pv_avoidwarning = NULL; #endif assert(cphmmap_map != NULL); assert(_pair_is_inited(&cphmmap_map->_pair_temp)); return _hash_multimap_value_compare; }
/** * Return the compare function of key. */ bfun_t hash_multimap_key_comp(const hash_multimap_t* cphmmap_map) { assert(cphmmap_map != NULL); assert(_pair_is_inited(&cphmmap_map->_pair_temp)); if (cphmmap_map->_bfun_keycompare != NULL) { return cphmmap_map->_bfun_keycompare; } else { return _GET_HASH_MULTIMAP_FIRST_TYPE_LESS_FUNCTION(cphmmap_map); } }
/** * Get the maximum number of elements int the map. */ size_t map_max_size(const map_t* cpmap_map) { assert(cpmap_map != NULL); assert(_pair_is_inited(&cpmap_map->_pair_temp)); #ifdef CSTL_MAP_AVL_TREE return _avl_tree_max_size(&cpmap_map->_t_tree); #else return _rb_tree_max_size(&cpmap_map->_t_tree); #endif }
/** * Assignment for the first element of pair. */ void _pair_make_first(pair_t* ppair_pair, ...) { va_list val_elemlist; assert(ppair_pair != NULL); assert(_pair_is_inited(ppair_pair)); va_start(val_elemlist, ppair_pair); _type_get_varg_value(&ppair_pair->_t_typeinfofirst, val_elemlist, ppair_pair->_pv_first); va_end(val_elemlist); }
/** * Access pair second element. */ void* pair_second(const pair_t* cppair_pair) { assert(cppair_pair != NULL); assert(_pair_is_inited(cppair_pair)); /* char* */ if (strncmp(_GET_PAIR_SECOND_TYPE_BASENAME(cppair_pair), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) { return (void*)basic_string_c_str((basic_string_t*)cppair_pair->_pv_second); } else { return cppair_pair->_pv_second; } }
/** * 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); }
/** * Return the number of specific elements in an map */ size_t _map_count_varg(const map_t* cpmap_map, va_list val_elemlist) { assert(cpmap_map != NULL); assert(_pair_is_inited(&cpmap_map->_pair_temp)); _type_get_varg_value(&((map_t*)cpmap_map)->_pair_temp._t_typeinfofirst, val_elemlist, cpmap_map->_pair_temp._pv_first); #ifdef CSTL_MAP_AVL_TREE return _avl_tree_count(&cpmap_map->_t_tree, &cpmap_map->_pair_temp); #else return _rb_tree_count(&cpmap_map->_t_tree, &cpmap_map->_pair_temp); #endif }
/** * 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; }
/** * Erase an element from a map that match a specified element. */ size_t _map_erase_varg(map_t* pmap_map, va_list val_elemlist) { assert(pmap_map != NULL); assert(_pair_is_inited(&pmap_map->_pair_temp)); /* get key */ _type_get_varg_value(&pmap_map->_pair_temp._t_typeinfofirst, val_elemlist, pmap_map->_pair_temp._pv_first); #ifdef CSTL_MAP_AVL_TREE return _avl_tree_erase(&pmap_map->_t_tree, &pmap_map->_pair_temp); #else return _rb_tree_erase(&pmap_map->_t_tree, &pmap_map->_pair_temp); #endif }