-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadditivedictionary.cpp
More file actions
48 lines (36 loc) · 959 Bytes
/
additivedictionary.cpp
File metadata and controls
48 lines (36 loc) · 959 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
44
45
46
47
48
#include "additivedictionary.h"
#include <fstream>
AdditiveDictionary::AdditiveDictionary()
{
}
bool AdditiveDictionary::compare(std::string A, std::string B){
return A.length() > B.length();
}
bool comp(ADWord A,ADWord B){
return A.getAmount() > B.getAmount();
}
unsigned hash_function(ADWord *X){
return 1;
}
bool equ(ADWord *A, ADWord *B){
return (A->getValue().compare(B->getValue()) == 0);
}
bool AdditiveDictionary::addValue(std::string value, unsigned amount){
ADWord V(value, amount);
ADWord *in = hashTable::find(new ADWord(value, amount), hash_function, equ);
if (in){
in->setAmount(in->getAmount() + amount);
}else{
hashTable::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) {
addValue(word, 1);
}
return true;
}