#include #include #include #include #include #include #include #include using namespace origin; // The purpose of this test to is to randomly populate hash arrays with // sequences of random keys and measure both the load and distribution of // keys within the hash tables. // TODO: What happens if the keys in the input sequence aren't uniformly // distributed? typedef std::minstd_rand Generator; typedef std::uniform_int_distribution<> Distribution; using std::cout; static size_t const RUNS = 100; static size_t const N = 1021; template void run(size_t i, Gen& rng, Dist& dist, Hash& table) { typedef typename Hash::iterator Iter; // Insert numbers into the hash until we fail to place one. while(1) { int n = dist(rng); std::pair x = table.insert(n); if(!x.second && x.first == table.end()) { break; } // Build a description of the mapping. std::stringstream mapping; mapping << "(" << n << ":" << table.hasher()(n) % N << ")"; cout << /* Run Number*/ std::setw(4) << i << /* Table Size */ std::setw(4) << table.size() << /* Mapping */ std::setw(12) << mapping.str() << /* Displacement */ std::setw(8) << table.displacement(n) << /* Load */ std::setw(12) << table.load_factor() << "\n"; } } int main() { Generator rng(std::time(0)); Distribution dist(0, std::numeric_limits::max()); for(size_t i = 0; i < RUNS; ++i) { hash_array_set table; // std::unordered_set table; run(i, rng, dist, table); } cout << "\n"; return 0; }