/** * Get data value pointer referenced by iterator. */ const void* _hashtable_iterator_get_pointer(_hashtable_iterator_t it_iter) { assert(_hashtable_iterator_belong_to_hashtable(_HASHTABLE_ITERATOR_HASHTABLE(it_iter), it_iter)); assert(!_hashtable_iterator_equal(it_iter, _hashtable_end(_HASHTABLE_ITERATOR_HASHTABLE(it_iter)))); /* char* */ if(strncmp(_GET_HASHTABLE_TYPE_BASENAME(_HASHTABLE_ITERATOR_HASHTABLE(it_iter)), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) { return (char*)string_c_str((string_t*)((_hashnode_t*)_HASHTABLE_ITERATOR_COREPOS(it_iter))->_pby_data); } else { return ((_hashnode_t*)_HASHTABLE_ITERATOR_COREPOS(it_iter))->_pby_data; } }
/** * Get data value referenced by iterator. */ void _hashtable_iterator_get_value(_hashtable_iterator_t it_iter, void* pv_value) { assert(pv_value != NULL); assert(_hashtable_iterator_belong_to_hashtable(_HASHTABLE_ITERATOR_HASHTABLE(it_iter), it_iter)); assert(!_hashtable_iterator_equal(it_iter, _hashtable_end(_HASHTABLE_ITERATOR_HASHTABLE(it_iter)))); /* char* */ if(strncmp(_GET_HASHTABLE_TYPE_BASENAME(_HASHTABLE_ITERATOR_HASHTABLE(it_iter)), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) { *(char**)pv_value = (char*)string_c_str((string_t*)((_hashnode_t*)_HASHTABLE_ITERATOR_COREPOS(it_iter))->_pby_data); } else { bool_t b_result = _GET_HASHTABLE_TYPE_SIZE(_HASHTABLE_ITERATOR_HASHTABLE(it_iter)); _GET_HASHTABLE_TYPE_COPY_FUNCTION(_HASHTABLE_ITERATOR_HASHTABLE(it_iter))( pv_value, ((_hashnode_t*)_HASHTABLE_ITERATOR_COREPOS(it_iter))->_pby_data, &b_result); assert(b_result); } }
/** * 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)); } } }