// ------------------------------------------------------------- // Algoritmos e Estruturas de Dados 2024/2025 - LEIC (FCUP/FEUP) // http://www.dcc.fc.up.pt/~pribeiro/aulas/aed2425/ // ------------------------------------------------------------- // A simple lightweight implemetation of hash tables // (using separate chaining, a.k.a. open hashing) // Last update: 08/12/2024 // ------------------------------------------------------------- #ifndef _HASHTABLESC_H_ #define _HASHTABLESC_H_ #include #include #include #include #include template class HashTableSC { int size; // Size of the hash table int numberKeys; // Number of inserted keys std::vector> table; // The hash table itself std::function hash; // Hash function: key -> unsigned public: // Constructor: receives the table size n and the hash function h HashTableSC(int n, std::function h) : size(n), numberKeys(0), table(n), hash(h) {} // Show contents of hash table (to check if implementation is correct) void showContents() { std::cout << "Size: " << size << " | Number of keys: " << numberKeys << " | Load Factor: " << std::fixed << std::setprecision(3) << (double)numberKeys / size << std::endl; for (int i=0; i