/** * Inserts an range of unique element into a hashtable. */ void _hashtable_insert_unique_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_unique(pt_hashtable, _iterator_get_pointer_ignore_cstr(it_iter)); } }
/** * Inserts an array of unique element into a hashtable. */ void _hashtable_insert_unique_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_unique(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_unique(pt_hashtable, (unsigned char*)cpv_array + i * _GET_HASHTABLE_TYPE_SIZE(pt_hashtable)); } } else { for (i = 0; i < t_count; ++i) { _hashtable_insert_unique(pt_hashtable, *((void**)cpv_array + i)); } } }
/** * Inserts an range of unique element into a hashtable. */ void _hashtable_insert_unique_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_unique(pt_hashtable, ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_iter))->_pby_data); } }