-
Notifications
You must be signed in to change notification settings - Fork 0
/
cppWebSearch.h
76 lines (67 loc) · 1.68 KB
/
cppWebSearch.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
/* Project: cppWebSearch
* File: cppWebSearch.h
*
* Created by Rane Brown 4/19/2015
*
*/
#ifndef cppWebSearch_H
#define cppWebSearch_H
#include <iostream>
#include <queue>
#include <vector>
// helper struct to store the occurence of a word per website
struct TopURL {
int count;
std::string url;
};
// struct to store words and urls in hash table
struct WordStruct {
std::string word;
std::vector<TopURL*> wOccr;
bool hasValue;
WordStruct *next;
};
class HashTable {
public:
HashTable();
~HashTable();
void Insert(std::string in_word, std::string url);
void Find(std::string in_word);
void Print();
void Clear();
protected:
private:
int HashSum(std::string word);
WordStruct *baseArray;
int tableSize;
};
class WebSearch {
public:
WebSearch();
virtual ~WebSearch();
void EnqueueSite(std::string url);
void BuildQueue(std::string url, int depth);
void PrintHTML(std::string url);
bool IsUnique(std::string url); // checks if url is already in queue
void PrintURLs();
void StoreWords();
void PrintWords();
void FindWebsite(std::string word);
void ClearAll();
protected:
private:
std::queue<std::string> urlList; // queue to store list of urls up to specified depth
HashTable hTable; // hash table used to store all words from html code of each site
};
inline void DisplayMenu() {
using namespace std;
cout << "======Main Menu======" << endl;
cout << "1. Initialize cppWebSearch" << endl;
cout << "2. Search for a word" << endl;
cout << "3. Print HTML code" << endl;
cout << "4. Print saved URLs" << endl;
cout << "5. Clear saved data" << endl;
cout << "6. Print all saved words" << endl;
cout << "7. Quit" << endl;
}
#endif // cppWebSearch_H