51template <
template <
typename,
class>
class HashTable,
typename Key,
55 typedef HashTable<Key, Cmp> Hset;
57 for (
auto it = s.get_it(); it.has_curr(); it.next())
58 ret_val.insert(it.get_curr());
63template <
template <
typename,
class>
class HashTable,
typename Key,
67 typedef HashTable<Key, Cmp> Hset;
74 for (
int k = 0;
k < 4;
k++)
76 cout <<
"k = " <<
k << endl
77 <<
"testing insertions and initial searches" << endl;
79 for (
int i = 0; i < n; i++)
84 if (table.search(
keys(i)) ==
nullptr)
88 table.insert(
keys(i));
91 cout <<
"done" << endl
94 table.print_stats(table.stats());
97 <<
"testing searches or previous inserted keys" << endl;
99 for (
int i = 0; i < n; i++)
101 const Key
k =
keys(i);
103 ptr = table.search(
k);
105 assert(ptr !=
nullptr);
106 assert(*ptr ==
keys(i));
108 cout <<
"done!" << endl
110 <<
"testing deletion ...." << endl;
111 for (
int i = 0; i < n; i += 2)
113 ptr = table.search(
keys(i));
115 assert(ptr !=
nullptr);
117 table.remove_ptr(ptr);
119 cout <<
"done!" << endl
121 <<
"Reinserting others keys ...." << endl;
122 for (
int i = 0; i < n; i += 2)
127 if (table.search(
keys(i)) ==
nullptr)
130 table.insert(
keys(i));
132 cout <<
"done!" << endl
134 <<
"Removing all the keys ...." << endl;
135 for (
int i = 0; i < n; i++)
137 const Key & key =
keys(i);
138 ptr = table.search(key);
139 assert(ptr !=
nullptr);
140 table.remove_ptr(ptr);
143 assert(table.size() == 0);
144 cout <<
"done! k = " <<
k << endl
148 cout <<
"Sorting keys backup ...." << endl;
151 cout <<
"done!" << endl
153 <<
"Testing iterator ...." << endl
155 <<
"Reinserting the keys ...."
157 for (
int i = 0; i < n; ++i)
158 table.insert(
keys(i));
161 for (
typename Hset::Iterator it(table);
162 it.has_curr(); it.next(), ++
count)
164 const Key & curr = it.get_curr();
167 assert(curr ==
keys(idx));
169 assert(
count == table.size());
170 cout <<
"done!" << endl
172 <<
"Testing backward iterator ...." << endl;
174 typename Hset::Iterator it(table);
177 for (
int i = 0; it.has_curr(); it.prev(), ++i, ++
count)
179 const Key & curr = it.get_curr();
182 assert(curr ==
keys(idx));
184 assert(
count == table.size());
185 cout <<
"done!" << endl
188 cout <<
"done!" << endl
190 <<
"Testing del() of iterator ...." << endl
191 <<
"Deleting all the keys via del() of iterator"
194 for (
typename Hset::Iterator it(table); it.has_curr(); ++
count)
197 cout <<
"done!. Deleted " <<
count <<
" entries " << endl
201 assert(table.is_empty());
203 cout <<
"Inserting again all keys ...." << endl
205 for (
int i = 0; i < n; ++i)
206 table.insert(
keys(i));
208 cout <<
"done!" << endl
210 <<
"Deleting a 10% of keys for causing deleted entries ...." << endl
212 for (
int i = 0; i < n/10; ++i)
215 const Key & key =
keys(idx);
217 Key * ptr = table.search(key);
221 table.remove_ptr(ptr);
224 table.print_stats(table.stats());
227 cout <<
"Testing copy constructor" << endl;
229 assert(aux.size() == table.size());
230 for (
typename Hset::Iterator it(table); it.has_curr(); it.next())
232 Key * key_ptr = aux.search(it.get_curr());
233 assert(key_ptr !=
nullptr);
234 assert(*key_ptr == it.get_curr());
236 cout <<
"done!" << endl;
240 cout <<
"Testing rvalue copy constructor ...." << endl;
243 assert(aux == table);
247 assert(aux == table);
249 cout <<
"done!" << endl
254int main(
int argc,
char *argv[])
257 unsigned int t = std::time(0);
262 n = std::stoi(argv[1]);
265 t = std::stoi(argv[2]);
274 cout <<
"n must be positive" << endl;
278 cout <<
"testOhash " << n <<
" " << t << endl;
282 test_hash_table<ODhashTable, unsigned int>(n,
r);
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
Core header for the Aleph-w library.
A random number generator with the sequences of GSL's gsl_rng_mt19937.
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
unsigned long uniform_int(const unsigned long n)
An integer in [0, n), each with the same probability, as gsl_rng_uniform_int(r, n).
unsigned long get() noexcept
The next number, as operator()().
bool binary_search(Itor beg, Itor end, const T &value)
Binary search for a value.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
void quicksort_op(C< T > &a, const Compare &cmp=Compare(), const size_t threshold=Quicksort_Threshold)
Optimized quicksort for containers using operator().
HashTable< Key, Cmp > create_table(const HashTable< Key, Cmp > &s)
static unsigned long tbl_size
void test_hash_table(size_t n, Gsl_Compatible_Rng &r)
Lazy and scalable dynamic array implementation.
Open addressing hash table with double hashing.
Open addressing hash table with linear probing.
Comprehensive sorting algorithms and search utilities for Aleph-w.