-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
110 lines (93 loc) · 2.51 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <sstream>
#include <vector>
#include <thread>
#include <boost/tokenizer.hpp>
#include "Bucket.h"
#include "Rating.h"
#include "HashIndex.h"
#include "randomFile.h"
int
main(int argc, char* argv[])
{
/*
// Testing HashIndex
Rating r = { 1,307,3.5,1256677221 };
HashIndex index = HashIndex(27000000);
std::cout << index.h(r) << std::endl;
*/
/*
// Testing serialization
std::ostringstream oss;
{
Rating r1{ 1, 307, 3.5, 1256677221 }, r2{ 2, 308, 3.7, 2256677221 };
Bucket b{ 0, 2, {r1, r2} };
boost::archive::text_oarchive oa(oss);
oa << b;
}
Bucket cloned;
std::istringstream iss(oss.str());
{
boost::archive::text_iarchive ia(iss);
ia >> cloned;
}
{
std::ostringstream oss2;
boost::archive::text_oarchive oa(oss2);
oa << cloned;
std::cout << oss.str() << std::endl;
std::cout << oss2.str() << std::endl;
}
*/
/*
// Testing HashIndex init
HashIndex index = HashIndex(270);
index.check_init();
*/
/*
// Testing HashIndex insert
HashIndex index = HashIndex(270);
Rating r1{ 1, 307, 3.5, 1256677221 };
index.insert(r1);
index.check_insert(r1);
// Testing HashIndex update
Rating r2{ 1, 307, 5, 2256677221 };
index.update(r2);
index.check_insert(r1);
*/
/*
// Testing init from csv
HashIndex index = HashIndex("static/ratings.csv");
index.check_init();
Rating r2{ 1, 307, 5, 2256677221 };
index.check_insert(r2);
*/
/*
//Testing find
HashIndex index = HashIndex("static/ratings.csv");
Rating r = index.find(1, 307);
std::cout << r.userId << " " << r.movieId << " " << r.rating << std::endl;
*/
// Testing HashIndex
std::vector<Rating> ratings = {
{ 1,307,3.5,1256677221 }, { 2,308,4,1256677221 },
{ 3,309,4.5,1256677221 }, { 4,310,5,1256677221 },
{ 5,311,1.5,1256677221 }, { 6,312,2.5,1256677221 }
};
HashIndex index(270);
std::vector<std::thread> threads(ratings.size());
for(size_t i = 0; i < ratings.size(); ++i) {
threads[i] = std::thread(&HashIndex::insert, &index, ratings[i]);
}
for(size_t i = 0; i < ratings.size(); ++i) {
threads[i].join();
}
RandomFile rf("static/ratings.csv");
for(size_t i = 0; i < ratings.size(); ++i) {
threads[i] = std::thread(&RandomFile::insert, &rf, ratings[i]);
}
for(size_t i = 0; i < ratings.size(); ++i) {
threads[i].join();
}
return 0;
}