-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss-index.h
49 lines (42 loc) · 1.58 KB
/
rss-index.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
/**
* File: rss-index.h
* -----------------
* Exports an RSSIndex type, which is a data structure that maps
* words to vectors of document/frequency pairs (where the document frequency
* pairs are represented as pair<Article, int>s).
*/
#pragma once
#include <map>
#include <vector>
#include "article.h"
class RSSIndex {
public:
/**
* Zero-argument constructor, constructs an empty index.
*/
RSSIndex() {}
/**
* Notes that each of the words in the supplied vector appears within the
* specified article. The add operation is not thread-safe, so care must be taken
* to externally lock the RSSIndex down if two racing threads might try to
* add to the RSSIndex at the same time.
*/
void add(const Article& article, const std::vector<std::string>& words);
void remove(const Article& article, const std::vector<std::string>& words);
/**
* Returns a reference to the list of documents associated with the specified
* word. The list is a vector of URL/frequency pairs, sorted by frequency from
* high to low (and alphabetically for those with the same frequence counts.)
*/
std::vector<std::pair<Article, int> > getMatchingArticles(const std::string& word) const;
private:
std::map<std::string, std::map<Article, int> > index;
/**
* RSSIndex instances can theoretically store a huge amount of data, so we
* elect to delete the compiler-supplied implementations of the copy constructor
* and operator= so that clients are forced to pass instances around by reference
* or by address.
*/
RSSIndex(const RSSIndex& other) = delete;
void operator=(const RSSIndex& rhs) = delete;
};