From a3772374011b9566ede798379da2c456bc9ede57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 10 Apr 2012 20:14:31 +0000 Subject: [PATCH] Changed ordered insertion function and added comments [SVN r77895] --- include/boost/container/detail/flat_tree.hpp | 52 +++++++++++++++++--- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/include/boost/container/detail/flat_tree.hpp b/include/boost/container/detail/flat_tree.hpp index 1cbe8da..960a491 100644 --- a/include/boost/container/detail/flat_tree.hpp +++ b/include/boost/container/detail/flat_tree.hpp @@ -301,7 +301,6 @@ class flat_tree return ret; } - iterator insert_equal(const value_type& val) { iterator i = this->upper_bound(KeyOfValue()(val)); @@ -339,14 +338,14 @@ class flat_tree iterator insert_equal(const_iterator pos, const value_type& val) { insert_commit_data data; - priv_insert_equal_prepare(pos, val, data); + this->priv_insert_equal_prepare(pos, val, data); return priv_insert_commit(data, val); } iterator insert_equal(const_iterator pos, BOOST_RV_REF(value_type) mval) { insert_commit_data data; - priv_insert_equal_prepare(pos, mval, data); + this->priv_insert_equal_prepare(pos, mval, data); return priv_insert_commit(data, boost::move(mval)); } @@ -362,7 +361,15 @@ class flat_tree { typedef typename std::iterator_traits::iterator_category ItCat; - priv_insert_equal(first, last, ItCat()); + this->priv_insert_equal(first, last, ItCat()); + } + + template + void insert_equal(ordered_range_t, InIt first, InIt last) + { + typedef typename + std::iterator_traits::iterator_category ItCat; + this->priv_insert_equal(ordered_range_t(), first, last, ItCat()); } #ifdef BOOST_CONTAINER_PERFECT_FORWARDING @@ -406,7 +413,7 @@ class flat_tree { value_type &&val = value_type(boost::forward(args)...); insert_commit_data data; - priv_insert_equal_prepare(hint, val, data); + this->priv_insert_equal_prepare(hint, val, data); return priv_insert_commit(data, boost::move(val)); } @@ -466,7 +473,7 @@ class flat_tree BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _) BOOST_PP_RPAREN_IF(n); \ value_type &val = vval; \ insert_commit_data data; \ - priv_insert_equal_prepare(hint, val, data); \ + this->priv_insert_equal_prepare(hint, val, data); \ return priv_insert_commit(data, boost::move(val)); \ } \ //! @@ -746,10 +753,39 @@ class flat_tree return std::pair(first, first); } - template - void priv_insert_equal(FwdIt first, FwdIt last, std::forward_iterator_tag) + template + void priv_insert_equal(ordered_range_t, BidirIt first, BidirIt last, std::bidirectional_iterator_tag) { size_type len = static_cast(std::distance(first, last)); + const size_type BurstSize = 16; + size_type positions[BurstSize]; + + while(len){ + const size_type burst = len < BurstSize ? len : BurstSize; + len -= burst; + const iterator beg(this->cbegin()); + iterator pos; + for(size_type i = 0; i != burst; ++i){ + pos = this->upper_bound(KeyOfValue()(*first)); + positions[i] = static_cast(pos - beg); + ++first; + } + this->m_data.m_vect.insert_ordered_at(burst, positions + burst, first); + } + } + + template + void priv_insert_equal_forward(ordered_range_t, FwdIt first, FwdIt last, std::forward_iterator_tag) + { this->priv_insert_equal(first, last, std::forward_iterator_tag()); } + + template + void priv_insert_equal(ordered_range_t, InIt first, InIt last, std::input_iterator_tag) + { this->priv_insert_equal(first, last, std::input_iterator_tag()); } + + template + void priv_insert_equal_forward(FwdIt first, FwdIt last, std::forward_iterator_tag) + { + const size_type len = static_cast(std::distance(first, last)); this->reserve(this->size()+len); this->priv_insert_equal(first, last, std::input_iterator_tag()); }