mirror of
https://github.com/boostorg/intrusive.git
synced 2025-08-03 14:34:44 +02:00
Added increase and decrease to size traits in order to make code cleaner.
[SVN r82844]
This commit is contained in:
@@ -132,6 +132,12 @@ struct size_holder
|
|||||||
void increment()
|
void increment()
|
||||||
{ ++size_; }
|
{ ++size_; }
|
||||||
|
|
||||||
|
void increase(SizeType n)
|
||||||
|
{ size_ += n; }
|
||||||
|
|
||||||
|
void decrease(SizeType n)
|
||||||
|
{ size_ -= n; }
|
||||||
|
|
||||||
SizeType size_;
|
SizeType size_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -152,6 +158,12 @@ struct size_holder<false, SizeType>
|
|||||||
|
|
||||||
void increment()
|
void increment()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void increase(SizeType)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void decrease(SizeType)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class KeyValueCompare, class Container>
|
template<class KeyValueCompare, class Container>
|
||||||
|
@@ -645,7 +645,7 @@ class list_impl
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(constant_time_size){
|
if(constant_time_size){
|
||||||
this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n);
|
this->priv_size_traits().decrease(n);
|
||||||
}
|
}
|
||||||
node_algorithms::unlink(b.pointed_node(), e.pointed_node());
|
node_algorithms::unlink(b.pointed_node(), e.pointed_node());
|
||||||
return e.unconst();
|
return e.unconst();
|
||||||
@@ -886,11 +886,11 @@ class list_impl
|
|||||||
void splice(const_iterator p, list_impl& x)
|
void splice(const_iterator p, list_impl& x)
|
||||||
{
|
{
|
||||||
if(!x.empty()){
|
if(!x.empty()){
|
||||||
size_traits &thist = this->priv_size_traits();
|
|
||||||
size_traits &xt = x.priv_size_traits();
|
|
||||||
node_algorithms::transfer
|
node_algorithms::transfer
|
||||||
(p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
|
(p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
|
||||||
thist.set_size(thist.get_size() + xt.get_size());
|
size_traits &thist = this->priv_size_traits();
|
||||||
|
size_traits &xt = x.priv_size_traits();
|
||||||
|
thist.increase(xt.get_size());
|
||||||
xt.set_size(size_type(0));
|
xt.set_size(size_type(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -953,12 +953,12 @@ class list_impl
|
|||||||
{
|
{
|
||||||
if(n){
|
if(n){
|
||||||
if(constant_time_size){
|
if(constant_time_size){
|
||||||
size_traits &thist = this->priv_size_traits();
|
|
||||||
size_traits &xt = x.priv_size_traits();
|
|
||||||
BOOST_INTRUSIVE_INVARIANT_ASSERT(n == std::distance(f, e));
|
BOOST_INTRUSIVE_INVARIANT_ASSERT(n == std::distance(f, e));
|
||||||
node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
|
node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
|
||||||
thist.set_size(thist.get_size() + n);
|
size_traits &thist = this->priv_size_traits();
|
||||||
xt.set_size(xt.get_size() - n);
|
size_traits &xt = x.priv_size_traits();
|
||||||
|
thist.increase(n);
|
||||||
|
xt.decrease(n);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
|
node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
|
||||||
|
@@ -819,8 +819,23 @@ class slist_impl
|
|||||||
template<class Iterator>
|
template<class Iterator>
|
||||||
void insert_after(const_iterator prev_p, Iterator f, Iterator l)
|
void insert_after(const_iterator prev_p, Iterator f, Iterator l)
|
||||||
{
|
{
|
||||||
for (; f != l; ++f)
|
//Insert first nodes avoiding cache and size checks
|
||||||
prev_p = this->insert_after(prev_p, *f);
|
size_type count = 0;
|
||||||
|
node_ptr prev_n(prev_p.pointed_node());
|
||||||
|
for (; f != l; ++f, ++count){
|
||||||
|
const node_ptr n = get_real_value_traits().to_node_ptr(*f);
|
||||||
|
if(safemode_or_autounlink)
|
||||||
|
BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n));
|
||||||
|
node_algorithms::link_after(prev_n, n);
|
||||||
|
prev_n = n;
|
||||||
|
}
|
||||||
|
//Now fix special cases if needed
|
||||||
|
if(cache_last && (this->get_last_node() == prev_p.pointed_node())){
|
||||||
|
this->set_last_node(prev_n);
|
||||||
|
}
|
||||||
|
if(constant_time_size){
|
||||||
|
this->priv_size_traits().increase(count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! <b>Requires</b>: value must be an lvalue and p must point to an element
|
//! <b>Requires</b>: value must be an lvalue and p must point to an element
|
||||||
@@ -932,7 +947,7 @@ class slist_impl
|
|||||||
}
|
}
|
||||||
node_algorithms::unlink_after(bfp, lp);
|
node_algorithms::unlink_after(bfp, lp);
|
||||||
if(constant_time_size){
|
if(constant_time_size){
|
||||||
this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n);
|
this->priv_size_traits().decrease(n);
|
||||||
}
|
}
|
||||||
return l.unconst();
|
return l.unconst();
|
||||||
}
|
}
|
||||||
@@ -1209,7 +1224,7 @@ class slist_impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n);
|
node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n);
|
||||||
this->priv_size_traits().set_size(this->priv_size_traits().get_size() + x.priv_size_traits().get_size());
|
this->priv_size_traits().increase(x.priv_size_traits().get_size());
|
||||||
x.priv_size_traits().set_size(size_type(0));
|
x.priv_size_traits().set_size(size_type(0));
|
||||||
if(l) *l = last_x;
|
if(l) *l = last_x;
|
||||||
}
|
}
|
||||||
@@ -1278,8 +1293,8 @@ class slist_impl
|
|||||||
this->priv_splice_after
|
this->priv_splice_after
|
||||||
(prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node());
|
(prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node());
|
||||||
if(constant_time_size){
|
if(constant_time_size){
|
||||||
this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n);
|
this->priv_size_traits().increase(n);
|
||||||
x.priv_size_traits().set_size(x.priv_size_traits().get_size() - n);
|
x.priv_size_traits().decrease(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1834,7 +1849,7 @@ class slist_impl
|
|||||||
BOOST_INTRUSIVE_INVARIANT_ASSERT(size_type(std::distance(iterator(f, this), iterator(before_l, this)))+1 == n);
|
BOOST_INTRUSIVE_INVARIANT_ASSERT(size_type(std::distance(iterator(f, this), iterator(before_l, this)))+1 == n);
|
||||||
this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l);
|
this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l);
|
||||||
if(constant_time_size){
|
if(constant_time_size){
|
||||||
this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n);
|
this->priv_size_traits().increase(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user