38# include <gtest/gtest.h>
61 static constexpr size_t N = 5;
121 for (
auto it =
zip_it(
l1,
l2,
l3); it.has_curr(); it.next_ne(), ++i)
123 auto t = it.get_curr_ne();
132 auto t = it.get_curr_ne();
140 auto t = it.get_curr_ne();
173 },
l1,
l2,
l3), length_error);
258 auto t = it.get_curr_ne();
296 for (
auto it =
zip_it(
l,
l1,
l2); it.has_curr(); it.next_ne())
298 auto c = it.get_curr_ne();
314 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
343 for (
auto it = result.get_it(); it.has_curr(); it.next_ne())
345 auto t = it.get_curr();
360 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++
expected_idx)
362 auto t = it.get_curr();
376 vector<int> v1 = { 1, 2, 3, 4, 5 };
383 for (
size_t i = 0; i < result.size(); ++i)
385 EXPECT_EQ(result[i].first,
static_cast<int>(i + 1));
386 EXPECT_EQ(result[i].second,
string(1,
'a' + i));
393 vector<int> v1 = { 1, 2, 3 };
394 vector<int> v2 = { 10, 20, 30, 40, 50 };
408 vector<int> v1 = { 1, 2, 3 };
423 vector<int> v1 = { 1, 2, 3 };
424 vector<double> v2 = { 1.1, 2.2, 3.3 };
438 vector<int> v1 = { 1, 2, 3 };
439 vector<double> v2 = { 1.1, 2.2, 3.3 };
461 vector<int> v1 = { 1, 2 };
462 vector<double> v2 = { 1.1, 2.2 };
479 vector<int> v1 = { 1, 2, 3 };
480 vector<double> v2 = { 1.1, 2.2, 3.3 };
490 vector<int> v1 = { 1, 2 };
491 vector<int> v2 = { 10, 20, 30 };
492 vector<int>
v3 = { 100, 200, 300, 400 };
504 vector<int> v1 = { 1, 2 };
505 vector<int> v2 = { 10, 20, 30 };
506 vector<int>
v3 = { 100, 200, 300, 400 };
507 vector<int>
v4 = { 1000, 2000, 3000, 4000, 5000 };
521 for (; it.has_curr(); it.next_ne(), ++
count)
523 auto t = it.get_curr_ne();
543 auto it =
zip_it(a, b, c);
616 const size_t SIZE = 1000;
652 while (it.has_curr())
664 while (it.has_curr())
685 auto t = it.get_curr_ne();
703 static_assert(std::is_same_v<std::decay_t<decltype(get<0>(t))>,
int>);
704 static_assert(std::is_same_v<std::decay_t<decltype(get<1>(t))>,
double>);
705 static_assert(std::is_same_v<std::decay_t<decltype(get<2>(t))>,
string>);
706 static_assert(std::is_same_v<std::decay_t<decltype(get<3>(t))>,
char>);
707 static_assert(std::is_same_v<std::decay_t<decltype(get<4>(t))>,
long>);
722 auto t = it.get_curr_ne();
747 auto t = it.get_curr_ne();
765 static_assert(std::is_same_v<std::decay_t<decltype(get<0>(t))>,
string>);
766 static_assert(std::is_same_v<std::decay_t<decltype(get<1>(t))>,
double>);
767 static_assert(std::is_same_v<std::decay_t<decltype(get<2>(t))>,
int>);
783 for (
auto it =
zip_it(hash, tree, list, arr); it.has_curr(); it.next_ne(), ++
count)
785 auto t = it.get_curr_ne();
820 for (
size_t i = 0; i <
N; ++i)
821 EXPECT_EQ(result[i],
static_cast<int>(2 * i));
831 for (
size_t i = 0; i <
N; ++i)
832 EXPECT_EQ(result[i],
static_cast<int>(i * i));
859 values.push_back(
get<0>(t));
865 for (
size_t i = 0; i <
N; ++i)
868 EXPECT_EQ(values[i],
static_cast<int>(i));
918 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
920 auto t = it.get_curr();
946 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
948 auto t = it.get_curr();
981 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
983 auto t = it.get_curr();
1011 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
1013 auto t = it.get_curr();
1046 auto t =
make_tuple(1, 2.5,
string(
"hello"));
1125 bool result =
all_of_tuple([](
auto x) {
return x % 2 == 0; }, t);
1133 bool result =
all_of_tuple([](
auto x) {
return x % 2 == 0; }, t);
1141 bool result =
all_of_tuple([](
auto) {
return false; }, t);
1149 bool result =
any_of_tuple([](
auto x) {
return x % 2 == 0; }, t);
1157 bool result =
any_of_tuple([](
auto x) {
return x % 2 == 0; }, t);
1165 bool result =
any_of_tuple([](
auto) {
return true; }, t);
1189 const size_t SIZE = 1000;
1198 for (
size_t i = 0; i <
SIZE; ++i)
1199 EXPECT_EQ(transformed[i],
static_cast<int>(2 * i));
1360 auto t = it.get_curr_ne();
1395 auto t =
zipped.get_first();
1408 auto t = it.get_curr_ne();
1753 static_assert(std::is_same_v<ZipIt::Tuple_Type, ExpectedType>,
1754 "Tuple_Type should be tuple<int, int, string>");
1757 ZipIt::Tuple_Type t = std::make_tuple(1, 2,
"test");
1767 static_assert(std::is_same_v<ZipIt::Item_Type, int>,
1768 "Item_Type should be int for single container");
1797 [](
auto t) {
return get<0>(t) > 1; },
1798 [](
auto t) {
return get<0>(t) * 10; },
1810 [](
auto) {
return true; },
1811 [](
auto t) {
return get<0>(t); },
1838 auto result =
zip_map([](
auto t) {
1847 "zip_map should return DynList<string>");
1853 auto result =
zip_map([](
auto t) {
1860 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
1861 EXPECT_EQ(it.get_curr(),
static_cast<int>(2 * i));
1864 static_assert(std::is_same_v<
decltype(result),
DynList<int>>,
1865 "zip_map should return DynList<int>");
1878 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
1879 EXPECT_EQ(it.get_curr(),
static_cast<int>(i * i));
1986 auto pred = [](
auto x) {
return x > 10; };
1995 const size_t SIZE = 1000;
2037 auto [i, s] = it.get_curr_ne();
String manipulation utilities.
Zip iterators and functional operations for multiple containers.
TEST_F(EmptyGroup, empty)
Functional programming utilities for Aleph-w containers.
Simple dynamic array with automatic resizing and functional operations.
bool contains(const Key &key) const noexcept
Return true if the key exists in the table.
Dynamic singly linked list with functional programming support.
Dynamic set backed by balanced binary search trees with automatic memory management.
bool contains(const Key &key) const
Checks if a key exists in the set.
Dynamic ordered set implemented with a Skip List.
size_t size() const noexcept
Count the number of elements of the list.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Type & nth(const size_t n)
Return the n-th item of the container.
Iterator that traverses multiple Aleph containers in lockstep.
Freq_Node * pred
Predecessor node in level-order traversal.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
ZipIterator< Cs... > zip_it(const Cs &...cs)
Alias for get_zip_it.
void zip_for_each_eq(Op &&op, const Cs &...cs)
Apply op to every zipped tuple; throw if containers differ in length.
bool zip_traverse_eq(Op &&op, const Cs &...cs)
Traverse zipped containers while op returns true; verify equal lengths.
void zip_for_each_indexed_eq(Op &&op, const Cs &...cs)
Apply op to each zipped tuple with index; throw if lengths differ.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
auto zip_drop_while(Pred &&pred, const Cs &...cs)
Skip tuples while predicate pred returns true, then return the rest.
auto t_enum_zip_eq(const Cs &...cs)
Materialize enumerated zipped tuples; throw if containers differ in length.
void zip_for_each(Op &&op, const Cs &...cs)
Apply op to every zipped tuple.
EnumZipIterator< Cs... > enum_zip_it_pos(size_t pos, const Cs &...cs)
Alias for get_enum_zip_it_pos.
ZipIterator< Cs... > zip_it_pos(size_t pos, const Cs &...cs)
Alias for get_zip_it_pos.
bool zip_forall_short(Op &&op, const Cs &...cs)
Alias for zip_all_short.
auto std_zip(const C1 &c1, const C2 &c2)
Build a vector of pairs from two STL containers.
bool all_of_tuple(Pred &&pred, const Tuple &t)
Return true if all tuple elements satisfy pred.
auto transform_tuple(Op &&op, Tuple &&t)
Transform each element of a tuple, returning a new tuple.
auto zip_transform_eq(Op &&op, const Cs &...cs)
Transform zipped tuples; throw if containers differ in length.
bool equal_length(const Cs &...cs)
Return true if all containers have the same length.
T zip_foldl(const T &init, Op op, const Cs &...cs)
Left fold (reduce) over zipped tuples.
bool zip_all_short(Op &&op, const Cs &...cs)
Return true if op returns true for all tuples (without length check).
void for_each_in_tuple(Op &&op, Tuple &&t)
Apply op to each element of a tuple.
auto std_zip_n(const Cs &...cs)
Build a vector of tuples from 2 or more STL containers (variadic).
size_t zip_length(const Cs &...cs)
Count all tuples (minimum length of containers).
auto zip_filter(Op op, const Cs &...cs)
Filter zipped tuples by predicate op.
T zip_foldl_eq(const T &init, Op op, const Cs &...cs)
Left fold over zipped tuples; throw if containers differ in length.
auto t_zip(const Cs &...cs)
Materialize zipped tuples into a DynList.
bool zip_any(Op &&op, const Cs &...cs)
Alias for zip_exists.
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.
auto zip_lists(const C &c, const Lists &...lists)
Take several container of same type and some length and builds a list of lists.
bool zip_forall(Op &&op, const Cs &...cs)
Alias for zip_all.
bool any_of_tuple(Pred &&pred, const Tuple &t)
Return true if any tuple element satisfies pred.
size_t zip_count(Op &&op, const Cs &...cs)
Count tuples that satisfy predicate op.
bool zip_traverse(Op &&op, const Cs &...cs)
Traverse zipped containers while op returns true.
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
auto zip_find_first(Op &&op, const Cs &...cs)
Return the first tuple that satisfies predicate op.
bool zip_all(Op &&op, const Cs &...cs)
Return true if op returns true for all tuples and containers have equal length.
auto t_zip_eq(const Cs &...cs)
Materialize zipped tuples; throw if containers differ in length.
bool none_of_tuple(Pred &&pred, const Tuple &t)
Return true if no tuple element satisfies pred.
bool zip_none(Op &&op, const Cs &...cs)
Return true if op returns false for all tuples.
auto tzip_std(const Cs &...cs)
Build a vector of tuples from 2 or more STL containers (variadic).
auto t_enum_zip(const Cs &...cs)
Materialize enumerated zipped tuples into a DynList.
auto zip_first(const Cs &...cs)
Return the first tuple from zipped containers.
EnumZipIterator< Cs... > enum_zip_it(const Cs &...cs)
Alias for get_enum_zip_it.
auto zip_find_last(Op &&op, const Cs &...cs)
Return the last tuple that satisfies predicate op.
auto t_unzip(const DynList< std::tuple< Ts... > > &tuples)
Unzip a list of tuples into a tuple of lists.
auto zip_map(Op &&op, const Cs &...cs)
Map op over zipped tuples with auto-deduced return type.
auto zip_partition(Op op, const Cs &...cs)
Partition zipped tuples by predicate op.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
size_t zip_find_index(Op op, const Cs &...cs)
Find the first index where op returns true.
auto zip_take_while(Pred &&pred, const Cs &...cs)
Take tuples while predicate pred returns true.
void zip_for_each_indexed(Op &&op, const Cs &...cs)
Apply op to each zipped tuple along with its index.
bool zip_exists(Op &&op, const Cs &...cs)
Return true if op returns true for at least one tuple.
auto zip_drop(const size_t n, const Cs &...cs)
Skip n tuples and return the rest.
auto zip_filter_eq(Op op, const Cs &...cs)
Filter zipped tuples by predicate op; throw if containers differ in length.
auto zip_nth(size_t n, const Cs &...cs)
Return the n-th tuple from zipped containers.
auto zip_lists_eq(const C &c, const Lists &...lists)
Like zip_lists but throws if containers differ in length.
bool zip_cmp(Cmp cmp, const Cs &...cs)
Return true if cmp(t) is true for each built tuple t.
auto zip_map_eq(Op &&op, const Cs &...cs)
Map op over zipped tuples with auto-deduced return type; throw if lengths differ.
auto zip_transform(Op &&op, const Cs &...cs)
Transform zipped tuples using op and return results in a vector.
auto zip_take(size_t n, const Cs &...cs)
Take at most n tuples from the zipped containers.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
static constexpr size_t N
Aleph::DynList< T > keys() const
Dynamic array container with automatic resizing.
Lazy and scalable dynamic array implementation.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.