-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmydatastore.h
executable file
·132 lines (103 loc) · 3.69 KB
/
mydatastore.h
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef MYDATASTORE_H
#define MYDATASTORE_H
#include <string>
#include <set>
#include <vector>
#include <map>
#include "product.h"
#include "user.h"
#include "util.h"
#include "datastore.h"
#include "review.h"
class MyDataStore : public DataStore{
public:
MyDataStore();
~MyDataStore();
/**
* Adds a product to the data store
*/
void addProduct(Product* p);
/**
* Adds a user to the data store
*/
void addUser(User* u);
/**
* Performs a search of products whose keywords match the given "terms"
* type 0 = AND search (intersection of results for each term) while
* type 1 = OR search (union of results for each term)
*/
std::vector<Product*> search(std::vector<std::string>& terms, int type);
/**
* Adds a given item to the cart given its index of the search position
*/
void addingToCart(int resultIndex);
/**
* Returns the cart by reference
*/
void viewingToCart();
/**
* Buys the shit in the cart from bezos
*/
void buyingToCart();
/**
* Reproduce the database file from the current Products and User values
*/
void dump(std::ostream& ofile);
void addReview(const std::string& prodName,
int rating,
const std::string& username,
const std::string& date,
const std::string& review_text);
void login(std::string username, std::string password);
void logout();
void addReview(int searchHitNum,
int rating,
const std::string& date,
const std::string& review_text);
void viewReview(int searchHitNum);
void rec();
std::vector<std::pair<std::string, double> > makeSuggestion(std::string currentUser);
void initializeSimilarityMatrix();
/**
* Deallocates memory
*/
void memDestroyer();
private:
//first stores set of users and products
std::set<User*> users;
std::set<Product*> products;
//a variable to store the current searchresult and the hit# along with
//the product that it corresponds to
std::map<int, Product*> searchResults;
//contains a map, with the key being the product name, and value
//being a pointer to the product
std::map<std::string, Product*> productNameDatabase;
//contains a map, with a keyword being the key and the value
//being a set of products that correspond to the item
std::map<std::string, std::set<Product*> > productKeywordDatabase;
//contains a map, with the key being a string representation of a
//username, while the value is a vector contain the items in the cart
std::map<std::string, std::vector<Product*> > usernameToCart;
//contains a map, with the key being a string representation of a
//username, with value being a user
std::map<std::string, User*> usernameToUser;
//checks if graphs adajecncy matrixes have been initialized
bool initialized;
//is the runnig index for what number to assign each user to
int index;
//maps the number to each user and vice versa
//for quick referencing in logn time
std::map<int, User*> indexToUser;
std::map<User*, int> userToIndex;
///each of these are same graph, just keeps track of differnt things
//this one is the number of same product reviewed
std::vector< std::vector<int> > numCorresRev;
//this one is the sum of all the similaries and differentsec
std::vector< std::vector<double> > totalRatingRev;
//this one keeps track of the averages
std::vector< std::vector<double> > avgRatingRev;
//current user
User* loggedIn;
std::set<Product*> getProducts(std::string term);
};
#endif //MYDATASTORE_H