bool_t multimap_empty(const multimap_t* cpt_multimap) { assert(cpt_multimap != NULL); #ifdef CSTL_MULTIMAP_AVL_TREE return _avl_tree_empty(_GET_MULTIMAP_AVL_TREE(cpt_multimap)); #else return _rb_tree_empty(_GET_MULTIMAP_RB_TREE(cpt_multimap)); #endif }
/** * Test if an set is empty. */ bool_t set_empty(const set_t* cpset_set) { assert(cpset_set != NULL); #ifdef CSTL_SET_AVL_TREE return _avl_tree_empty(&cpset_set->_t_tree); #else return _rb_tree_empty(&cpset_set->_t_tree); #endif }
/** * Test if an multiset is empty. */ bool_t multiset_empty(const multiset_t* cpmset_mset) { assert(cpmset_mset != NULL); #ifdef CSTL_MULTISET_AVL_TREE return _avl_tree_empty(&cpmset_mset->_t_tree); #else return _rb_tree_empty(&cpmset_mset->_t_tree); #endif }
/** * Test if an map is empty. */ bool_t map_empty(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_empty(&cpmap_map->_t_tree); #else return _rb_tree_empty(&cpmap_map->_t_tree); #endif }
/** * Insert the value into subtree. */ _rbnode_t* _rb_tree_insert_rbnode(_rb_tree_t* pt_rb_tree, const void* cpv_value) { _rbnode_t* pt_parent = NULL; _rbnode_t* pt_cur = NULL; bool_t b_result = false; bool_t b_less = false; assert(pt_rb_tree != NULL); assert(cpv_value != NULL); assert(_rb_tree_is_inited(pt_rb_tree)); /* if the rb tree is empty */ if(_rb_tree_empty(pt_rb_tree)) { /* allocat a new root */ pt_cur = _alloc_allocate( (_alloc_t*)&pt_rb_tree->_t_allocator, _RB_TREE_NODE_SIZE(_GET_RB_TREE_TYPE_SIZE(pt_rb_tree)), 1); assert(pt_cur != NULL); _rb_tree_init_elem_auxiliary(pt_rb_tree, pt_cur); /* set its color is BLACK */ pt_cur->_pt_left = pt_cur->_pt_right = NULL; pt_cur->_t_color = BLACK; pt_cur->_pt_parent = (_rbnode_t*)&pt_rb_tree->_t_rbroot; b_result = _GET_RB_TREE_TYPE_SIZE(pt_rb_tree); _GET_RB_TREE_TYPE_COPY_FUNCTION(pt_rb_tree)(pt_cur->_pby_data, cpv_value, &b_result); assert(b_result); /* insert the node */ pt_rb_tree->_t_rbroot._pt_parent = pt_cur; } else { pt_parent = pt_rb_tree->_t_rbroot._pt_parent; b_less = _GET_RB_TREE_TYPE_SIZE(pt_rb_tree); _rb_tree_elem_compare_auxiliary(pt_rb_tree, cpv_value, pt_parent->_pby_data, &b_less); if(b_less) { pt_cur = pt_parent->_pt_left; } else { pt_cur = pt_parent->_pt_right; } /* from the root to insert position */ while(pt_cur != NULL) { /* next current position */ pt_parent = pt_cur; b_less = _GET_RB_TREE_TYPE_SIZE(pt_rb_tree); _rb_tree_elem_compare_auxiliary(pt_rb_tree, cpv_value, pt_parent->_pby_data, &b_less); if(b_less) { pt_cur = pt_parent->_pt_left; } else { pt_cur = pt_parent->_pt_right; } } /* allocate new node */ pt_cur = _alloc_allocate( (_alloc_t*)&pt_rb_tree->_t_allocator, _RB_TREE_NODE_SIZE(_GET_RB_TREE_TYPE_SIZE(pt_rb_tree)), 1); assert(pt_cur != NULL); _rb_tree_init_elem_auxiliary(pt_rb_tree, pt_cur); pt_cur->_pt_left = pt_cur->_pt_right = NULL; pt_cur->_t_color = RED; pt_cur->_pt_parent = pt_parent; b_result = _GET_RB_TREE_TYPE_SIZE(pt_rb_tree); _GET_RB_TREE_TYPE_COPY_FUNCTION(pt_rb_tree)(pt_cur->_pby_data, cpv_value, &b_result); assert(b_result); if(b_less) { assert(pt_parent->_pt_left == NULL); pt_parent->_pt_left = pt_cur; } else { assert(pt_parent->_pt_right == NULL); pt_parent->_pt_right = pt_cur; } if(_rb_tree_get_color(pt_parent) == RED) { _rb_tree_rebalance(pt_rb_tree, pt_cur); } } return pt_cur; }