small changes in map insert and erase
This commit is contained in:
@@ -16,7 +16,8 @@ MP_TPL MP::
|
||||
, _comp(comp)
|
||||
, _allocator(alloc) {
|
||||
|
||||
_init_sentinel();
|
||||
_sentinel = _allocator_sentinel.allocate(1);
|
||||
_allocator_sentinel.construct(_sentinel, sentinel<value_type>());
|
||||
}
|
||||
MP_TPL template < typename InputIt > MP::
|
||||
map (InputIt first, InputIt last, const key_compare& comp, const allocator_type& alloc)
|
||||
@@ -25,7 +26,8 @@ MP_TPL template < typename InputIt > MP::
|
||||
, _comp(comp)
|
||||
, _allocator(alloc) {
|
||||
|
||||
_init_sentinel();
|
||||
_sentinel = _allocator_sentinel.allocate(1);
|
||||
_allocator_sentinel.construct(_sentinel, sentinel<value_type>());
|
||||
insert(first, last);
|
||||
}
|
||||
MP_TPL MP::
|
||||
@@ -35,7 +37,8 @@ MP_TPL MP::
|
||||
, _comp(src._comp)
|
||||
, _allocator(src._allocator) {
|
||||
|
||||
_init_sentinel();
|
||||
_sentinel = _allocator_sentinel.allocate(1);
|
||||
_allocator_sentinel.construct(_sentinel, sentinel<value_type>());
|
||||
*this = src;
|
||||
}
|
||||
// destructor --------------------------------
|
||||
@@ -128,7 +131,7 @@ MP_TPL typename MP::mapped_type& MP::
|
||||
return (n->value.second);
|
||||
}
|
||||
|
||||
n = insert( ft::make_pair(key, mapped_type()) ).first.getNode();
|
||||
n = insert( ft::make_pair(key, mapped_type()) ).first.get_node();
|
||||
|
||||
return (n->value.second);
|
||||
}
|
||||
@@ -193,33 +196,33 @@ MP_TPL template < typename InputIt > void MP::
|
||||
MP_TPL void MP::
|
||||
erase(iterator pos) {
|
||||
|
||||
node<value_type>* n = pos.getNode();
|
||||
node<value_type>* n = pos.get_node();
|
||||
node<value_type>* n_del = NULL;
|
||||
node<value_type>* next;
|
||||
|
||||
if (n->left && n->right)
|
||||
if (!(n->left && n->right))
|
||||
{
|
||||
if (n->left)
|
||||
n_del = _swap_nodes(n, n->left);
|
||||
else if (n->right)
|
||||
n_del = _swap_nodes(n, n->right);
|
||||
else
|
||||
n_del = _swap_nodes(n, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
next = n->right->min();
|
||||
|
||||
if (next->up != n)
|
||||
{
|
||||
_subtree_shift(next, next->right);
|
||||
_swap_nodes(next, next->right);
|
||||
next->right = n->right;
|
||||
next->right->up = next;
|
||||
}
|
||||
n_del = _subtree_shift(n, next);
|
||||
n_del = _swap_nodes(n, next);
|
||||
next->left = n->left;
|
||||
next->left->up = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n->left)
|
||||
n_del = _subtree_shift(n, n->left);
|
||||
else if (n->right)
|
||||
n_del = _subtree_shift(n, n->right);
|
||||
else
|
||||
n_del = _subtree_shift(n, NULL);
|
||||
}
|
||||
|
||||
_allocator_node.destroy(n);
|
||||
_allocator_node.deallocate(n, 1);
|
||||
@@ -403,14 +406,8 @@ MP_TPL typename MP::allocator_type MP::
|
||||
/*********************
|
||||
* private functions :
|
||||
*********************/
|
||||
MP_TPL void MP::
|
||||
_init_sentinel() {
|
||||
|
||||
_sentinel = _allocator_sentinel.allocate(1);
|
||||
_allocator_sentinel.construct(_sentinel, sentinel<value_type>());
|
||||
}
|
||||
MP_TPL node<typename MP::value_type>* MP::
|
||||
_subtree_shift(node<value_type>* n_old, node<value_type>* n_new) {
|
||||
_swap_nodes(node<value_type>* n_old, node<value_type>* n_new) {
|
||||
|
||||
node<value_type>* p = n_old->up;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user