reimplemented random_access_index internal, cross-index splice in linear time

This commit is contained in:
joaquintides 2021-08-16 10:20:51 +02:00
parent b590797738
commit 536c6e91ac
2 changed files with 35 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* Copyright 2003-2018 Joaquin M Lopez Munoz.
/* Copyright 2003-2021 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -169,6 +169,25 @@ struct random_access_index_node_impl
}
}
static ptr_pointer gather_nulls(
ptr_pointer pbegin,ptr_pointer pend,ptr_pointer x)
{
for(ptr_pointer p=pbegin;p!=x;++p){
if(*p){
*pbegin=*p;
(*pbegin)->up()=pbegin;
++pbegin;
}
}
for(ptr_pointer p=pend;p!=x;){
if(*--p){
*--pend=*p;
(*pend)->up()=pend;
}
}
return pbegin;
}
private:
ptr_pointer up_;
};

View File

@ -1140,9 +1140,21 @@ private:
template<typename Iterator>
void internal_splice(iterator position,Iterator first,Iterator last)
{
index_node_type* pn=position.get_node();
while(first!=last){
relocate(pn,static_cast<index_node_type*>((first++).get_node()));
/* null out [first, last) positions in ptrs array */
for(Iterator it=first;it!=last;++it){
*(static_cast<index_node_type*>(it.get_node())->up())=0;
}
node_impl_ptr_pointer pp=node_impl_type::gather_nulls(
ptrs.begin(),ptrs.end(),
static_cast<index_node_type*>(position.get_node())->up());
/* relink [first, last) */
for(Iterator it=first;it!=last;++it,++pp){
*pp=static_cast<index_node_type*>(it.get_node());
(*pp)->up()=pp;
}
}