/** * Destroy vector container auxiliary function. */ void _vector_destroy_auxiliary(vector_t* pvec_vector) { vector_iterator_t it_iter; vector_iterator_t it_begin; vector_iterator_t it_end; bool_t b_result = false; assert(pvec_vector != NULL); assert(_vector_is_inited(pvec_vector) || _vector_is_created(pvec_vector)); /* destroy all elements */ it_begin = vector_begin(pvec_vector); it_end = vector_end(pvec_vector); for (it_iter = it_begin; !iterator_equal(it_iter, it_end); it_iter = iterator_next(it_iter)) { b_result = _GET_VECTOR_TYPE_SIZE(pvec_vector); _GET_VECTOR_TYPE_DESTROY_FUNCTION(pvec_vector)(_VECTOR_ITERATOR_COREPOS(it_iter), &b_result); assert(b_result); } /* free vector memory */ if (pvec_vector->_pby_start != NULL) { _alloc_deallocate(&pvec_vector->_t_allocator, pvec_vector->_pby_start, _GET_VECTOR_TYPE_SIZE(pvec_vector), (pvec_vector->_pby_endofstorage - pvec_vector->_pby_start) / _GET_VECTOR_TYPE_SIZE(pvec_vector)); } _alloc_destroy(&pvec_vector->_t_allocator); pvec_vector->_pby_start = NULL; pvec_vector->_pby_finish = NULL; pvec_vector->_pby_endofstorage = NULL; }
/** * Destroy slist container auxiliary function. */ void _slist_destroy_auxiliary(slist_t* pslist_slist) { _slistnode_t* pt_node = NULL; bool_t b_result = false; /* test the pslist_slist is valid */ assert(pslist_slist != NULL); assert(_slist_is_inited(pslist_slist) || _slist_is_created(pslist_slist)); /* _alloc_deallocate all nodes in slist */ while (pslist_slist->_t_head._pt_next != NULL) { /* take out each node from the slist */ pt_node = pslist_slist->_t_head._pt_next; pslist_slist->_t_head._pt_next = pt_node->_pt_next; pt_node->_pt_next = NULL; /* destroy the node itself */ b_result = _GET_SLIST_TYPE_SIZE(pslist_slist); _GET_SLIST_TYPE_DESTROY_FUNCTION(pslist_slist)(pt_node->_pby_data, &b_result); assert(b_result); _alloc_deallocate(&pslist_slist->_t_allocator, pt_node, _SLIST_NODE_SIZE(_GET_SLIST_TYPE_SIZE(pslist_slist)), 1); pt_node = NULL; } /* _alloc_deallocate the allocator */ _alloc_destroy(&pslist_slist->_t_allocator); }
/** * Destroy avl tree container auxiliary function. */ void _avl_tree_destroy_auxiliary(_avl_tree_t* pt_avl_tree) { assert(pt_avl_tree != NULL); assert(_avl_tree_is_inited(pt_avl_tree) || _avl_tree_is_created(pt_avl_tree)); /* destroy all elements */ pt_avl_tree->_t_avlroot._pt_parent = _avl_tree_destroy_subtree(pt_avl_tree, pt_avl_tree->_t_avlroot._pt_parent); assert(pt_avl_tree->_t_avlroot._pt_parent == NULL); pt_avl_tree->_t_avlroot._pt_left = &pt_avl_tree->_t_avlroot; pt_avl_tree->_t_avlroot._pt_right = &pt_avl_tree->_t_avlroot; /* destroy allocator */ _alloc_destroy(&pt_avl_tree->_t_allocator); pt_avl_tree->_t_nodecount = 0; pt_avl_tree->_t_compare = NULL; }