28# include <gsl/gsl_rng.h>
58template <
template <
typename,
class>
class HashTable,
typename Key,
64 for (
typename Hset::Iterator it(s); it.has_curr(); it.next())
70template <
template <
typename,
class>
class HashTable,
typename Key,
81 for (
int k = 0;
k < 4;
k++)
83 cout <<
"k = " <<
k <<
endl
84 <<
"testing insertions and initial searches" <<
endl;
86 for (
int i = 0; i < n; i++)
91 if (table.search(
keys(i)) ==
nullptr)
95 table.insert(
keys(i));
98 cout <<
"done" <<
endl
101 table.print_stats(table.stats());
104 <<
"testing searches or previous inserted keys" <<
endl;
106 for (
int i = 0; i < n; i++)
108 const Key
k =
keys(i);
110 ptr = table.search(
k);
115 cout <<
"done!" <<
endl
117 <<
"testing deletion ...." <<
endl;
118 for (
int i = 0; i < n; i += 2)
120 ptr = table.search(
keys(i));
124 table.remove_ptr(ptr);
126 cout <<
"done!" <<
endl
128 <<
"Reinserting others keys ...." <<
endl;
129 for (
int i = 0; i < n; i += 2)
134 if (table.search(
keys(i)) ==
nullptr)
137 table.insert(
keys(i));
139 cout <<
"done!" <<
endl
141 <<
"Removing all the keys ...." <<
endl;
142 for (
int i = 0; i < n; i++)
144 const Key & key =
keys(i);
145 ptr = table.search(key);
147 table.remove_ptr(ptr);
150 assert(table.size() == 0);
151 cout <<
"done! k = " <<
k <<
endl
155 cout <<
"Sorting keys backup ...." <<
endl;
158 cout <<
"done!" <<
endl
160 <<
"Testing iterator ...." <<
endl
162 <<
"Reinserting the keys ...."
164 for (
int i = 0; i < n; ++i)
165 table.insert(
keys(i));
168 for (
typename Hset::Iterator it(table);
169 it.has_curr(); it.next(), ++
count)
171 const Key & curr = it.get_curr();
177 cout <<
"done!" <<
endl
179 <<
"Testing backward iterator ...." <<
endl;
181 typename Hset::Iterator it(table);
184 for (
int i = 0; it.has_curr(); it.prev(), ++i, ++
count)
186 const Key & curr = it.get_curr();
192 cout <<
"done!" <<
endl
195 cout <<
"done!" <<
endl
197 <<
"Testing del() of iterator ...." <<
endl
198 <<
"Deleting all the keys via del() of iterator"
201 for (
typename Hset::Iterator it(table); it.has_curr(); ++
count)
204 cout <<
"done!. Deleted " <<
count <<
" entries " <<
endl
210 cout <<
"Inserting again all keys ...." <<
endl
212 for (
int i = 0; i < n; ++i)
213 table.insert(
keys(i));
215 cout <<
"done!" <<
endl
217 <<
"Deleting a 10% of keys for causing deleted entries ...." <<
endl
219 for (
int i = 0; i < n/10; ++i)
222 const Key & key =
keys(idx);
224 Key * ptr = table.search(key);
228 table.remove_ptr(ptr);
231 table.print_stats(table.stats());
234 cout <<
"Testing copy constructor" <<
endl;
236 assert(aux.size() == table.size());
237 for (
typename Hset::Iterator it(table); it.has_curr(); it.next())
239 Key * key_ptr = aux.search(it.get_curr());
240 assert(key_ptr !=
nullptr);
241 assert(*key_ptr == it.get_curr());
243 cout <<
"done!" <<
endl;
247 cout <<
"Testing rvalue copy constructor ...." <<
endl;
256 cout <<
"done!" <<
endl
264 unsigned int t = std::time(0);
269 n = std::stoi(
argv[1]);
272 t = std::stoi(
argv[2]);
281 cout <<
"n must be positive" <<
endl;
285 cout <<
"testOhash " << n <<
" " << t <<
endl;
Core header for the Aleph-w library.
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.
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().
gsl_rng_holder(unsigned int seed)
void test_hash_table(size_t n, gsl_rng *r)
HashTable< Key, Cmp > create_table(const HashTable< Key, Cmp > &s)
static unsigned long tbl_size
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.