33# include <gsl/gsl_rng.h>
63template <
template <
typename,
class>
class HashTable,
typename Key,
69 for (
typename Hset::Iterator it(s); it.has_curr(); it.next())
75template <
template <
typename,
class>
class HashTable,
typename Key,
86 for (
int k = 0;
k < 4;
k++)
88 cout <<
"k = " <<
k <<
endl
89 <<
"testing insertions and initial searches" <<
endl;
91 for (
int i = 0; i < n; i++)
96 if (table.search(
keys(i)) ==
nullptr)
100 table.insert(
keys(i));
103 cout <<
"done" <<
endl
106 table.print_stats(table.stats());
109 <<
"testing searches or previous inserted keys" <<
endl;
111 for (
int i = 0; i < n; i++)
113 const Key
k =
keys(i);
115 ptr = table.search(
k);
120 cout <<
"done!" <<
endl
122 <<
"testing deletion ...." <<
endl;
123 for (
int i = 0; i < n; i += 2)
125 ptr = table.search(
keys(i));
129 table.remove_ptr(ptr);
131 cout <<
"done!" <<
endl
133 <<
"Reinserting others keys ...." <<
endl;
134 for (
int i = 0; i < n; i += 2)
139 if (table.search(
keys(i)) ==
nullptr)
142 table.insert(
keys(i));
144 cout <<
"done!" <<
endl
146 <<
"Removing all the keys ...." <<
endl;
147 for (
int i = 0; i < n; i++)
149 const Key & key =
keys(i);
150 ptr = table.search(key);
152 table.remove_ptr(ptr);
155 assert(table.size() == 0);
156 cout <<
"done! k = " <<
k <<
endl
160 cout <<
"Sorting keys backup ...." <<
endl;
163 cout <<
"done!" <<
endl
165 <<
"Testing iterator ...." <<
endl
167 <<
"Reinserting the keys ...."
169 for (
int i = 0; i < n; ++i)
170 table.insert(
keys(i));
173 for (
typename Hset::Iterator it(table);
174 it.has_curr(); it.next(), ++
count)
176 const Key & curr = it.get_curr();
182 cout <<
"done!" <<
endl
184 <<
"Testing backward iterator ...." <<
endl;
186 typename Hset::Iterator it(table);
189 for (
int i = 0; it.has_curr(); it.prev(), ++i, ++
count)
191 const Key & curr = it.get_curr();
197 cout <<
"done!" <<
endl
200 cout <<
"done!" <<
endl
202 <<
"Testing del() of iterator ...." <<
endl
203 <<
"Deleting all the keys via del() of iterator"
206 for (
typename Hset::Iterator it(table); it.has_curr(); ++
count)
209 cout <<
"done!. Deleted " <<
count <<
" entries " <<
endl
215 cout <<
"Inserting again all keys ...." <<
endl
217 for (
int i = 0; i < n; ++i)
218 table.insert(
keys(i));
220 cout <<
"done!" <<
endl
222 <<
"Deleting a 10% of keys for causing deleted entries ...." <<
endl
224 for (
int i = 0; i < n/10; ++i)
227 const Key & key =
keys(idx);
229 Key * ptr = table.search(key);
233 table.remove_ptr(ptr);
236 table.print_stats(table.stats());
239 cout <<
"Testing copy constructor" <<
endl;
241 assert(aux.size() == table.size());
242 for (
typename Hset::Iterator it(table); it.has_curr(); it.next())
244 Key * key_ptr = aux.search(it.get_curr());
245 assert(key_ptr !=
nullptr);
246 assert(*key_ptr == it.get_curr());
248 cout <<
"done!" <<
endl;
252 cout <<
"Testing rvalue copy constructor ...." <<
endl;
261 cout <<
"done!" <<
endl
269 unsigned int t = std::time(0);
274 n = std::stoi(
argv[1]);
277 t = std::stoi(
argv[2]);
286 cout <<
"n must be positive" <<
endl;
290 cout <<
"testOhash " << n <<
" " << t <<
endl;
Core header for the Aleph-w library.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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.