43#include <gtest/gtest.h>
52using namespace testing;
73 auto other = std::make_unique<Slinknc>();
74 link.insert(
other.get());
85 auto other = std::make_unique<Slinknc>();
143 string str =
"Hello World";
163 EXPECT_EQ(n1.get_next()->get_next()->get_data(), 3);
216 delete list.remove_first();
229 delete list.remove_first();
239 EXPECT_EQ(list.get_first()->to_data<
int>(), 1);
240 EXPECT_EQ(list.get_last()->to_data<
int>(), 3);
243 list.remove_all_and_delete();
253 EXPECT_EQ(list.get_first()->to_data<
int>(), 1);
254 EXPECT_EQ(list.get_last()->to_data<
int>(), 3);
257 list.remove_all_and_delete();
272 for (
int i = 1; i <= 5; ++i)
294 Slinknc *first = list.get_first();
301 vector<int>
expected = {1, 10, 11, 12, 2, 3, 4, 5};
334 vector<int>
expected = {1, 2, 3, 20, 21, 4, 5};
354 Slinknc *last = list.get_last();
359 EXPECT_EQ(list.get_last()->to_data<
int>(), 31);
362 vector<int>
expected = {1, 2, 3, 4, 5, 30, 31};
376 Slinknc *first = list.get_first();
383 for (
int i = 1; i <= 5; ++i, it.
next())
458 for (
int i = 1; i <= 10; ++i)
478 for (
int i = 1; i <= 7; ++i)
519 for (
int i = 1; i <= 5; ++i)
545 for (
int i = 1; i <= 5; ++i)
551 vector<int>
expected = {2, 3, 4, 5, 1};
620 for (
int i = 0; i < 5; ++i)
623 for (
int i = 0; i < 5; ++i)
648 for (
int i = 1; i <= 10; ++i)
656 int removed = list.remove([](
const int &x)
663 for (
auto it = list.get_it(); it.has_curr(); it.next())
669 int removed = list.remove([](
const int &x)
678 int removed = list.remove([](
const int &x)
679 {
return x == 10; });
689 list.remove([](
const int &x)
690 { return x == 100; }),
697 int result = list.remove_ne([](
const int &x)
698 {
return x == 100; });
706 int removed = list.remove_ne([](
const int &x)
716 for (
int i = 2; i <= 10; i += 2)
719 list.remove([target](
const int &x)
720 {
return x == target; });
726 for (
auto it = list.get_it(); it.has_curr(); it.next())
737 for (
int i = 1; i <= 5; ++i)
745 auto it2 =
copy.get_it();
746 while (it1.has_curr())
748 EXPECT_EQ(it1.get_curr(), it2.get_curr());
757 for (
int i = 1; i <= 5; ++i)
769 for (
int i = 1; i <= 5; ++i)
784 for (
int i = 1; i <= 5; ++i)
797 for (
int i = 1; i <= 5; ++i)
813 for (
int i = 1; i <= 3; ++i)
815 for (
int i = 4; i <= 6; ++i)
818 list1.
append(std::move(list2));
824 for (
auto it = list1.
get_it(); it.has_curr(); it.next(), ++
expected)
832 for (
int i = 1; i <= 3; ++i)
834 for (
int i = 4; i <= 6; ++i)
847 for (
int i = 4; i <= 6; ++i)
849 for (
int i = 1; i <= 3; ++i)
852 list1.
insert(std::move(list2));
866 for (
int i = 1; i <= 5; ++i)
872 for (
auto it = list.
get_it(); it.has_curr(); it.next(), --
expected)
879 for (
int i = 1; i <= 5; ++i)
887 for (
auto it = list.
get_it(); it.has_curr(); it.next(), ++
expected)
892 for (
auto it = reversed.
get_it(); it.has_curr(); it.next(), --
expected)
907 for (
int i = 1; i <= 5; ++i)
915 for (
auto it = list.get_it(); it.has_curr(); it.next(), ++
expected)
924 int deleted = it.
del();
936 int deleted = it.
del();
1007 constexpr size_t N = 100000;
1010 for (
size_t i = 0; i <
N; ++i)
1011 list.
append(
static_cast<int>(i));
1025 constexpr size_t OPS = 10000;
1028 std::mt19937
rng(42);
1029 std::uniform_int_distribution<int>
opDist(0, 3);
1030 std::uniform_int_distribution<int>
valDist(0, 1000);
1032 for (
size_t i = 0; i <
OPS; ++i)
1057 for (
auto it = list.
get_it(); it.has_curr(); it.next())
1095 for (
int i = 1; i <= 10; ++i)
Iterator on the items of list.
T & get_curr() const
Return the current item.
T del()
Remove the current item of the iterator.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
T & append(const T &item)
T & get_last() const
Return the last item of the list.
T & get_first() const
Return the first item of the list.
T remove()
Remove the first item of the list.
DynList & reverse() noexcept
long get_pos() const noexcept
void reset_last()
It has O(n) of performance.
bool is_last() const noexcept
Slinknc * get_curr() const
bool has_curr() const noexcept
void end() noexcept
Set the iterator to its end position, which has not.
void reset() noexcept
Reset the iterator at the first item.
Single linked list of nodes.
Slinknc * get_first() const noexcept
void push(Slinknc *link) noexcept
void put(Slinknc *link) noexcept
size_t reverse_list() noexcept
void remove_all_and_delete() noexcept
size_t reverse() noexcept
It inverts all list elements. It returns list size.
void cut_list(Slinknc *link, HTList &list) noexcept
constexpr bool is_empty() const noexcept
void rotate_left(size_t n)
Rotate to left the list n positions.
void concat_list(HTList &l) noexcept
void append(Slinknc *link) noexcept
size_t split_list(HTList &l, HTList &r) noexcept
It divides 'this' into two equal lists without modifying.
size_t split(HTList &l, HTList &r) noexcept
size_t size() const noexcept
Count the number of elements of the list.
bool remove(Slinknc *link)
bool is_unitarian() const noexcept
Return true if the list contains exactly just one.
Slinknc * get_last() const noexcept
Return the last item of the list (nullptr if the list is empty)
size_t split_list_ne(HTList &l, HTList &r) noexcept
void concat(HTList &l) noexcept
Concat to 'this' all 'l' list; 'l' becomes empty.
bool has_curr() const noexcept
Return true if the iterator is positioned on a valid link.
Slinknc * get_curr() const
Link of a single linked list non-circular and without header node.
Slinknc *& get_next() noexcept
constexpr bool is_empty() const noexcept
Return true if this is empty.
Snodenc< T > * to_snodenc() noexcept
Convert this to a Snodenc<T>.
Slinknc * remove_next() noexcept
void insert(Slinknc *p) noexcept
insert(p) inserts the node pointed by p after this.
T & get_data() noexcept
Return a modifiable reference to the data.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Singly linked list implementations with head-tail access.
TEST_F(SlinkcTest, DefaultConstructor)
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
bool operator==(const TestStruct &other) const