Newer
Older
Ítalo Epifânio de Lima e Silva
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#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