本文整理汇总了C++中HashTable::hashFunct方法的典型用法代码示例。如果您正苦于以下问题:C++ HashTable::hashFunct方法的具体用法?C++ HashTable::hashFunct怎么用?C++ HashTable::hashFunct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable::hashFunct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
HashTable<int> hashtable;
int inc = 0;
int dec = 0;
int ninehun = 0;
int onehun = 0;
for (int i = 0; i < MAXHASH; i++) {
int hashed = hashtable.hashFunct(i);
if (hashed > 500) {
inc++;
}
if (hashed <= 500) {
dec++;
}
if (hashed > 900) {
ninehun++;
}
if (hashed < 100) {
onehun++;
}
cout << i << "----------" << hashed << endl;
}
cout << "Keys above 500: " << inc << " | Keys less than 500: " << dec << " | Keys above 900: " << ninehun << " | Keys below 100: " << onehun << endl;
int collisions = 0;
int size = 0;
for (size_t i = 0; i < MAXHASH; ++i) {
collisions = 0;
bool isGud = hashtable.insert(i, MAXHASH - i, collisions);
if (isGud) {
size++;
}
cout << "Inserted? " << isGud << endl;
cout << "Number of collisions: " << collisions << endl;
cout << "Actual size: " << size << endl;
}
collisions = 0;
hashtable.insert(777, 11025101160059, collisions);
int newVal = 0;
bool isFound = hashtable.find(777, newVal);
cout << "777 is found? " << isFound << endl;
bool isGone = hashtable.remove(777);
cout << "777 is gone? " << isGone << endl;
isFound = hashtable.find(777, newVal);
cout << "777 is found? (Should return false): " << isFound << endl;
cout << "Actual size: " << size << endl;
//Create test function to add random keys & keep track of number of collisions
for (size_t n = 100; n <= 1000; n = n + 100) {
for (size_t i = 0; i < MAXHASH; ++i) {
collisions = 0;
bool isGud = hashtable.remove(i);
if (isGud) {
--size;
}
}
srand(MAXHASH);
int random = rand() % 1000;
vector<int> coll;
for (size_t i = 0; i < n; ++i) {
collisions = 0;
bool isGud = hashtable.insert(i, random, collisions);
if (isGud) {
size++;
}
coll.push_back(collisions);
//cout << "Inserted record with key " << i << "? " << isGud << endl;
//cout << "Number of collisions: " << collisions << endl;
}
cout << "Attempted to insert " << n << " items." << endl;
cout << "Actually inserted " << size << " items." << endl;
int avg = 0;
int denom = coll.size();
for (size_t i = 0; i < MAXHASH; i++) {
avg = avg + coll.at(i);
coll.push_back(i);
}
avg = avg / denom;
cout << "Average number of collisions for " << n << " inserts: " << avg << endl;
cout << "The alpha value is: " << hashtable.alpha() << endl;
}
system("pause");
return 0;
}