38# include <gtest/gtest.h>
61using namespace testing;
67 static constexpr size_t N = 1000;
72 for (
size_t i = 0; i <
N; ++i)
89 EXPECT_TRUE(c.traverse([&
l] (
auto &
k) { l.append(k); return true; }));
91 this->item_list,
sort(
l)));
102 this->item_list,
sort(
l)));
110 auto ptr = c.find_ptr([
N] (
auto &
k) {
return k ==
int(
N); });
112 this->item_list.for_each([&c] (
auto &
k)
114 auto ptr = c.find_ptr([
k] (
auto i) {
return k == i; });
126 auto idx = c.find_index([
N] (
auto &
k) {
return k ==
int(
N); });
129 this->item_list.for_each([&c] (
auto &
k)
131 auto idx = c.find_index([
k] (
auto i) {
return k == i; });
142 auto t = c.find_item([
N] (
auto &
k) {
return k ==
int(
N); });
145 this->item_list.for_each([&c] (
auto &
k)
147 auto t = c.find_item([
k] (
auto i) {
return k == i; });
158 const std::vector<int> v = c.to_vector();
172 for (
auto & item : c)
177 auto it = c.get_it();
193 auto ptr = c.find_ptr([
N] (
auto i) {
return i ==
N; });
198 c.nappend(
N + 1,
N + 2,
N + 3);
201 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 1; });
205 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 2; });
209 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 3; });
220 auto ptr = c.find_ptr([
N] (
auto i) {
return i ==
N; });
225 c.ninsert(
N + 1,
N + 2,
N + 3);
228 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 1; });
232 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 2; });
236 ptr = c.find_ptr([
N] (
auto i) {
return i ==
N + 3; });
248 const bool ret = tbl.contains(i);
260 auto &
l = this->item_list;
262 { return c.exists([i] (auto k) { return i == k; }); }));
269 auto &
l = this->item_list;
270 auto fct = [] (
int i) {
return i + 1; };
272 all([] (
auto & p) {
return p.first == p.second; }));
274 { return i < 7; },
fct))),
276 { return i < 7; },
fct))).
277 all([] (
auto & p) {
return p.first == p.second; }));
283 auto &
l = this->item_list;
284 auto fct = [] (
int i) {
return i + 1; };
286 all([] (
auto & p) {
return p.first == p.second; }));
288 { return i < 7; },
fct))),
290 { return i < 7; },
fct))).
291 all([] (
auto & p) {
return p.first == p.second; }));
298 auto sum = c.foldl(0, [] (
auto & a,
auto & i) {
return a + i; });
304 auto fct = [] (
int a,
int i) {
return a + i; };
306 auto sum = c.filter([] (
auto i) {
return i < 8; }).
foldl(0,
fct);
309 auto l = c.
ptr_filter([] (
auto & i) {
return i < 8; });
310 sum =
l.
foldl(0, [] (
auto a,
auto ptr) {
return a + *ptr; });
315 auto p = c.partition([] (
auto & i) {
return i < 8; });
316 auto S = p.first.foldl(0,
fct) + p.second.foldl(0,
fct);
319 auto t = c.tpartition([] (
auto & i) {
return i < 8; });
356 static constexpr size_t N = 10;
363 ptr_2 =
new C({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
379 auto ptr_1 = this->ptr_1;
380 auto ptr_2 = this->ptr_2;
381 auto ptr_3 = this->ptr_3;
392 const auto &
r3 =
r1;
446 std::map<int, std::string>
std_map;
460 [] (
int x) {
return x > 2; },
461 [] (
int x) {
return x * 3; }
472 auto result =
mapped.foldl(0, [] (
int acc,
int val) {
return acc + val; });
INSTANTIATE_TYPED_TEST_SUITE_P(traverses, Container, Ctypes)
Types< DynList< int >, DynDlist< int >, DynArray< int >, HashSet< int, ODhashTable >, HashSet< int, OLhashTable >, DynHashTable< int, LhashTable >, DynHashTable< int, LinearHashTable >, DynSetHash< int >, DynSetTree< int, Treap >, DynSetTree< int, Treap_Rk >, DynSetTree< int, Rand_Tree >, DynSetTree< int, Splay_Tree >, DynSetTree< int, Avl_Tree >, DynSetTree< int, Rb_Tree >, Array< int >, ArrayQueue< int >, ArrayStack< int >, DynListQueue< int >, DynListStack< int >, DynArrayHeap< int >, DynBinHeap< int >, FixedQueue< int >, FixedStack< int > > Ctypes
REGISTER_TYPED_TEST_SUITE_P(Container, traverse, for_each, find_ptr, find_index_nth, find_item, iterator_operations, nappend, ninsert, all, exists, maps, map_synonyms, foldl, filter_ops)
TYPED_TEST_SUITE_P(Container)
TYPED_TEST_P(Container, traverse)
String manipulation utilities.
Zip iterators and functional operations for multiple containers.
Functional programming utilities for Aleph-w containers.
High-level sorting functions for Aleph containers.
Queue implemented with a single dynamic array.
Stack implemented with simple dynamic array and with bounds verification.
Simple dynamic array with automatic resizing and functional operations.
Dynamic heap (priority queue) backed by DynArray.
Dynamic heap of elements of type T ordered by a comparison functor.
Dynamic doubly linked list with O(1) size and bidirectional access.
Self-adjusting dynamic hash table.
Dynamic queue of elements of generic type T based on single linked list.
Dynamic stack of elements of generic type T based on a singly linked list.
Doubly-linked list (defined in tpl_dynList.H).
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.
Dynamic set backed by balanced binary search trees with automatic memory management.
Very simple queue implemented with a contiguous array.
size_t size() const noexcept
Count the number of elements of the list.
Mixin providing equality comparison for sequence containers.
bool equal_to(const Container &r) const
Equality test between this and r.
Aleph::DynList< __T > maps_if(Prop prop, Operation &op) const
Aleph::DynList< T > to_dynlist() const
Convert container to DynList.
__T foldl(const __T &init, Op &op) const
Fold the elements of the container to a specific result.
Aleph::DynList< T > take(const size_t n) const
Return a list with the first n elements seen in the container during its traversal.
Aleph::DynList< const T * > ptr_filter(Operation &operation) const
Filter the elements of a container according to a matching criterion and return a pointer to the matc...
Aleph::DynList< __T > map(Operation &op) const
Synonym of maps().
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Aleph::DynList< __T > map_if(Prop prop, Operation &op) const
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
Aleph::DynList< T > drop(const size_t n) const
Drop the first n elements seen in the container during its traversal.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
MapOLhash< int, Foo > tbl
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
DynList< typename Container::Item_Type > to_dynlist(const Container &c)
bool traverse(Node *root, Op op)
DynList< std::pair< typename Container1::Item_Type, typename Container2::Item_Type > > zip(const Container1 &a, const Container2 &b)
Zip two containers into a list of pairs.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
T foldl(const Container &container, const T &init, Operation operation)
Classic left fold (reduce).
bool exists(Container &container, Operation &operation)
Return true if at least one element satisfies a predicate.
DynArray< T > sort(const DynArray< T > &a, Cmp &&cmp=Cmp())
Returns a sorted copy of a DynArray.
bool zip_all(Op &&op, const Cs &...cs)
Return true if op returns true for all tuples and containers have equal length.
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
Container::Item_Type * find_ptr(Container &container, Pred &pred)
Find the first element satisfying pred.
DynList< T > maps(const C &c, Op op)
Classic map operation.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
static constexpr size_t N
static constexpr size_t N
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.
Unified hash table interface.
Random access queue (bag) with O(1) random pop.