-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashValley.cpp
More file actions
46 lines (42 loc) · 868 Bytes
/
HashValley.cpp
File metadata and controls
46 lines (42 loc) · 868 Bytes
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
#include "HashValley.h"
HashValley::HashValley()
{
sizeHashTable = 41;
hashTable.resize(41);
}
int HashValley::HashFunction(string Vall)
{
int sum = 0;
for (char c : Vall) {
sum += (int)(c);
}
return sum % sizeHashTable;
}
void HashValley::insert(valley* Vall)
{
int index = HashFunction(Vall->getName());
hashTable[index].push_back(Vall);
}
valley* HashValley::search(string Vall)
{
if (!hashTable.empty()) {
int index = HashFunction(Vall);
if (index < hashTable.size()) {
for (auto x : hashTable[index]) {
if (x->getName() == Vall) {
return x;
}
}
}
}
return NULL;
}
void HashValley::Deleted(valley Vall) {
int index = HashFunction(Vall.getName());
for (auto it = hashTable[index].begin(); it != hashTable[index].end(); ++it) {
if ((*it)->getName() == Vall.getName()) {
hashTable[index].erase(it);
break;
}
}
}