-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordIndex.h
More file actions
51 lines (44 loc) · 1.15 KB
/
WordIndex.h
File metadata and controls
51 lines (44 loc) · 1.15 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
#ifndef WORDINDEX_H
#define WORDINDEX_H
#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
class WordIndex
{
struct word
{
std::string name;
int count;
word(const std::string &n, int c)
: name(n), count(c)
{
}
};
typedef boost::multi_index_container<
word,
boost::multi_index::indexed_by<
boost::multi_index::hashed_unique<
boost::multi_index::member<
word, std::string, &word::name
>
>,
boost::multi_index::ordered_non_unique<
// ordered_unique would be cleaner but had unexpected results
boost::multi_index::member<
word, int, &word::count
>,
std::greater<int>
>
>
> word_multi;
private:
word_multi words;
typedef word_multi::nth_index<0>::type word_find_by_name;
void incr_count (word &w);
public:
void insert_word(const std::string & word_str);
void get_top_words(int topN);
};
#endif