-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadditivedictionary.cpp
54 lines (37 loc) · 996 Bytes
/
additivedictionary.cpp
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
#include "additivedictionary.h"
#include <fstream>
AdditiveDictionary::AdditiveDictionary()
{
}
unsigned hash_function(ADWord *A){
return A->getAmount();
}
bool comp(ADWord A,ADWord B){
return A.getAmount() > B.getAmount();
}
bool equal(ADWord* A, ADWord* B){
return (A->getValue().compare(B->getValue()) == 0);
}
bool AdditiveDictionary::addValue(std::string value, unsigned amount){
ADWord V(value, amount);
HTChained::add(&V, hash_function);
return true;
}
bool AdditiveDictionary::addValueFromFile(std::string file_name){
std::ifstream file;
file.open(file_name);
std::string word;
while (file>>word) {
unsigned amount;
file>>amount;
addValue(word, amount);
}
return true;
}
bool AdditiveDictionary::findValue(std::string value, unsigned amount){
ADWord V(value, amount);
HTChained::find(&V, hash_function, equal);
return true;
}
bool AdditiveDictionary::delValue(std::string, unsigned){
}