making notes about the function pointer usage

This commit is contained in:
Jidong Xiao
2025-03-31 20:11:54 -04:00
committed by JamesFlare
parent 7a7c44ed25
commit a02407b35d

View File

@@ -23,6 +23,7 @@ unsigned int betterHash(const std::string& k, unsigned int N) {
} }
// a good hash function should distribute values evenly across N buckets. // a good hash function should distribute values evenly across N buckets.
// note that function pointers are used here
void testCollisions(unsigned int (*hashFunc)(const std::string&, unsigned int), void testCollisions(unsigned int (*hashFunc)(const std::string&, unsigned int),
const std::vector<std::string>& testStrings, unsigned int N) { const std::vector<std::string>& testStrings, unsigned int N) {
std::unordered_map<unsigned int, int> bucketCounts; std::unordered_map<unsigned int, int> bucketCounts;
@@ -53,6 +54,7 @@ std::vector<std::string> generateTestStrings(int count) {
return testStrings; return testStrings;
} }
// note that function pointers are used here
void benchmark(unsigned int (*hashFunc)(const std::string&, unsigned int), void benchmark(unsigned int (*hashFunc)(const std::string&, unsigned int),
const std::vector<std::string>& testStrings, unsigned int N) { const std::vector<std::string>& testStrings, unsigned int N) {
clock_t start = clock(); clock_t start = clock();