/** * Test the type that saved in the hashtable container and referenced by it_iter are same. */ bool_t _hashtable_same_hashtable_iterator_type_ex(const _hashtable_t* cpt_hashtable, _hashtable_iterator_t it_iter) { assert(cpt_hashtable != NULL); assert(_HASHTABLE_ITERATOR_HASHTABLE(it_iter) != NULL); return _hashtable_same_type_ex(cpt_hashtable, _HASHTABLE_ITERATOR_HASHTABLE(it_iter)); }
/** * Tests if the two rb tree are equal. */ bool_t _hashtable_equal(const _hashtable_t* cpt_first, const _hashtable_t* cpt_second) { _hashtable_iterator_t it_first; _hashtable_iterator_t it_second; bool_t b_less = false; bool_t b_greater = false; assert(cpt_first != NULL); assert(cpt_second != NULL); assert(_hashtable_is_inited(cpt_first)); assert(_hashtable_is_inited(cpt_second)); if(cpt_first == cpt_second) { return true; } /* check type */ if(!_hashtable_same_type_ex(cpt_first, cpt_second)) { return false; } /* check size or bucket count*/ if(_hashtable_size(cpt_first) != _hashtable_size(cpt_second) || _hashtable_bucket_count(cpt_first) != _hashtable_bucket_count(cpt_second)) { return false; } /* check each element */ for(it_first = _hashtable_begin(cpt_first), it_second = _hashtable_begin(cpt_second); !_hashtable_iterator_equal(it_first, _hashtable_end(cpt_first)) && !_hashtable_iterator_equal(it_second, _hashtable_end(cpt_second)); it_first = _hashtable_iterator_next(it_first), it_second = _hashtable_iterator_next(it_second)) { b_less = b_greater = _GET_HASHTABLE_TYPE_SIZE(cpt_first); _GET_HASHTABLE_TYPE_LESS_FUNCTION(cpt_first)( ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_first))->_pby_data, ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_second))->_pby_data, &b_less); _GET_HASHTABLE_TYPE_LESS_FUNCTION(cpt_first)( ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_second))->_pby_data, ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_first))->_pby_data, &b_greater); if(b_less || b_greater) { return false; } } assert(_hashtable_iterator_equal(it_first, _hashtable_end(cpt_first)) && _hashtable_iterator_equal(it_second, _hashtable_end(cpt_second))); return true; }
/** * Assign hashtable container. */ void _hashtable_assign(_hashtable_t* pt_dest, const _hashtable_t* cpt_src) { 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 */ if(!_hashtable_empty(cpt_src)) { _hashtable_insert_equal_range(pt_dest, _hashtable_begin(cpt_src), _hashtable_end(cpt_src)); } }
/** * Tests if the first rb tree is less than the second rb tree. */ bool_t _hashtable_less(const _hashtable_t* cpt_first, const _hashtable_t* cpt_second) { _hashtable_iterator_t it_first; _hashtable_iterator_t it_second; bool_t b_less = false; bool_t b_greater = false; assert(cpt_first != NULL); assert(cpt_second != NULL); assert(_hashtable_is_inited(cpt_first)); assert(_hashtable_is_inited(cpt_second)); assert(_hashtable_same_type_ex(cpt_first, cpt_second)); /* check vector bucket count */ if(vector_size(&cpt_first->_vec_bucket) == vector_size(&cpt_second->_vec_bucket)) { /* check each element */ for(it_first = _hashtable_begin(cpt_first), it_second = _hashtable_begin(cpt_second); !_hashtable_iterator_equal(it_first, _hashtable_end(cpt_first)) && !_hashtable_iterator_equal(it_second, _hashtable_end(cpt_second)); it_first = _hashtable_iterator_next(it_first), it_second = _hashtable_iterator_next(it_second)) { b_less = _GET_HASHTABLE_TYPE_SIZE(cpt_first); _GET_HASHTABLE_TYPE_LESS_FUNCTION(cpt_first)( ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_first))->_pby_data, ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_second))->_pby_data, &b_less); if(b_less) { return true; } b_greater = _GET_HASHTABLE_TYPE_SIZE(cpt_first); _GET_HASHTABLE_TYPE_LESS_FUNCTION(cpt_first)( ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_second))->_pby_data, ((_hashnode_t*)_GET_HASHTABLE_COREPOS(it_first))->_pby_data, &b_greater); if(b_greater) { return false; } } } return _hashtable_size(cpt_first) < _hashtable_size(cpt_second) ? true : false; }
/** * Swap the datas of first hashtable and second hashtable. */ void _hashtable_swap(_hashtable_t* pt_first, _hashtable_t* pt_second) { _hashtable_t t_swap; assert(pt_first != NULL); assert(pt_second != NULL); assert(_hashtable_is_inited(pt_first)); assert(_hashtable_is_inited(pt_second)); assert(_hashtable_same_type_ex(pt_first, pt_second)); if (_hashtable_equal(pt_first, pt_second)) { return; } t_swap = *pt_first; *pt_first = *pt_second; *pt_second = t_swap; }
/** * 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)); } }