-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump_ciff_lin.cpp
88 lines (74 loc) · 1.83 KB
/
dump_ciff_lin.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
DUMP_CIFF_LIN.CPP
-----------------
Copyright (c) 2019 Andrew Trotman
Released under the 2-clause BSD license (See:https://en.wikipedia.org/wiki/BSD_licenses)
*/
/*!
@file
@author Andrew Trotman
@copyright 2019 Andrew Trotman
@brief Read and dump an index in Jimmy Lin's Common Index File Format.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#else
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif
#include <iostream>
#include "ciff_lin.h"
/*
READ_ENTIRE_FILE()
------------------
*/
size_t read_entire_file(const std::string &filename, std::string &into)
{
FILE *fp;
struct stat details;
size_t file_length = 0;
if ((fp = fopen(filename.c_str(), "rb")) != nullptr)
{
if (fstat(fileno(fp), &details) == 0)
if ((file_length = details.st_size) != 0)
{
into.resize(file_length);
if (fread(&into[0], details.st_size, 1, fp) != 1)
into.resize(0);
}
fclose(fp);
}
return file_length;
}
/*
MAIN()
------
*/
int main(int argc, const char *argv[])
{
std::string file;
size_t file_size;
if (argc != 2)
exit(printf("Usage:%s <infile.pb>\n", argv[0]));
if ((file_size = read_entire_file(argv[1], file)) == 0)
exit(printf("Can't read file:%s\n", argv[1]));
JASS::ciff_lin source((uint8_t *)&file[0], file_size);
for (const auto &posting : source)
{
std::cout.write((char *)posting.term.start, posting.term.length);
std::cout << " " << posting.document_frequency << " " << posting.collection_frequency << ":";
uint64_t cumulative_total = 0;
for (const auto &pair : posting.postings)
{
cumulative_total += pair.docid;
std::cout << "<" << cumulative_total << "," << pair.term_frequency << ">";
}
std::cout << "\n";
}
if (source.status == JASS::ciff_lin::FAIL)
exit(printf("File is not in the correct format\n"));
return 0;
}