Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 23 additions & 31 deletions include/fast_io_dsal/impl/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,15 @@ inline constexpr ::std::ptrdiff_t deque_iter_difference_common(::fast_io::contai
{
::std::ptrdiff_t controllerdiff{a.controller_ptr - b.controller_ptr};
constexpr ::std::ptrdiff_t blocksizedf{static_cast<::std::ptrdiff_t>(::fast_io::containers::details::deque_block_size<sizeof(T)>)};
return controllerdiff * blocksizedf + (a.curr_ptr - b.begin_ptr) + (b.begin_ptr - b.curr_ptr);
return controllerdiff * blocksizedf + (a.curr_ptr - a.begin_ptr) + (b.begin_ptr - b.curr_ptr);
}

template <typename T>
inline constexpr ::std::size_t deque_iter_difference_unsigned_common(::fast_io::containers::details::deque_control_block<T> const &a, ::fast_io::containers::details::deque_control_block<T> const &b) noexcept
{
::std::size_t controllerdiff{a.controller_ptr - b.controller_ptr};
constexpr ::std::size_t blocksizedf{::fast_io::containers::details::deque_block_size<sizeof(T)>};
return controllerdiff * blocksizedf + static_cast<::std::size_t>((a.curr_ptr - b.begin_ptr) + (b.begin_ptr - b.curr_ptr));
return controllerdiff * blocksizedf + static_cast<::std::size_t>((a.curr_ptr - a.begin_ptr) + (b.begin_ptr - b.curr_ptr));
}

template <typename T, bool isconst1, bool isconst2>
Expand Down Expand Up @@ -1776,40 +1776,22 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
requires ::std::constructible_from<value_type, ::std::ranges::range_value_t<R>>
inline constexpr insert_range_result insert_range_impl(size_type pos, R &&rg, size_type old_size) noexcept(::std::is_nothrow_constructible_v<value_type, ::std::ranges::range_value_t<R>>)
{
size_type const halfold_size{old_size >> 1u};
#if 0
size_type const halfold_size{old_size >> 1u};
if constexpr(::std::ranges::sized_range<R>)
{
size_type const rgsize{::std::ranges::size(rg)};
}
else
#endif
{
size_type retpos;
iterator retit, rotfirst, rotmid, rotlast;
if (pos < halfold_size)
{
this->prepend_range(rg);
size_type const new_size{this->size()};
size_type const inserted{new_size - old_size};
auto bg{this->begin()};
size_type newpos{pos + inserted};
rotfirst = bg;
rotmid = bg + inserted;
retpos = newpos;
retit = rotlast = bg + newpos;
}
else
{
this->append_range(rg);
auto bg{this->begin()};
rotfirst = retit = bg + pos;
rotmid = bg + old_size;
rotlast = this->end();
retpos = pos;
}
this->append_range(rg);
auto bg{this->begin()};
iterator rotfirst = bg + pos;
iterator rotmid = bg + old_size;
iterator rotlast = this->end();
::fast_io::containers::rotate_for_fast_io_deque(rotfirst, rotmid, rotlast);
return {retpos, retit};
return {pos, rotfirst};
}
}

Expand Down Expand Up @@ -1845,18 +1827,28 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
this->push_back(e);
}
}

#if 0
private:
template <::std::ranges::range R>
requires ::std::constructible_from<value_type, ::std::ranges::range_value_t<R>>
inline constexpr void prepend_range(R &&rg) noexcept(::std::is_nothrow_constructible_v<value_type, ::std::ranges::range_value_t<R>>)
inline constexpr size_type prepend_range_impl(R &&rg) noexcept(::std::is_nothrow_constructible_v<value_type, ::std::ranges::range_value_t<R>>)
{
// To do: cleanup code
size_type const old_size{this->size()};
for (auto &e : rg)
{
this->push_front(e);
}
return this->size() - old_size;
}

public:
template <::std::ranges::range R>
requires ::std::constructible_from<value_type, ::std::ranges::range_value_t<R>>
inline constexpr void prepend_range(R &&rg) noexcept(::std::is_nothrow_constructible_v<value_type, ::std::ranges::range_value_t<R>>)
{
// To do: cleanup code
this->prepend_range_impl(::std::forward<R>(rg));
}
#endif

inline constexpr ~deque()
{
Expand Down
10 changes: 5 additions & 5 deletions tests/0026.container/0003.deque/insert_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,16 @@ inline void test_insert_range_index()
}

// Helper to compare dq and ref
auto check_equal = [&](auto const &msg) {
auto check_equal = [&](auto const &msg, ::std::source_location src = ::std::source_location::current()) {
if (dq.size() != ref.size())
{
::fast_io::io::panicln("ERROR: size mismatch: ", msg);
::fast_io::io::panicln(src, "\tERROR: size mismatch: ", msg);
}
for (::std::size_t i{}; i != dq.size(); ++i)
{
if (dq[i] != ref[i])
{
::fast_io::io::panicln("ERROR: value mismatch at index ", i, " : ", msg);
::fast_io::io::panicln(src, "\tERROR: value mismatch at index ", i, "\tdq[i]=", dq[i], "\tref[i]=", ref[i], " : ", msg);
}
}
};
Expand Down Expand Up @@ -257,7 +257,7 @@ inline void test_insert_range_index()
int main()
{
test_iterator_ops();
#if 0
test_insert_range_index();
#if 1
test_insert_range_index();
#endif
}