Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test-zip-it.cc
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
26*/
27
28# include <iostream>
29
30# include <ah-zip.H>
31# include <tpl_dynSetTree.H>
32
33using namespace std;
34using namespace Aleph;
35
36DynList<int> l1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
37DynList<int> l2 = { 0, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
38DynList<char> l3 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k' };
39DynSetTree<char> l5 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K' };
40
41int main()
42{
43 auto it = get_zip_it(l1, l2, l3, l5);
44 for (; it.has_curr(); it.next())
45 {
46 auto curr = it.get_curr();
47 cout << "curr = (" << get<0>(curr) << ", " << get<1>(curr) << ", "
48 << get<2>(curr) << ")" << endl;
49 }
50
51 zip_for_each([] (auto t) {}, l1, l2);
52
53 assert(not it.completed());
54
55 auto l = t_enum_zip(l1, l2, l3);
56
57 auto lu = t_unzip(l);
58
59 for (auto it = get<3>(lu).get_it(); it.has_curr(); it.next())
60 cout << it.get_curr() << " ";
61 cout << endl;
62
63 auto l4 = l1.maps([] (auto i) { return 10*i; });
64
65 for (auto it = get_zip_it(l1, l2, l4); it.has_curr(); it.next())
66 {
67 auto l = it.get_curr_list();
68 l.for_each([] (auto i) { cout << i << " "; });
69 cout << endl;
70 }
71
72 zip_lists(l1, l2, l4).for_each([] (auto & l)
73 {
74 l.for_each([] (auto i) { cout << i << " "; });
75 cout << endl;
76 });
77
79 ([] (tuple<int, int, int> t) { return get<0>(t) + get<1>(t) + get<2>(t); },
80 l1, l2, l4).for_each([] (auto i) { cout << i << endl; });
81
82 auto filter = zip_filter([] (auto t) { return get<0>(t) < 5; }, l1, l2, l3, l5);
83
84 for (auto it = filter.get_it(); it.has_curr(); it.next())
85 {
86 auto & t = it.get_curr();
87 cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << " " << get<3>(t)
88 << endl;
89 }
90}
Zip iterators and functional operations for multiple containers.
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
Dynamic set backed by balanced binary search trees with automatic memory management.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:779
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Definition ah-dry.H:1057
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
void zip_for_each(Op &&op, const Cs &...cs)
Apply op to every zipped tuple.
Definition ah-zip.H:382
Container2< typename Container1::Item_Type > filter(Container1 &container, Operation &operation)
Filter elements that satisfy operation.
ZipIterator< Cs... > get_zip_it(const Cs &...cs)
Create a ZipIterator over the given containers.
Definition ah-zip.H:247
auto zip_filter(Op op, const Cs &...cs)
Filter zipped tuples by predicate op.
Definition ah-zip.H:870
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.
Definition ah-zip.H:1388
auto t_enum_zip(const Cs &...cs)
Materialize enumerated zipped tuples into a DynList.
Definition ah-zip.H:1315
auto t_unzip(const DynList< std::tuple< Ts... > > &tuples)
Unzip a list of tuples into a tuple of lists.
Definition ah-zip.H:1364
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
Definition ahAlgo.H:76
STL namespace.
DynList< char > l3
DynList< int > l1
DynList< int > l2
int main()
DynSetTree< char > l5
Dynamic set implementations based on balanced binary search trees.
DynList< int > l