-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbigTest.cc
44 lines (40 loc) · 1.15 KB
/
bigTest.cc
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
#include "iptree.h"
#include <iostream>
#include <string>
#include <fstream>
#include "json/json.h"
using namespace std;
void buildTree(std::string file, iptree_node_t * root) {
std::string line;
std::ifstream test_data(file, std::ifstream::in);
while (test_data) {
std::getline(test_data, line);
Json::Value res;
Json::Reader reader;
bool parsingSuccessful = reader.parse(line, res);
if(!parsingSuccessful) {
return;
}
string *prefix = new string(res["bgp_prefix"].asString());
iptree_insert_str(root, prefix->c_str(),
const_cast<char*>(prefix->c_str()));
}
}
void testTree(std::string file, iptree_node_t * root) {
std::string line;
std::ifstream in_data(file, std::ifstream::in);
while (in_data) {
std::getline(in_data, line);
if(line.size() < 7) {
continue;
}
std::cout << iptree_lookup_best_str(root, line.c_str()) << endl;
}
}
int main() {
iptree_node_t * root = iptree_create();
buildTree("test_data.json", root);
testTree("in.txt", root);
iptree_destroy(root);
return 0;
}