-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListTable.h
46 lines (39 loc) · 829 Bytes
/
ListTable.h
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
#pragma once
#ifndef LISTTABLE_H
#define LISTTABLE_H
#include <list>
#include <vector>
#include <algorithm>
//#include <string>
using namespace std;
template<class T>
class ListTable {
list<vector<T>> ls;
int currentSize;
size_t myhash(const T& value) {
return hash<T>()(value) % ls.size();
}
void rehash() {
}
public:
ListTable(int size = 101) :ls(101),currentSize(0) {};
void insert(const T& value) {
int pos = myhash(value);
ls[pos].push_back(value);
if (++currentSize >= 0.5 * ls.size()) {
rehash();
}
}
void del(const T& value) {
int pos = myhash(value);
ls.erase( find(ls[pos].begin(),ls.[pos].end,value) );
}
bool contains(const T& value) {
int pos = myhash(value);
if (find(ls[pos].begin(), ls[pos].end(), value) != ls[pos].end()) {
return true;
}
return false;
}
};
#endif