-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_from_dictionary.cpp
61 lines (43 loc) · 1.25 KB
/
load_from_dictionary.cpp
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
/*
load_and_search.cpp
By Stephen Holiday 2011
http://stephenholiday.com
(Exception, Distance Algorithm by Anders Sewerin Johansen)
The code is under the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0) license.
This is a utility for creating a BKTree from a text file and saving to disk.
The input files should have one entry per line.
./bkLoad [from] [to]
./bkLoad /usr/share/dict/words wordTree.dat
*/
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "BKTree.h"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
int main(int argc, char* argv[]) {
BKTree<std::string> tree=BKTree<std::string>();
std::ifstream words (argv[1]);
std::string str;
std::ofstream ofs(argv[2]);
if ( !words.is_open() ) {
// The file could not be opened
}
else {
while(std::getline(words, str))
{
tree.insert(str);
}
}
std::cout<<"Loaded "<<tree.size()<< " entries"<<std::endl;
{
boost::archive::text_oarchive oa(ofs);
oa<<tree;
}
return 0;
}