47#include <gtest/gtest.h>
103 arr.touch(100) = 999;
122 arr.touch(10000) = 1;
129 for (
int i = 0; i < 100; ++i)
191 for (
int i = 0; i < 10; ++i)
202 for (
int i = 0; i < 20; ++i)
207 for (
int i = 0; i < 20; ++i)
214 for (
int i = 0; i < 8; ++i)
217 for (
int i = 0; i < 5; ++i)
221 for (
int i = 0; i < 5; ++i)
266 for (
int i = 0; i < 10; ++i)
276 for (
int i = 0; i < 20; ++i)
281 for (
int i = 19; i >= 0; --i)
314 EXPECT_THROW(dlist.remove_first(), std::underflow_error);
315 EXPECT_THROW(dlist.remove_last(), std::underflow_error);
358 auto it = dlist.begin();
378 for (
int i = 1; i <= 5; ++i)
400 dlist.append(std::move(
other));
424 EXPECT_THROW(slist.remove_first(), std::underflow_error);
488 int * p = table.insert(42);
493 int *
found = table.search(42);
503 int * dup = table.insert(42);
511 for (
int i = 0; i < 100; ++i)
513 int * p = table.insert(i);
514 EXPECT_NE(p,
nullptr) <<
"Failed to insert " << i;
520 for (
int i = 0; i < 100; ++i)
521 EXPECT_NE(table.search(i),
nullptr) <<
"Failed to find " << i;
567 int * p = table.insert(42);
579 for (
int i = 0; i < 50; ++i)
585 for (
int i = 0; i < 50; ++i)
619 int * p = tree.insert(42);
636 int * dup = tree.insert(42);
643 for (
int i = 1; i <= 100; ++i)
653 for (
int i = 100; i >= 1; --i)
663 for (
int i = 1; i <= 10; ++i)
673 for (
int i = 1; i <= 10; ++i)
683 for (
int i = 1; i <= 10; ++i)
693 vector<int> values = {5, 3, 7, 1, 4, 6, 8};
698 tree.for_each([&](
int x) { result.push_back(x); });
700 EXPECT_TRUE(std::is_sorted(result.begin(), result.end()));
705 tree.insert(std::numeric_limits<int>::max());
706 tree.insert(std::numeric_limits<int>::min());
709 EXPECT_EQ(tree.min(), std::numeric_limits<int>::min());
710 EXPECT_EQ(tree.max(), std::numeric_limits<int>::max());
739 for (
size_t i = 0; i < 64; ++i)
742 for (
size_t i = 0; i < 64; ++i)
751 for (
size_t i = 0; i < 64; ++i)
759 for (
size_t i = 0; i < 100; ++i)
762 for (
size_t i = 0; i < 100; ++i)
815 std::mt19937
gen(12345);
816 std::uniform_int_distribution<int>
val_dist(0, 10000);
817 std::uniform_int_distribution<int>
op_dist(0, 2);
819 std::set<int> reference;
821 for (
int i = 0; i < 10000; ++i)
826 if (op == 0 || op == 1)
836 else if (!reference.empty())
838 auto it = reference.begin();
839 std::advance(it,
gen() % reference.
size());
851 for (
int val : reference)
858 std::mt19937
gen(54321);
859 std::uniform_int_distribution<int>
val_dist(0, 5000);
860 std::uniform_int_distribution<int>
op_dist(0, 2);
862 std::set<int> reference;
864 for (
int i = 0; i < 5000; ++i)
869 if (op == 0 || op == 1)
879 else if (!reference.empty())
881 auto it = reference.begin();
882 std::advance(it,
gen() % reference.
size());
894 for (
int val : reference)
901 std::deque<int> reference;
902 std::mt19937
gen(99999);
903 std::uniform_int_distribution<int>
val_dist(0, 1000);
904 std::uniform_int_distribution<int>
op_dist(0, 3);
906 for (
int i = 0; i < 5000; ++i)
915 reference.push_front(val);
920 reference.push_back(val);
924 if (!reference.empty())
927 int ref_val = reference.front();
928 reference.pop_front();
934 if (!reference.empty())
937 int ref_val = reference.back();
938 reference.pop_back();
952 std::mt19937
gen(77777);
953 std::uniform_int_distribution<int>
val_dist(0, 1000);
979 ::testing::InitGoogleTest(&
argc,
argv);
Space-efficient bit array implementation.
Queue implemented with a single dynamic array.
T & put(const T &item)
Copy and put an item in the queue.
T get()
Remove the oldest item of the queue and return a copy.
Stack implemented with simple dynamic array and with bounds verification.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Contiguous array of bits.
int read_bit(const size_t i) const
Read bit i.
void write_bit(const size_t i, const unsigned int value)
Write bit i with the value.
constexpr size_t size() const noexcept
Returns the dimension of the bit array.
Dynamic doubly linked list with O(1) size and bidirectional access.
const size_t & size() const noexcept
Return the number of elements (constant time)
T remove_last()
Remove the last item of the list; return a copy of removed item.
T & append(const T &item)
Append a copied item at the end of the list.
T & insert(const T &item)
Insert a copy of item at the beginning of the list.
T remove_first()
Remove the first item of the list; return a copy of removed item.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
Dynamic set backed by balanced binary search trees with automatic memory management.
const size_t & size() const
Returns the cardinality of the set.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
bool has(const Key &key) const
size_t remove(const Key &key)
Removes a key from the dynamic set.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
size_t size() const noexcept
Return the number of elements.
bool is_empty() const noexcept
Return true is the array is empty.
Open addressing hash table with double hashing collision resolution.
Key * search(const Key &key) const noexcept
searches the table for the key.
void remove(const Key &key)
Remove a key from the hash table.
Open addressing hash table with linear probing collision resolution.
constexpr size_t size() const noexcept
Returns the number of entries in the table.
Key * insert(const Key &key)
Inserts a key into the hash table (copy version).
TEST_F(DynArrayEdgeCases, EmptyArray_SizeIsZero)
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Circular queue implementations backed by arrays.
Stack implementations backed by dynamic or fixed arrays.
Dynamic array container with automatic resizing.
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
Dynamic set implementations based on balanced binary search trees.
Open addressing hash table with double hashing.
Open addressing hash table with linear probing.