55 Entry(
unsigned long k,
unsigned long v)
64 cout <<
"Capacity = " << table.
capacity() << endl
65 <<
"size = " << table.
size() << endl
66 <<
"busy slots = " << table.
busy_slots() << endl
67 <<
"expansions = " << table.
expansions() << endl
68 <<
"alpha = " << 1.0*table.
size()/table.
capacity() << endl;
71int main(
int argc,
char *argv[])
73 const unsigned long numNodes = 10000;
75 unsigned long i, n = numNodes;
79 unsigned int t = std::time(NULL);
84 n = std::stoul(argv[1]);
87 t = std::stoul(argv[2]);
96 cout <<
"n must be positive" << endl;
102 cout <<
"testDynamicHash " << n <<
" " << t << endl;
111 cout <<
"Inserting..." << endl;
113 for (i = 0; i < n; i++)
117 value =
keys[i] = (
unsigned long) (10*n*(rand() /(RAND_MAX + 1.0)));
121 cout <<
value <<
" ";
133 cout << endl <<
"Searching..." << endl;
135 for (i = 0; i < n; i++)
141 cout << endl <<
"Error key " <<
keys[i] <<
" not found" << endl;
146 cout <<
"Testing iterator" << endl;
152 cout << it.get_curr()->get_key() <<
" ";
157 cout << endl <<
"testing deleting ..." << endl;
161 for (i = 0; i < n; i++)
171 AH_ERROR(
"%u th key %u not found\n", (
int) i, (
int)
keys[i]);
175 catch (exception& exc)
177 cout << exc.what() <<
" exception has been thrown" << endl;
181 cout <<
" unknown exception has been thrown" << endl;
184 assert(table.
size() == 0);
#define AH_ERROR(...)
Print an error message (always enabled).
Core header for the Aleph-w library.
size_t size_t int32_t value
bool has_curr() const noexcept
Return true if the iterator has current item.
Generic linear hash table.
const size_t & capacity() const noexcept
Returns the table capacity.
const size_t & size() const noexcept
Returns the number of elements in the table.
const size_t & expansions() const noexcept
Returns the expansion level performed on the table.
Bucket * remove(Bucket *bucket) noexcept
Removes bucket from the table, without freeing it.
const size_t & busy_slots() const noexcept
Returns the number of busy slots in the table.
Bucket * insert(Bucket *bucket)
Insert bucket in the table.
Bucket * search(const Key &key) const noexcept
Search for key in the linear hash table.
Main namespace for Aleph-w library functions.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Entry(unsigned long k, unsigned long v)
void print_stats(LinearHashTableVtl< unsigned long > &table)
Linear hashing with chaining.