mirror of
https://github.com/BlackMATov/flat.hpp.git
synced 2025-12-13 01:36:27 +07:00
add ctors from sorted ranges optimization
This commit is contained in:
@@ -72,140 +72,140 @@ namespace flat_hpp
|
|||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_map(InputIter first, InputIter last) {
|
flat_map(InputIter first, InputIter last) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_map(sorted_range_t, InputIter first, InputIter last) {
|
flat_map(sorted_range_t, InputIter first, InputIter last) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_map(sorted_unique_range_t, InputIter first, InputIter last) {
|
flat_map(sorted_unique_range_t, InputIter first, InputIter last) {
|
||||||
insert(sorted_unique_range, first, last);
|
from_range_(sorted_unique_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_map(InputIter first, InputIter last, const Compare& c)
|
flat_map(InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_map(sorted_range_t, InputIter first, InputIter last, const Compare& c)
|
flat_map(sorted_range_t, InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_map(sorted_unique_range_t, InputIter first, InputIter last, const Compare& c)
|
flat_map(sorted_unique_range_t, InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_unique_range, first, last);
|
from_range_(sorted_unique_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_map(InputIter first, InputIter last, const Allocator& a)
|
flat_map(InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_map(sorted_range_t, InputIter first, InputIter last, const Allocator& a)
|
flat_map(sorted_range_t, InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_map(sorted_unique_range_t, InputIter first, InputIter last, const Allocator& a)
|
flat_map(sorted_unique_range_t, InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_unique_range, first, last);
|
from_range_(sorted_unique_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter , typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_map(InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_map(InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter , typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_map(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_map(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter , typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_map(sorted_unique_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_map(sorted_unique_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_unique_range, first, last);
|
from_range_(sorted_unique_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_map(std::initializer_list<value_type> ilist) {
|
flat_map(std::initializer_list<value_type> ilist) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_map(sorted_range_t, std::initializer_list<value_type> ilist) {
|
flat_map(sorted_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_map(sorted_unique_range_t, std::initializer_list<value_type> ilist) {
|
flat_map(sorted_unique_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_unique_range, ilist);
|
from_range_(sorted_unique_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_map(std::initializer_list<value_type> ilist, const Compare& c)
|
flat_map(std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_map(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
flat_map(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_map(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
flat_map(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_unique_range, ilist);
|
from_range_(sorted_unique_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_map(std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_map(std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_map(sorted_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_map(sorted_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_map(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_map(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_unique_range, ilist);
|
from_range_(sorted_unique_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_map(std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_map(std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_map(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_map(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_map(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_map(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_unique_range, ilist);
|
from_range_(sorted_unique_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
@@ -401,32 +401,20 @@ namespace flat_hpp
|
|||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
void insert(InputIter first, InputIter last) {
|
void insert(InputIter first, InputIter last) {
|
||||||
const auto mid_iter = data_.insert(data_.end(), first, last);
|
insert_range_(first, last);
|
||||||
std::sort(mid_iter, data_.end(), value_comp());
|
|
||||||
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
|
||||||
data_.erase(
|
|
||||||
std::unique(data_.begin(), data_.end(),
|
|
||||||
detail::eq_compare<value_compare>(value_comp())),
|
|
||||||
data_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
void insert(sorted_range_t, InputIter first, InputIter last) {
|
void insert(sorted_range_t, InputIter first, InputIter last) {
|
||||||
assert(detail::is_sorted(first, last, value_comp()));
|
insert_range_(sorted_range, first, last);
|
||||||
const auto mid_iter = data_.insert(data_.end(), first, last);
|
|
||||||
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
|
||||||
data_.erase(
|
|
||||||
std::unique(data_.begin(), data_.end(),
|
|
||||||
detail::eq_compare<value_compare>(value_comp())),
|
|
||||||
data_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(std::initializer_list<value_type> ilist) {
|
void insert(std::initializer_list<value_type> ilist) {
|
||||||
insert(ilist.begin(), ilist.end());
|
insert_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(sorted_range_t, std::initializer_list<value_type> ilist) {
|
void insert(sorted_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_range, ilist.begin(), ilist.end());
|
insert_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename... Args >
|
template < typename... Args >
|
||||||
@@ -611,6 +599,57 @@ namespace flat_hpp
|
|||||||
value_compare value_comp() const {
|
value_compare value_comp() const {
|
||||||
return value_compare(key_comp());
|
return value_compare(key_comp());
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
std::sort(data_.begin(), data_.end(), value_comp());
|
||||||
|
data_.erase(
|
||||||
|
std::unique(data_.begin(), data_.end(),
|
||||||
|
detail::eq_compare<value_compare>(value_comp())),
|
||||||
|
data_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(sorted_range_t, Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
assert(detail::is_sorted(first, last, value_comp()));
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
data_.erase(
|
||||||
|
std::unique(data_.begin(), data_.end(),
|
||||||
|
detail::eq_compare<value_compare>(value_comp())),
|
||||||
|
data_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(sorted_unique_range_t, Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
assert(detail::is_sorted_unique(first, last, value_comp()));
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
template < typename Iter >
|
||||||
|
void insert_range_(Iter first, Iter last) {
|
||||||
|
const auto mid_iter = data_.insert(data_.end(), first, last);
|
||||||
|
std::sort(mid_iter, data_.end(), value_comp());
|
||||||
|
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
||||||
|
data_.erase(
|
||||||
|
std::unique(data_.begin(), data_.end(),
|
||||||
|
detail::eq_compare<value_compare>(value_comp())),
|
||||||
|
data_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void insert_range_(sorted_range_t, Iter first, Iter last) {
|
||||||
|
assert(detail::is_sorted(first, last, value_comp()));
|
||||||
|
const auto mid_iter = data_.insert(data_.end(), first, last);
|
||||||
|
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
||||||
|
data_.erase(
|
||||||
|
std::unique(data_.begin(), data_.end(),
|
||||||
|
detail::eq_compare<value_compare>(value_comp())),
|
||||||
|
data_.end());
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
container_type data_;
|
container_type data_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -72,94 +72,94 @@ namespace flat_hpp
|
|||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_multimap(InputIter first, InputIter last) {
|
flat_multimap(InputIter first, InputIter last) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_multimap(sorted_range_t, InputIter first, InputIter last) {
|
flat_multimap(sorted_range_t, InputIter first, InputIter last) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_multimap(InputIter first, InputIter last, const Compare& c)
|
flat_multimap(InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_multimap(sorted_range_t, InputIter first, InputIter last, const Compare& c)
|
flat_multimap(sorted_range_t, InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_multimap(InputIter first, InputIter last, const Allocator& a)
|
flat_multimap(InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_multimap(sorted_range_t, InputIter first, InputIter last, const Allocator& a)
|
flat_multimap(sorted_range_t, InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter , typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_multimap(InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_multimap(InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter , typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_multimap(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_multimap(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_multimap(std::initializer_list<value_type> ilist) {
|
flat_multimap(std::initializer_list<value_type> ilist) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_multimap(sorted_range_t, std::initializer_list<value_type> ilist) {
|
flat_multimap(sorted_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_multimap(std::initializer_list<value_type> ilist, const Compare& c)
|
flat_multimap(std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_multimap(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
flat_multimap(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_multimap(std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_multimap(std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_multimap(sorted_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_multimap(sorted_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_multimap(std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_multimap(std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_multimap(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_multimap(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
@@ -351,24 +351,20 @@ namespace flat_hpp
|
|||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
void insert(InputIter first, InputIter last) {
|
void insert(InputIter first, InputIter last) {
|
||||||
const auto mid_iter = data_.insert(data_.end(), first, last);
|
insert_range_(first, last);
|
||||||
std::sort(mid_iter, data_.end(), value_comp());
|
|
||||||
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
void insert(sorted_range_t, InputIter first, InputIter last) {
|
void insert(sorted_range_t, InputIter first, InputIter last) {
|
||||||
assert(detail::is_sorted(first, last, value_comp()));
|
insert_range_(sorted_range, first, last);
|
||||||
const auto mid_iter = data_.insert(data_.end(), first, last);
|
|
||||||
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(std::initializer_list<value_type> ilist) {
|
void insert(std::initializer_list<value_type> ilist) {
|
||||||
insert(ilist.begin(), ilist.end());
|
insert_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(sorted_range_t, std::initializer_list<value_type> ilist) {
|
void insert(sorted_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_range, ilist.begin(), ilist.end());
|
insert_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename... Args >
|
template < typename... Args >
|
||||||
@@ -553,6 +549,34 @@ namespace flat_hpp
|
|||||||
value_compare value_comp() const {
|
value_compare value_comp() const {
|
||||||
return value_compare(key_comp());
|
return value_compare(key_comp());
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
std::sort(data_.begin(), data_.end(), value_comp());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(sorted_range_t, Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
assert(detail::is_sorted(first, last, value_comp()));
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
template < typename Iter >
|
||||||
|
void insert_range_(Iter first, Iter last) {
|
||||||
|
const auto mid_iter = data_.insert(data_.end(), first, last);
|
||||||
|
std::sort(mid_iter, data_.end(), value_comp());
|
||||||
|
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void insert_range_(sorted_range_t, Iter first, Iter last) {
|
||||||
|
assert(detail::is_sorted(first, last, value_comp()));
|
||||||
|
const auto mid_iter = data_.insert(data_.end(), first, last);
|
||||||
|
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
container_type data_;
|
container_type data_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,94 +54,94 @@ namespace flat_hpp
|
|||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_multiset(InputIter first, InputIter last) {
|
flat_multiset(InputIter first, InputIter last) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_multiset(sorted_range_t, InputIter first, InputIter last) {
|
flat_multiset(sorted_range_t, InputIter first, InputIter last) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_multiset(InputIter first, InputIter last, const Compare& c)
|
flat_multiset(InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_multiset(sorted_range_t, InputIter first, InputIter last, const Compare& c)
|
flat_multiset(sorted_range_t, InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_multiset(InputIter first, InputIter last, const Allocator& a)
|
flat_multiset(InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_multiset(sorted_range_t, InputIter first, InputIter last, const Allocator& a)
|
flat_multiset(sorted_range_t, InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_multiset(InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_multiset(InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_multiset(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_multiset(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_multiset(std::initializer_list<value_type> ilist) {
|
flat_multiset(std::initializer_list<value_type> ilist) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_multiset(sorted_range_t, std::initializer_list<value_type> ilist) {
|
flat_multiset(sorted_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_multiset(std::initializer_list<value_type> ilist, const Compare& c)
|
flat_multiset(std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_multiset(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
flat_multiset(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_multiset(std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_multiset(std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_multiset(sorted_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_multiset(sorted_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_multiset(std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_multiset(std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_multiset(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_multiset(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
@@ -279,24 +279,20 @@ namespace flat_hpp
|
|||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
void insert(InputIter first, InputIter last) {
|
void insert(InputIter first, InputIter last) {
|
||||||
const auto mid_iter = data_.insert(data_.end(), first, last);
|
insert_range_(first, last);
|
||||||
std::sort(mid_iter, data_.end(), value_comp());
|
|
||||||
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
void insert(sorted_range_t, InputIter first, InputIter last) {
|
void insert(sorted_range_t, InputIter first, InputIter last) {
|
||||||
assert(detail::is_sorted(first, last, value_comp()));
|
insert_range_(sorted_range, first, last);
|
||||||
const auto mid_iter = data_.insert(data_.end(), first, last);
|
|
||||||
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(std::initializer_list<value_type> ilist) {
|
void insert(std::initializer_list<value_type> ilist) {
|
||||||
insert(ilist.begin(), ilist.end());
|
insert_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(sorted_range_t, std::initializer_list<value_type> ilist) {
|
void insert(sorted_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_range, ilist.begin(), ilist.end());
|
insert_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename... Args >
|
template < typename... Args >
|
||||||
@@ -469,6 +465,34 @@ namespace flat_hpp
|
|||||||
value_compare value_comp() const {
|
value_compare value_comp() const {
|
||||||
return value_compare(key_comp());
|
return value_compare(key_comp());
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
std::sort(data_.begin(), data_.end(), key_comp());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(sorted_range_t, Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
assert(detail::is_sorted(first, last, key_comp()));
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
template < typename Iter >
|
||||||
|
void insert_range_(Iter first, Iter last) {
|
||||||
|
const auto mid_iter = data_.insert(data_.end(), first, last);
|
||||||
|
std::sort(mid_iter, data_.end(), key_comp());
|
||||||
|
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void insert_range_(sorted_range_t, Iter first, Iter last) {
|
||||||
|
assert(detail::is_sorted(first, last, key_comp()));
|
||||||
|
const auto mid_iter = data_.insert(data_.end(), first, last);
|
||||||
|
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
container_type data_;
|
container_type data_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,140 +54,140 @@ namespace flat_hpp
|
|||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_set(InputIter first, InputIter last) {
|
flat_set(InputIter first, InputIter last) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_set(sorted_range_t, InputIter first, InputIter last) {
|
flat_set(sorted_range_t, InputIter first, InputIter last) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_set(sorted_unique_range_t, InputIter first, InputIter last) {
|
flat_set(sorted_unique_range_t, InputIter first, InputIter last) {
|
||||||
insert(sorted_unique_range, first, last);
|
from_range_(sorted_unique_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_set(InputIter first, InputIter last, const Compare& c)
|
flat_set(InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_set(sorted_range_t, InputIter first, InputIter last, const Compare& c)
|
flat_set(sorted_range_t, InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
flat_set(sorted_unique_range_t, InputIter first, InputIter last, const Compare& c)
|
flat_set(sorted_unique_range_t, InputIter first, InputIter last, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_unique_range, first, last);
|
from_range_(sorted_unique_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_set(InputIter first, InputIter last, const Allocator& a)
|
flat_set(InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_set(sorted_range_t, InputIter first, InputIter last, const Allocator& a)
|
flat_set(sorted_range_t, InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_set(sorted_unique_range_t, InputIter first, InputIter last, const Allocator& a)
|
flat_set(sorted_unique_range_t, InputIter first, InputIter last, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_unique_range, first, last);
|
from_range_(sorted_unique_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_set(InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_set(InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(first, last);
|
from_range_(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_set(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_set(sorted_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_range, first, last);
|
from_range_(sorted_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter, typename Allocator >
|
template < typename InputIter, typename Allocator >
|
||||||
flat_set(sorted_unique_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
flat_set(sorted_unique_range_t, InputIter first, InputIter last, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_unique_range, first, last);
|
from_range_(sorted_unique_range, first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_set(std::initializer_list<value_type> ilist) {
|
flat_set(std::initializer_list<value_type> ilist) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_set(sorted_range_t, std::initializer_list<value_type> ilist) {
|
flat_set(sorted_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_set(sorted_unique_range_t, std::initializer_list<value_type> ilist) {
|
flat_set(sorted_unique_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_unique_range, ilist);
|
from_range_(sorted_unique_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_set(std::initializer_list<value_type> ilist, const Compare& c)
|
flat_set(std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_set(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
flat_set(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat_set(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
flat_set(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Compare& c)
|
||||||
: base_type(c) {
|
: base_type(c) {
|
||||||
insert(sorted_unique_range, ilist);
|
from_range_(sorted_unique_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_set(std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_set(std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_set(sorted_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_set(sorted_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_set(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
flat_set(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Allocator& a)
|
||||||
: data_(a) {
|
: data_(a) {
|
||||||
insert(sorted_unique_range, ilist);
|
from_range_(sorted_unique_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_set(std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_set(std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(ilist);
|
from_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_set(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_set(sorted_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_range, ilist);
|
from_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
flat_set(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
flat_set(sorted_unique_range_t, std::initializer_list<value_type> ilist, const Compare& c, const Allocator& a)
|
||||||
: base_type(c)
|
: base_type(c)
|
||||||
, data_(a) {
|
, data_(a) {
|
||||||
insert(sorted_unique_range, ilist);
|
from_range_(sorted_unique_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Allocator >
|
template < typename Allocator >
|
||||||
@@ -329,32 +329,20 @@ namespace flat_hpp
|
|||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
void insert(InputIter first, InputIter last) {
|
void insert(InputIter first, InputIter last) {
|
||||||
const auto mid_iter = data_.insert(data_.end(), first, last);
|
insert_range_(first, last);
|
||||||
std::sort(mid_iter, data_.end(), value_comp());
|
|
||||||
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
|
||||||
data_.erase(
|
|
||||||
std::unique(data_.begin(), data_.end(),
|
|
||||||
detail::eq_compare<value_compare>(value_comp())),
|
|
||||||
data_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename InputIter >
|
template < typename InputIter >
|
||||||
void insert(sorted_range_t, InputIter first, InputIter last) {
|
void insert(sorted_range_t, InputIter first, InputIter last) {
|
||||||
assert(detail::is_sorted(first, last, value_comp()));
|
insert_range_(sorted_range, first, last);
|
||||||
const auto mid_iter = data_.insert(data_.end(), first, last);
|
|
||||||
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
|
||||||
data_.erase(
|
|
||||||
std::unique(data_.begin(), data_.end(),
|
|
||||||
detail::eq_compare<value_compare>(value_comp())),
|
|
||||||
data_.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(std::initializer_list<value_type> ilist) {
|
void insert(std::initializer_list<value_type> ilist) {
|
||||||
insert(ilist.begin(), ilist.end());
|
insert_range_(ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(sorted_range_t, std::initializer_list<value_type> ilist) {
|
void insert(sorted_range_t, std::initializer_list<value_type> ilist) {
|
||||||
insert(sorted_range, ilist.begin(), ilist.end());
|
insert_range_(sorted_range, ilist.begin(), ilist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename... Args >
|
template < typename... Args >
|
||||||
@@ -527,6 +515,57 @@ namespace flat_hpp
|
|||||||
value_compare value_comp() const {
|
value_compare value_comp() const {
|
||||||
return value_compare(key_comp());
|
return value_compare(key_comp());
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
std::sort(data_.begin(), data_.end(), key_comp());
|
||||||
|
data_.erase(
|
||||||
|
std::unique(data_.begin(), data_.end(),
|
||||||
|
detail::eq_compare<key_compare>(key_comp())),
|
||||||
|
data_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(sorted_range_t, Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
assert(detail::is_sorted(first, last, key_comp()));
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
data_.erase(
|
||||||
|
std::unique(data_.begin(), data_.end(),
|
||||||
|
detail::eq_compare<key_compare>(key_comp())),
|
||||||
|
data_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void from_range_(sorted_unique_range_t, Iter first, Iter last) {
|
||||||
|
assert(data_.empty());
|
||||||
|
assert(detail::is_sorted_unique(first, last, key_comp()));
|
||||||
|
data_.insert(data_.end(), first, last);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
template < typename Iter >
|
||||||
|
void insert_range_(Iter first, Iter last) {
|
||||||
|
const auto mid_iter = data_.insert(data_.end(), first, last);
|
||||||
|
std::sort(mid_iter, data_.end(), key_comp());
|
||||||
|
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
||||||
|
data_.erase(
|
||||||
|
std::unique(data_.begin(), data_.end(),
|
||||||
|
detail::eq_compare<key_compare>(key_comp())),
|
||||||
|
data_.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename Iter >
|
||||||
|
void insert_range_(sorted_range_t, Iter first, Iter last) {
|
||||||
|
assert(detail::is_sorted(first, last, key_comp()));
|
||||||
|
const auto mid_iter = data_.insert(data_.end(), first, last);
|
||||||
|
std::inplace_merge(data_.begin(), mid_iter, data_.end());
|
||||||
|
data_.erase(
|
||||||
|
std::unique(data_.begin(), data_.end(),
|
||||||
|
detail::eq_compare<key_compare>(key_comp())),
|
||||||
|
data_.end());
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
container_type data_;
|
container_type data_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -200,6 +200,15 @@ TEST_CASE("flat_map") {
|
|||||||
s3 = {{0,1}, {1,2}};
|
s3 = {{0,1}, {1,2}};
|
||||||
REQUIRE(s3 == map_t{{0,1}, {1,2}});
|
REQUIRE(s3 == map_t{{0,1}, {1,2}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto s0 = map_t(sorted_range, {{1,4},{2,3},{2,2},{3,1}});
|
||||||
|
REQUIRE(s0 == map_t{{1,4},{2,3},{3,1}});
|
||||||
|
|
||||||
|
vec_t v1({{1,4},{2,3},{2,2},{3,1}});
|
||||||
|
auto s1 = map_t(sorted_range, v1.begin(), v1.end());
|
||||||
|
REQUIRE(s1 == map_t{{1,4},{2,3},{3,1}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SECTION("capacity") {
|
SECTION("capacity") {
|
||||||
using map_t = flat_map<int, unsigned>;
|
using map_t = flat_map<int, unsigned>;
|
||||||
|
|||||||
@@ -200,6 +200,15 @@ TEST_CASE("flat_multimap") {
|
|||||||
s3 = {{0,1}, {1,2}};
|
s3 = {{0,1}, {1,2}};
|
||||||
REQUIRE(s3 == map_t{{0,1}, {1,2}});
|
REQUIRE(s3 == map_t{{0,1}, {1,2}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto s0 = map_t(sorted_range, {{1,4},{2,3},{2,2},{3,1}});
|
||||||
|
REQUIRE(s0 == map_t{{1,4},{2,3},{2,2},{3,1}});
|
||||||
|
|
||||||
|
vec_t v1({{1,4},{2,3},{2,2},{3,1}});
|
||||||
|
auto s1 = map_t(sorted_range, v1.begin(), v1.end());
|
||||||
|
REQUIRE(s1 == map_t{{1,4},{2,3},{2,2},{3,1}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SECTION("capacity") {
|
SECTION("capacity") {
|
||||||
using map_t = flat_multimap<int, unsigned>;
|
using map_t = flat_multimap<int, unsigned>;
|
||||||
|
|||||||
@@ -186,6 +186,15 @@ TEST_CASE("flat_multiset") {
|
|||||||
s3 = {1,2,3};
|
s3 = {1,2,3};
|
||||||
REQUIRE(s3 == set_t{1,2,3});
|
REQUIRE(s3 == set_t{1,2,3});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto s0 = set_t(sorted_range, {1,2,2,3});
|
||||||
|
REQUIRE(s0 == set_t{1,2,2,3});
|
||||||
|
|
||||||
|
vec_t v1({1,2,3,3});
|
||||||
|
auto s1 = set_t(sorted_range, v1.begin(), v1.end());
|
||||||
|
REQUIRE(s1 == set_t{1,2,3,3});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SECTION("capacity") {
|
SECTION("capacity") {
|
||||||
using set_t = flat_multiset<int>;
|
using set_t = flat_multiset<int>;
|
||||||
|
|||||||
@@ -186,6 +186,15 @@ TEST_CASE("flat_set") {
|
|||||||
s3 = {1,2,3};
|
s3 = {1,2,3};
|
||||||
REQUIRE(s3 == set_t{1,2,3});
|
REQUIRE(s3 == set_t{1,2,3});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto s0 = set_t(sorted_unique_range, {1,2,3});
|
||||||
|
REQUIRE(s0 == set_t{1,2,3});
|
||||||
|
|
||||||
|
vec_t v1({1,2,3});
|
||||||
|
auto s1 = set_t(sorted_unique_range, v1.begin(), v1.end());
|
||||||
|
REQUIRE(s1 == set_t{1,2,3});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SECTION("capacity") {
|
SECTION("capacity") {
|
||||||
using set_t = flat_set<int>;
|
using set_t = flat_set<int>;
|
||||||
|
|||||||
Reference in New Issue
Block a user