const_list: implemented swap and merge
This commit is contained in:
parent
a497cfbb22
commit
cf759983b8
|
|
@ -402,6 +402,102 @@ namespace cc {
|
|||
--_size;
|
||||
}
|
||||
|
||||
template<typename Node>
|
||||
constexpr void const_list<Node>::swap(const_list &other) noexcept
|
||||
{
|
||||
auto tmp = _tail;
|
||||
_tail = other._tail;
|
||||
other._tail = tmp;
|
||||
}
|
||||
|
||||
template<typename Node>
|
||||
constexpr void const_list<Node>::merge(const_list &other)
|
||||
{
|
||||
merge(std::forward<decltype(other)>(other), [](const value_type& v1, const value_type& v2) -> bool { return v1 < v2; });
|
||||
}
|
||||
|
||||
template<typename Node>
|
||||
constexpr void const_list<Node>::merge(const_list &&other)
|
||||
{
|
||||
merge(std::forward<decltype(other)>(other), [](const value_type& v1, const value_type& v2) -> bool { return v1 < v2; });
|
||||
}
|
||||
|
||||
template<typename Node>
|
||||
template<typename Compare>
|
||||
constexpr void const_list<Node>::merge(const_list &other, Compare comp)
|
||||
{
|
||||
if (std::addressof(other) == this) return;
|
||||
|
||||
auto first1 = begin();
|
||||
auto last1 = end();
|
||||
auto first2 = other.begin();
|
||||
auto last2 = other.end();
|
||||
|
||||
while (first1 != last1 && first2 != last2) {
|
||||
if (comp(*first2, *first1)) {
|
||||
auto next = std::next(first2);
|
||||
|
||||
first2._node->_owner = this;
|
||||
first1._node->push_before(first2._node);
|
||||
|
||||
first2 = next;
|
||||
} else {
|
||||
++first1;
|
||||
}
|
||||
}
|
||||
|
||||
while (first2 != last2) {
|
||||
auto next = std::next(first2);
|
||||
|
||||
first2._node->_owner = this;
|
||||
_tail.push_before(first2._node);
|
||||
|
||||
first2 = next;
|
||||
}
|
||||
|
||||
other._tail._next = &other._tail;
|
||||
other._tail._prev = &other._tail;
|
||||
other._size = 0;
|
||||
}
|
||||
|
||||
template<typename Node>
|
||||
template<typename Compare>
|
||||
constexpr void const_list<Node>::merge(const_list &&other, Compare comp)
|
||||
{
|
||||
if (std::addressof(other) == this) return;
|
||||
|
||||
auto first1 = begin();
|
||||
auto last1 = end();
|
||||
auto first2 = other.begin();
|
||||
auto last2 = other.end();
|
||||
|
||||
while (first1 != last1 && first2 != last2) {
|
||||
if (comp(*first2, *first1)) {
|
||||
auto next = std::next(first2);
|
||||
|
||||
first2._node->_owner = this;
|
||||
first1._node->push_before(first2._node);
|
||||
|
||||
first2 = next;
|
||||
} else {
|
||||
++first1;
|
||||
}
|
||||
}
|
||||
|
||||
while (first2 != last2) {
|
||||
auto next = std::next(first2);
|
||||
|
||||
first2._node->_owner = this;
|
||||
_tail.push_before(first2._node);
|
||||
|
||||
first2 = next;
|
||||
}
|
||||
|
||||
other._tail._next = &other._tail;
|
||||
other._tail._prev = &other._tail;
|
||||
other._size = 0;
|
||||
}
|
||||
|
||||
template<typename D>
|
||||
constexpr const_list_node<D>::const_list_node(const const_list_node &other) noexcept
|
||||
: _delete_cb(other._delete_cb)
|
||||
|
|
|
|||
Loading…
Reference in New Issue