55 C c = { 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 };
59 c.traverse([] (
auto i) { cout <<
" " << i;
return true; }); cout <<
endl;
61 a.traverse([] (
auto i) { cout <<
" " << i;
return true; }); cout <<
endl;
63 assert(c.all([] (
auto i) { return i >= 0; }));
64 assert(a.all([] (
auto i) { return i >= 0; }));
66 int vals[11];
int k = 0;
67 c.for_each([&
k, &
vals] (
int i) {
vals[
k++] = i; });
69 c.for_each([&c,
vals] (
int i) {
assert(c.nth_ne(i) ==
vals[i]); });
72 a.for_each([&
k, &
vals] (
int i) {
vals[
k++] = i; });
73 a.for_each([&a,
vals] (
int i) {
assert(a.nth_ne(i) ==
vals[i]); });
75 assert(c.find_ptr([] (
int i) { return i == 5; }));
76 assert(a.find_ptr([] (
int i) { return i == 5; }));
77 assert(
not c.find_ptr([] (
int i) { return i == 15; }));
78 assert(
not a.find_ptr([] (
int i) { return i == 15; }));
79 assert(
get<0>(c.find_item([] (
int i) { return i == 5; })));
81 get<1>(c.find_item([] (
int i) { return i == 5; })) == 5);
82 assert(
get<0>(a.find_item([] (
int i) { return i == 5; })));
84 get<1>(a.find_item([] (
int i) { return i == 5; })) == 5);
91 C c = { 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 };
93 c.traverse([] (
auto i) { cout <<
" " << i;
return true; }); cout <<
endl;
94 a.traverse([] (
auto i) { cout <<
" " << i;
return true; }); cout <<
endl;
97 c1.for_each([] (
int i) { cout <<
" " << i; }); cout <<
endl;
100 c2.for_each([] (
int i) { cout <<
" " << i; }); cout <<
endl;
102 vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 };
104 C
c3(v.begin(), v.end());
105 c3.for_each([] (
int i) { cout <<
" " << i; }); cout <<
endl;
107 const C
c4(v.begin(), v.end());
108 c4.for_each([] (
int i) { cout <<
" " << i; }); cout <<
endl;
114 C c = { 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 };
117 c.for_each([] (
int i) { cout <<
" " << i; }); cout <<
endl;
118 a.for_each([] (
int i) { cout <<
" " << i; }); cout <<
endl;
120 assert(c.all([&a] (
int i) { return a.exists([i] (int k)
121 { return k == i; }); }));
122 assert(a.all([&c] (
int i) { return c.exists([i] (int k)
123 { return k == i; }); }));
125 assert(c.exists([] (
int i) { return i == 9; }));
126 assert(a.exists([] (
int i) { return i == 9; }));
129 { return c.exists([i] (int k) { return i == k; }); }));
131 { return a.exists([i] (int k) { return i == k; }); }));
133 C
cm = c.maps([] (
int i) {
return 10*i; });
136 return c.exists([k] (int i) { return 10*i == k; });
139 const C
ccm = a.maps([] (
int i) {
return 10*i; });
142 return a.exists([k] (int i) { return 10*i == k; });
150 << c.template
foldl<int>(0, [] (
auto a,
auto i) {
return a + i; })
153 <<
ccm.template
foldl<int>(0, [] (
int a,
int i) { return a + i; })
155 <<
"S3 = " << c.
fold(0, [] (
auto a,
auto i) {
return a + i; })
157 <<
"S4 = " << a.fold(0, [] (
auto a,
auto i) { return a + i; })
162 sort(c.filter([] (
int i) { return i < 6; }))));
164 sort(a.filter([] (
int i) { return i < 6; }))));
166 c.pfilter([] (
int i) {
return i < 6; }).
for_each([] (
auto p)
171 a.pfilter([] (
int i) {
return i < 6; }).
for_each([] (
auto p)
178 auto cmp_tup = [] (std::tuple<size_t,size_t>
t1, std::tuple<size_t,size_t>
t2)
183 auto l1 =
sort(c.pfilter([] (
int i) { return i < 6; }),
cmp_tup);
184 auto l2 =
sort(a.pfilter([] (
int i) { return i < 6; }),
cmp_tup);
198 auto eq_tup = [] (std::tuple<size_t,size_t>
t1, std::tuple<size_t,size_t>
t2)
204 auto p = c.partition([] (
int i) {
return i < 6; });
207 p = a.partition([] (
int i) {
return i < 6; });
211 auto t = c.tpartition([] (
int i) {
return i < 6; });
214 t = a.tpartition([] (
int i) {
return i < 6; });
221 c.take(3).for_each([] (
auto i) { cout << i <<
" "; });
223 a.take(3).for_each([] (
auto i) { cout << i <<
" "; });
230 c.take(3).for_each([] (
auto i) { cout << i <<
" "; });
232 cc.take(3).for_each([] (
auto i) { cout << i <<
" "; });
239 cout <<
"All test were passed!" <<
endl
247 cout <<
"Testing for " <<
typeid(C).name() <<
endl
254 cout <<
"Ended tests for " <<
typeid(C).name() <<
endl
High-level sorting functions for Aleph containers.
Dynamic doubly linked list with O(1) size and bidirectional access.
Dynamic singly linked list with functional programming support.
T fold(const T &init, Operation &operation) const
Simplified version of foldl() where the folded type is the same type of elements stored in the contai...
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
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.
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
std::ostream & join(const C &c, const std::string &sep, std::ostream &out)
Join elements of an Aleph-style container into a stream.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Fixed-capacity binary heap and heapsort algorithms.
Circular queue implementations backed by arrays.
Array-based dynamic binary heap.
Lazy and scalable dynamic array implementation.
Dynamic binary heap with node-based storage.
Dynamic doubly linked list implementation.
Dynamic stack implementation based on linked lists.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.
Open addressing hash table with double hashing.
Open addressing hash table with linear probing.
Random access queue (bag) with O(1) random pop.