mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-24 20:52:16 +08:00
Retranslate the complete English edition from Simplified Chinese (#2010)
* Retranslate the complete English edition from Simplified Chinese * Polish three English explanations after reader-focused review
This commit is contained in:
@@ -17,14 +17,14 @@ struct Pair {
|
||||
}
|
||||
};
|
||||
|
||||
/* Hash table based on array implementation */
|
||||
/* Hash table implemented with an array */
|
||||
class ArrayHashMap {
|
||||
private:
|
||||
vector<Pair *> buckets;
|
||||
|
||||
public:
|
||||
ArrayHashMap() {
|
||||
// Initialize array with 100 buckets
|
||||
// Initialize an array containing 100 buckets
|
||||
buckets = vector<Pair *>(100);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class ArrayHashMap {
|
||||
return index;
|
||||
}
|
||||
|
||||
/* Query operation */
|
||||
/* Lookup operation */
|
||||
string get(int key) {
|
||||
int index = hashFunc(key);
|
||||
Pair *pair = buckets[index];
|
||||
@@ -51,7 +51,7 @@ class ArrayHashMap {
|
||||
return pair->val;
|
||||
}
|
||||
|
||||
/* Add operation */
|
||||
/* Insert operation */
|
||||
void put(int key, string val) {
|
||||
Pair *pair = new Pair(key, val);
|
||||
int index = hashFunc(key);
|
||||
@@ -61,7 +61,7 @@ class ArrayHashMap {
|
||||
/* Remove operation */
|
||||
void remove(int key) {
|
||||
int index = hashFunc(key);
|
||||
// Free memory and set to nullptr
|
||||
// Free the memory and set the pointer to nullptr
|
||||
delete buckets[index];
|
||||
buckets[index] = nullptr;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class ArrayHashMap {
|
||||
return valueSet;
|
||||
}
|
||||
|
||||
/* Print hash table */
|
||||
/* Print the hash table */
|
||||
void print() {
|
||||
for (Pair *kv : pairSet()) {
|
||||
cout << kv->key << " -> " << kv->val << endl;
|
||||
@@ -107,4 +107,4 @@ class ArrayHashMap {
|
||||
}
|
||||
};
|
||||
|
||||
// See array_hash_map_test.cpp for test cases
|
||||
// See array_hash_map_test.cpp for the test example
|
||||
|
||||
@@ -6,44 +6,44 @@
|
||||
|
||||
#include "./array_hash_map.cpp"
|
||||
|
||||
/* Driver Code */
|
||||
/* Driver code */
|
||||
int main() {
|
||||
/* Initialize hash table */
|
||||
/* Initialize the hash table */
|
||||
ArrayHashMap map = ArrayHashMap();
|
||||
|
||||
/* Add operation */
|
||||
// Add key-value pair (key, value) to the hash table
|
||||
map.put(12836, "Xiao Ha");
|
||||
map.put(15937, "Xiao Luo");
|
||||
map.put(16750, "Xiao Suan");
|
||||
map.put(13276, "Xiao Fa");
|
||||
map.put(10583, "Xiao Ya");
|
||||
cout << "\nAfter adding is complete, hash table is\nKey -> Value" << endl;
|
||||
/* Insert operation */
|
||||
// Insert the key-value pair (key, value) into the hash table
|
||||
map.put(12836, "小哈");
|
||||
map.put(15937, "小啰");
|
||||
map.put(16750, "小算");
|
||||
map.put(13276, "小法");
|
||||
map.put(10583, "小鸭");
|
||||
cout << "\nHash table after insertion:\nKey -> Value" << endl;
|
||||
map.print();
|
||||
|
||||
/* Query operation */
|
||||
// Input key into hash table to get value
|
||||
/* Lookup operation */
|
||||
// Look up key in the hash table to obtain value
|
||||
string name = map.get(15937);
|
||||
cout << "\nInput student ID 15937, query name " << name << endl;
|
||||
cout << "\nLook up student ID 15937 to obtain the name " << name << endl;
|
||||
|
||||
/* Remove operation */
|
||||
// Remove key-value pair (key, value) from hash table
|
||||
// Remove the key-value pair (key, value) from the hash table
|
||||
map.remove(10583);
|
||||
cout << "\nAfter removing 10583, hash table is\nKey -> Value" << endl;
|
||||
cout << "\nHash table after removing 10583:\nKey -> Value" << endl;
|
||||
map.print();
|
||||
|
||||
/* Traverse hash table */
|
||||
cout << "\nTraverse key-value pairs Key->Value" << endl;
|
||||
/* Traverse the hash table */
|
||||
cout << "\nTraverse key-value pairs: Key->Value" << endl;
|
||||
for (auto kv : map.pairSet()) {
|
||||
cout << kv->key << " -> " << kv->val << endl;
|
||||
}
|
||||
|
||||
cout << "\nTraverse keys only Key" << endl;
|
||||
cout << "\nTraverse keys only: Key" << endl;
|
||||
for (auto key : map.keySet()) {
|
||||
cout << key << endl;
|
||||
}
|
||||
|
||||
cout << "\nTraverse values only Value" << endl;
|
||||
cout << "\nTraverse values only: Value" << endl;
|
||||
for (auto val : map.valueSet()) {
|
||||
cout << val << endl;
|
||||
}
|
||||
|
||||
@@ -6,24 +6,24 @@
|
||||
|
||||
#include "../utils/common.hpp"
|
||||
|
||||
/* Driver Code */
|
||||
/* Driver code */
|
||||
int main() {
|
||||
int num = 3;
|
||||
size_t hashNum = hash<int>()(num);
|
||||
cout << "Hash value of integer " << num << " is " << hashNum << "\n";
|
||||
cout << "Integer " << num << " has hash value " << hashNum << "\n";
|
||||
|
||||
bool bol = true;
|
||||
size_t hashBol = hash<bool>()(bol);
|
||||
cout << "Hash value of boolean " << bol << " is " << hashBol << "\n";
|
||||
cout << "Boolean " << bol << " has hash value " << hashBol << "\n";
|
||||
|
||||
double dec = 3.14159;
|
||||
size_t hashDec = hash<double>()(dec);
|
||||
cout << "Hash value of decimal " << dec << " is " << hashDec << "\n";
|
||||
cout << "Floating-point number " << dec << " has hash value " << hashDec << "\n";
|
||||
|
||||
string str = "Hello Algo";
|
||||
string str = "Hello 算法";
|
||||
size_t hashStr = hash<string>()(str);
|
||||
cout << "Hash value of string " << str << " is " << hashStr << "\n";
|
||||
cout << "String " << str << " has hash value " << hashStr << "\n";
|
||||
|
||||
// In C++, built-in std::hash() only provides hash calculation for basic data types
|
||||
// Hash calculation for arrays and objects needs to be implemented manually
|
||||
// C++ std::hash provides hashing for fundamental types and selected standard-library types
|
||||
// For arrays and unsupported object types, supply your own hash implementation
|
||||
}
|
||||
|
||||
@@ -6,38 +6,38 @@
|
||||
|
||||
#include "../utils/common.hpp"
|
||||
|
||||
/* Driver Code */
|
||||
/* Driver code */
|
||||
int main() {
|
||||
/* Initialize hash table */
|
||||
/* Initialize the hash table */
|
||||
unordered_map<int, string> map;
|
||||
|
||||
/* Add operation */
|
||||
// Add key-value pair (key, value) to the hash table
|
||||
map[12836] = "Xiao Ha";
|
||||
map[15937] = "Xiao Luo";
|
||||
map[16750] = "Xiao Suan";
|
||||
map[13276] = "Xiao Fa";
|
||||
map[10583] = "Xiao Ya";
|
||||
cout << "\nAfter adding is complete, hash table is\nKey -> Value" << endl;
|
||||
/* Insert operation */
|
||||
// Insert the key-value pair (key, value) into the hash table
|
||||
map[12836] = "小哈";
|
||||
map[15937] = "小啰";
|
||||
map[16750] = "小算";
|
||||
map[13276] = "小法";
|
||||
map[10583] = "小鸭";
|
||||
cout << "\nHash table after insertion:\nKey -> Value" << endl;
|
||||
printHashMap(map);
|
||||
|
||||
/* Query operation */
|
||||
// Input key into hash table to get value
|
||||
/* Lookup operation */
|
||||
// Look up key in the hash table to obtain value
|
||||
string name = map[15937];
|
||||
cout << "\nInput student ID 15937, query name " << name << endl;
|
||||
cout << "\nLook up student ID 15937 to obtain the name " << name << endl;
|
||||
|
||||
/* Remove operation */
|
||||
// Remove key-value pair (key, value) from hash table
|
||||
// Remove the key-value pair (key, value) from the hash table
|
||||
map.erase(10583);
|
||||
cout << "\nAfter removing 10583, hash table is\nKey -> Value" << endl;
|
||||
cout << "\nHash table after removing 10583:\nKey -> Value" << endl;
|
||||
printHashMap(map);
|
||||
|
||||
/* Traverse hash table */
|
||||
cout << "\nTraverse key-value pairs Key->Value" << endl;
|
||||
/* Traverse the hash table */
|
||||
cout << "\nTraverse key-value pairs: Key->Value" << endl;
|
||||
for (auto kv : map) {
|
||||
cout << kv.first << " -> " << kv.second << endl;
|
||||
}
|
||||
cout << "\nTraverse Key->Value using iterator" << endl;
|
||||
cout << "\nTraverse Key->Value pairs using an iterator" << endl;
|
||||
for (auto iter = map.begin(); iter != map.end(); iter++) {
|
||||
cout << iter->first << "->" << iter->second << endl;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ class HashMapChaining {
|
||||
private:
|
||||
int size; // Number of key-value pairs
|
||||
int capacity; // Hash table capacity
|
||||
double loadThres; // Load factor threshold for triggering expansion
|
||||
int extendRatio; // Expansion multiplier
|
||||
double loadThres; // Load factor threshold that triggers capacity growth
|
||||
int extendRatio; // Capacity growth factor
|
||||
vector<vector<Pair *>> buckets; // Bucket array
|
||||
|
||||
public:
|
||||
@@ -41,34 +41,34 @@ class HashMapChaining {
|
||||
return (double)size / (double)capacity;
|
||||
}
|
||||
|
||||
/* Query operation */
|
||||
/* Lookup operation */
|
||||
string get(int key) {
|
||||
int index = hashFunc(key);
|
||||
// Traverse bucket, if key is found, return corresponding val
|
||||
// Traverse the bucket; if key is found, return its corresponding val
|
||||
for (Pair *pair : buckets[index]) {
|
||||
if (pair->key == key) {
|
||||
return pair->val;
|
||||
}
|
||||
}
|
||||
// Return empty string if key not found
|
||||
// Return an empty string if key is not found
|
||||
return "";
|
||||
}
|
||||
|
||||
/* Add operation */
|
||||
/* Insert operation */
|
||||
void put(int key, string val) {
|
||||
// When load factor exceeds threshold, perform expansion
|
||||
// Grow the capacity when the load factor exceeds the threshold
|
||||
if (loadFactor() > loadThres) {
|
||||
extend();
|
||||
}
|
||||
int index = hashFunc(key);
|
||||
// Traverse bucket, if specified key is encountered, update corresponding val and return
|
||||
// Traverse the bucket; if the specified key is found, update its val and return
|
||||
for (Pair *pair : buckets[index]) {
|
||||
if (pair->key == key) {
|
||||
pair->val = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If key does not exist, append key-value pair to the end
|
||||
// If key is absent, append the key-value pair at the end
|
||||
buckets[index].push_back(new Pair(key, val));
|
||||
size++;
|
||||
}
|
||||
@@ -77,11 +77,11 @@ class HashMapChaining {
|
||||
void remove(int key) {
|
||||
int index = hashFunc(key);
|
||||
auto &bucket = buckets[index];
|
||||
// Traverse bucket and remove key-value pair from it
|
||||
// Traverse the bucket and remove the key-value pair
|
||||
for (int i = 0; i < bucket.size(); i++) {
|
||||
if (bucket[i]->key == key) {
|
||||
Pair *tmp = bucket[i];
|
||||
bucket.erase(bucket.begin() + i); // Remove key-value pair from it
|
||||
bucket.erase(bucket.begin() + i); // Remove the key-value pair from the list
|
||||
delete tmp; // Free memory
|
||||
size--;
|
||||
return;
|
||||
@@ -89,16 +89,16 @@ class HashMapChaining {
|
||||
}
|
||||
}
|
||||
|
||||
/* Expand hash table */
|
||||
/* Grow the hash table capacity */
|
||||
void extend() {
|
||||
// Temporarily store the original hash table
|
||||
// Keep a copy of the original bucket array
|
||||
vector<vector<Pair *>> bucketsTmp = buckets;
|
||||
// Initialize expanded new hash table
|
||||
// Initialize a new hash table with the expanded capacity
|
||||
capacity *= extendRatio;
|
||||
buckets.clear();
|
||||
buckets.resize(capacity);
|
||||
size = 0;
|
||||
// Move key-value pairs from original hash table to new hash table
|
||||
// Move the key-value pairs from the original hash table to the new one
|
||||
for (auto &bucket : bucketsTmp) {
|
||||
for (Pair *pair : bucket) {
|
||||
put(pair->key, pair->val);
|
||||
@@ -108,7 +108,7 @@ class HashMapChaining {
|
||||
}
|
||||
}
|
||||
|
||||
/* Print hash table */
|
||||
/* Print the hash table */
|
||||
void print() {
|
||||
for (auto &bucket : buckets) {
|
||||
cout << "[";
|
||||
@@ -120,30 +120,30 @@ class HashMapChaining {
|
||||
}
|
||||
};
|
||||
|
||||
/* Driver Code */
|
||||
/* Driver code */
|
||||
int main() {
|
||||
/* Initialize hash table */
|
||||
/* Initialize the hash table */
|
||||
HashMapChaining map = HashMapChaining();
|
||||
|
||||
/* Add operation */
|
||||
// Add key-value pair (key, value) to the hash table
|
||||
map.put(12836, "Xiao Ha");
|
||||
map.put(15937, "Xiao Luo");
|
||||
map.put(16750, "Xiao Suan");
|
||||
map.put(13276, "Xiao Fa");
|
||||
map.put(10583, "Xiao Ya");
|
||||
cout << "\nAfter adding is complete, hash table is\nKey -> Value" << endl;
|
||||
/* Insert operation */
|
||||
// Insert the key-value pair (key, value) into the hash table
|
||||
map.put(12836, "小哈");
|
||||
map.put(15937, "小啰");
|
||||
map.put(16750, "小算");
|
||||
map.put(13276, "小法");
|
||||
map.put(10583, "小鸭");
|
||||
cout << "\nHash table after insertion:\nKey -> Value" << endl;
|
||||
map.print();
|
||||
|
||||
/* Query operation */
|
||||
// Input key into hash table to get value
|
||||
/* Lookup operation */
|
||||
// Look up key in the hash table to obtain value
|
||||
string name = map.get(13276);
|
||||
cout << "\nInput student ID 13276, query name " << name << endl;
|
||||
cout << "\nLook up student ID 13276 to obtain the name " << name << endl;
|
||||
|
||||
/* Remove operation */
|
||||
// Remove key-value pair (key, value) from hash table
|
||||
// Remove the key-value pair (key, value) from the hash table
|
||||
map.remove(12836);
|
||||
cout << "\nAfter removing 12836, hash table is\nKey -> Value" << endl;
|
||||
cout << "\nHash table after removing 12836:\nKey -> Value" << endl;
|
||||
map.print();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -11,10 +11,10 @@ class HashMapOpenAddressing {
|
||||
private:
|
||||
int size; // Number of key-value pairs
|
||||
int capacity = 4; // Hash table capacity
|
||||
const double loadThres = 2.0 / 3.0; // Load factor threshold for triggering expansion
|
||||
const int extendRatio = 2; // Expansion multiplier
|
||||
const double loadThres = 2.0 / 3.0; // Load factor threshold that triggers capacity growth
|
||||
const int extendRatio = 2; // Capacity growth factor
|
||||
vector<Pair *> buckets; // Bucket array
|
||||
Pair *TOMBSTONE = new Pair(-1, "-1"); // Removal marker
|
||||
Pair *TOMBSTONE = new Pair(-1, "-1"); // Tombstone marker
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
@@ -41,68 +41,68 @@ class HashMapOpenAddressing {
|
||||
return (double)size / capacity;
|
||||
}
|
||||
|
||||
/* Search for bucket index corresponding to key */
|
||||
/* Find the bucket index for key */
|
||||
int findBucket(int key) {
|
||||
int index = hashFunc(key);
|
||||
int firstTombstone = -1;
|
||||
// Linear probing, break when encountering an empty bucket
|
||||
// Probe linearly until an empty bucket is reached
|
||||
while (buckets[index] != nullptr) {
|
||||
// If key is encountered, return the corresponding bucket index
|
||||
// If key is found, return its bucket index
|
||||
if (buckets[index]->key == key) {
|
||||
// If a removal marker was encountered before, move the key-value pair to that index
|
||||
// If a tombstone was encountered earlier, move the key-value pair to that index
|
||||
if (firstTombstone != -1) {
|
||||
buckets[firstTombstone] = buckets[index];
|
||||
buckets[index] = TOMBSTONE;
|
||||
return firstTombstone; // Return the moved bucket index
|
||||
return firstTombstone; // Return the bucket index after the move
|
||||
}
|
||||
return index; // Return bucket index
|
||||
return index; // Return the bucket index
|
||||
}
|
||||
// Record the first removal marker encountered
|
||||
// Record the first tombstone encountered
|
||||
if (firstTombstone == -1 && buckets[index] == TOMBSTONE) {
|
||||
firstTombstone = index;
|
||||
}
|
||||
// Calculate bucket index, wrap around to the head if past the tail
|
||||
// Calculate the bucket index, wrapping to the beginning after the end
|
||||
index = (index + 1) % capacity;
|
||||
}
|
||||
// If key does not exist, return the index for insertion
|
||||
// If key is absent, return the index for insertion
|
||||
return firstTombstone == -1 ? index : firstTombstone;
|
||||
}
|
||||
|
||||
/* Query operation */
|
||||
/* Lookup operation */
|
||||
string get(int key) {
|
||||
// Search for bucket index corresponding to key
|
||||
// Find the bucket index for key
|
||||
int index = findBucket(key);
|
||||
// If key-value pair is found, return corresponding val
|
||||
// If the key-value pair is found, return its val
|
||||
if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {
|
||||
return buckets[index]->val;
|
||||
}
|
||||
// Return empty string if key-value pair does not exist
|
||||
// Return an empty string if the key-value pair does not exist
|
||||
return "";
|
||||
}
|
||||
|
||||
/* Add operation */
|
||||
/* Insert operation */
|
||||
void put(int key, string val) {
|
||||
// When load factor exceeds threshold, perform expansion
|
||||
// Grow the capacity when the load factor exceeds the threshold
|
||||
if (loadFactor() > loadThres) {
|
||||
extend();
|
||||
}
|
||||
// Search for bucket index corresponding to key
|
||||
// Find the bucket index for key
|
||||
int index = findBucket(key);
|
||||
// If key-value pair is found, overwrite val and return
|
||||
// If the key-value pair is found, overwrite val and return
|
||||
if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {
|
||||
buckets[index]->val = val;
|
||||
return;
|
||||
}
|
||||
// If key-value pair does not exist, add the key-value pair
|
||||
// If the key-value pair is absent, insert it
|
||||
buckets[index] = new Pair(key, val);
|
||||
size++;
|
||||
}
|
||||
|
||||
/* Remove operation */
|
||||
void remove(int key) {
|
||||
// Search for bucket index corresponding to key
|
||||
// Find the bucket index for key
|
||||
int index = findBucket(key);
|
||||
// If key-value pair is found, overwrite it with removal marker
|
||||
// If the key-value pair is found, replace it with a tombstone
|
||||
if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {
|
||||
delete buckets[index];
|
||||
buckets[index] = TOMBSTONE;
|
||||
@@ -110,15 +110,15 @@ class HashMapOpenAddressing {
|
||||
}
|
||||
}
|
||||
|
||||
/* Expand hash table */
|
||||
/* Grow the hash table capacity */
|
||||
void extend() {
|
||||
// Temporarily store the original hash table
|
||||
// Keep a copy of the original bucket array
|
||||
vector<Pair *> bucketsTmp = buckets;
|
||||
// Initialize expanded new hash table
|
||||
// Initialize a new hash table with the expanded capacity
|
||||
capacity *= extendRatio;
|
||||
buckets = vector<Pair *>(capacity, nullptr);
|
||||
size = 0;
|
||||
// Move key-value pairs from original hash table to new hash table
|
||||
// Move the key-value pairs from the original hash table to the new one
|
||||
for (Pair *pair : bucketsTmp) {
|
||||
if (pair != nullptr && pair != TOMBSTONE) {
|
||||
put(pair->key, pair->val);
|
||||
@@ -127,7 +127,7 @@ class HashMapOpenAddressing {
|
||||
}
|
||||
}
|
||||
|
||||
/* Print hash table */
|
||||
/* Print the hash table */
|
||||
void print() {
|
||||
for (Pair *pair : buckets) {
|
||||
if (pair == nullptr) {
|
||||
@@ -141,30 +141,30 @@ class HashMapOpenAddressing {
|
||||
}
|
||||
};
|
||||
|
||||
/* Driver Code */
|
||||
/* Driver code */
|
||||
int main() {
|
||||
// Initialize hash table
|
||||
// Initialize the hash table
|
||||
HashMapOpenAddressing hashmap;
|
||||
|
||||
// Add operation
|
||||
// Add key-value pair (key, val) to the hash table
|
||||
hashmap.put(12836, "Xiao Ha");
|
||||
hashmap.put(15937, "Xiao Luo");
|
||||
hashmap.put(16750, "Xiao Suan");
|
||||
hashmap.put(13276, "Xiao Fa");
|
||||
hashmap.put(10583, "Xiao Ya");
|
||||
cout << "\nAfter adding is complete, hash table is\nKey -> Value" << endl;
|
||||
// Insert operation
|
||||
// Insert the key-value pair (key, val) into the hash table
|
||||
hashmap.put(12836, "小哈");
|
||||
hashmap.put(15937, "小啰");
|
||||
hashmap.put(16750, "小算");
|
||||
hashmap.put(13276, "小法");
|
||||
hashmap.put(10583, "小鸭");
|
||||
cout << "\nHash table after insertion:\nKey -> Value" << endl;
|
||||
hashmap.print();
|
||||
|
||||
// Query operation
|
||||
// Input key into hash table to get value val
|
||||
// Lookup operation
|
||||
// Look up key in the hash table to obtain val
|
||||
string name = hashmap.get(13276);
|
||||
cout << "\nInput student ID 13276, query name " << name << endl;
|
||||
cout << "\nLook up student ID 13276 to obtain the name " << name << endl;
|
||||
|
||||
// Remove operation
|
||||
// Remove key-value pair (key, val) from hash table
|
||||
// Remove the key-value pair (key, val) from the hash table
|
||||
hashmap.remove(16750);
|
||||
cout << "\nAfter removing 16750, hash table is\nKey -> Value" << endl;
|
||||
cout << "\nHash table after removing 16750:\nKey -> Value" << endl;
|
||||
hashmap.print();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ int xorHash(string key) {
|
||||
return hash & MODULUS;
|
||||
}
|
||||
|
||||
/* Rotational hash */
|
||||
/* Rotating hash */
|
||||
int rotHash(string key) {
|
||||
long long hash = 0;
|
||||
const int MODULUS = 1000000007;
|
||||
@@ -46,21 +46,21 @@ int rotHash(string key) {
|
||||
return (int)hash;
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
/* Driver code */
|
||||
int main() {
|
||||
string key = "Hello Algo";
|
||||
string key = "Hello 算法";
|
||||
|
||||
int hash = addHash(key);
|
||||
cout << "Additive hash value is " << hash << endl;
|
||||
cout << "Additive hash value: " << hash << endl;
|
||||
|
||||
hash = mulHash(key);
|
||||
cout << "Multiplicative hash value is " << hash << endl;
|
||||
cout << "Multiplicative hash value: " << hash << endl;
|
||||
|
||||
hash = xorHash(key);
|
||||
cout << "XOR hash value is " << hash << endl;
|
||||
cout << "XOR hash value: " << hash << endl;
|
||||
|
||||
hash = rotHash(key);
|
||||
cout << "Rotational hash value is " << hash << endl;
|
||||
cout << "Rotation hash value: " << hash << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user