// ------------------------------------------------------------- // 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 open addressing, a.k.a. closed hashing) // Last update: 08/12/2024 // ------------------------------------------------------------- #ifndef _HASHTABLEOA_H_ #define _HASHTABLEOA_H_ #include #include #include #include template class HashTableOA { enum EntryType {EMPTY, ACTIVE, DELETED}; // Type of table entry struct HashEntry { // One table entry EntryType state; KeyType key; }; int size; // Size of the hash table int numberActive; // Number of active table entries (with keys) int numberDeleted; // Number of deleted table entries 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 HashTableOA(int n, std::function h) : size(n), numberActive(0), numberDeleted(0), table(n), hash(h) { for (int i=0; i