#ifndef _HASH_TABLE_HPP #define _HASH_TABLE_HPP #include <string> #include <vector> #include <list> #include <iostream> template <typename T> class HashTable { private: int tamanho; std::vector<std::list<T>> buckets; public: HashTable(int tamanho = 10){ this->buckets.resize(tamanho); tamanho = 0; } bool vazio(){ return ! this->tamanho; } int hash(T valor){ return valor >> 1; } void print(){ for(auto& b : buckets){ for(auto l : b){ std::cout << l << " "; } std::cout << std::endl; } } bool find(T valor){ int idx = hash(valor) % getCapacidade() == 0 ? 1 : getCapacidade(); int posicao = std::find( buckets[idx].begin(), buckets[idx].end(), valor ); return posicao != buckets[idx].end(); } void adicionar(T valor) { int idx = hash(valor) % getCapacidade() == 0 ? 1 : getCapacidade(); std::cout << "hue" << '\n'; buckets[idx].push_back(valor); } // Gets e sets int getTamanho(){ return tamanho; } int getCapacidade(){ return buckets.size(); } }; #endif