-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserDatabase.h
More file actions
82 lines (72 loc) · 2.35 KB
/
UserDatabase.h
File metadata and controls
82 lines (72 loc) · 2.35 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
#ifndef USER_DATABASE_H
#define USER_DATABASE_H
#include "Utility.h"
#include "Exceptions.h"
#include "UserNode.h"
class UserDatabase {
private:
// DO NOT CHANGE
vector<UserNode*> _userTable;
size_t _size;
double _load_factor;
UserNode* _dummy;
// ADD YOUR HELPER FUCTIONS HERE
public:
// DO NOT CHANGE
inline void printDatabase() const {
size_t max_length = 0U;
for (size_t i = 0; i < capacity(); i++) {
if (_userTable[i] == NULL)
max_length = std::max(max_length, size_t(4U));
else if (_userTable[i] == _dummy)
max_length = std::max(max_length, size_t(5U));
else
max_length = std::max(max_length, _userTable[i]->username.size());
}
cout << string(max_length + 2U, '_') << endl;
for (size_t i = 0; i < capacity(); i++) {
if (_userTable[i] == NULL)
cout << "|" << printStyle(string("NULL"), max_length) << "|" << endl;
else if (_userTable[i] == _dummy)
cout << "|" << printStyle(string("DUMMY"), max_length) << "|" << endl;
else
cout << "|" << printStyle(_userTable[i]->username, max_length) << "|" << endl;
}
cout << string(max_length + 2U, '_') << endl;
}
inline void printUserList(bool withCount = false) const {
vector<string> uList = getUserList();
for (size_t i = 0; i < uList.size(); i++) {
cout << uList[i];
if (withCount) {
cout << "\t" << userFollowerCount(uList[i]) << "\t" << userFollowsCount(uList[i]);
}
cout << endl;
}
}
// IMPLEMENT THESE
UserDatabase();
UserDatabase(size_t s, double load);
~UserDatabase();
size_t size() const;
size_t capacity() const;
bool isEmpty() const;
void addUser(string username);
void removeUser(string username);
UserNode* getUser(string username) const;
void resize(size_t size);
void follow(string username1, string username2);
void unfollow(string username1, string username2);
bool userExists(string username) const;
bool userFollows(string username1, string username2) const;
size_t userFollowerCount(string username) const;
size_t userFollowsCount(string username) const;
vector<string> getUserList() const;
void printAdjacencyMatrix() const;
int BFS(string username1, string username2, bool printPath = true);
int DFS(string username1, string username2, bool printPath = true);
double averageBFS();
double averageDFS();
vector<string> getSharedNeighbourhood(string username1, string username2, size_t k);
};
#endif // !USER_DATABASE_H