-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
116 lines (99 loc) · 3.9 KB
/
main.cpp
File metadata and controls
116 lines (99 loc) · 3.9 KB
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
111
112
113
114
115
116
#include "ds_hashset.h"
int main()
{
std::string filename, token;
int table_size = 100;
std::list<MovieData> movielist;
std::map<std::string, std::string> actorlist;
ds_hashset htable(table_size);
std::set<std::string> title_all, year_all, runtime_all;
std::set<std::list<std::string> > Genre_all, Actor_all, Role_all;
std::ifstream command("top250_example_input.txt"); // Temporary
while (command >> token)
{
if (token == "movies")
{
command >> filename;
std::ifstream infile(filename);
if (!infile) {
std::cerr << "cannot open file";
}
while (!infile.eof()) {
movielist.push_back(MovieData(infile, title_all, year_all, runtime_all,
Genre_all, Actor_all, Role_all));
}
std::list<std::string> emptylist;
Genre_all.insert(emptylist);
Actor_all.insert(emptylist);
Role_all.insert(emptylist);
infile.close();
year_all.insert("?");
runtime_all.insert("?");
title_all.insert("?");
}
else if (token == "actors")
{
command >> filename;
std::ifstream infile(filename);
if (!infile) {
std::cerr << "cannot open file";
}
std::string nconst, aname;
while (!infile.eof()) {
infile >> nconst >> aname;
actorlist[nconst] = aname;
}
infile.close();
for (std::set<std::string>::const_iterator it_title = title_all.cbegin();
it_title!=title_all.cend();it_title++){
for (std::set<std::string>::const_iterator it_year = year_all.cbegin();
it_year!=year_all.cend();it_year++){
for (std::set<std::string>::const_iterator it_runt = runtime_all.cbegin();
it_runt!=runtime_all.cend(); it_runt++){
for (std::set<std::list<std::string>>::const_iterator it_G = Genre_all.cbegin();
it_G!=Genre_all.cend(); it_G++){
for (std::set<std::list<std::string>>::const_iterator it_A = Actor_all.cbegin();
it_A!=Actor_all.cend(); it_A++){
for (std::set<std::list<std::string>>::const_iterator it_R = Role_all.cbegin();
it_R!=Role_all.cend(); it_R++){
int debug=htable.getsize();
assert(debug!=0);
Query one=Query(*it_title,*it_year,
*it_runt,*it_G,*it_A, *it_R);
std::pair<Query, std::list<MovieData*> > *one_value = new std::pair<Query, std::list<MovieData*> >(
one.compare(movielist));
if (one_value->second.size()!=0)
htable.insert(one_value); // ignore query with no match
}
}
}
}
}
}
}
else if (token == "table_size")
{
command >> table_size;
htable.change_size(table_size);
}
else if (token == "occupancy")
{
float f;
command >> f;
htable.change_occupancy_level(f);
}
else if (token == "query")
{
Query current_query(command);
htable.print(current_query, actorlist);
}
else if (token == "quit")
{
break;
}
else{
std::cerr << "Invalid input\n";
}
}
return 0;
}