-
Notifications
You must be signed in to change notification settings - Fork 1
/
posting_test.c
107 lines (91 loc) · 2.46 KB
/
posting_test.c
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* Copyright (c) 2008 Jeremy English <jhe@jeremyenglish.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* Created: 02-November-2008
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "posting.h"
#include "eprintf.h"
#include "fileutils.h"
int main(int argc, char **argv){
int i = 10;
Posting *list;
FILE *fp;
int of1, of2, of3;
setprogname(argv[0]);
fp = open_binary_file("posting.dat", FM_WRITE);
srand(time(NULL));
list = NULL;
while(i--){
int n = rand() % 100;
Posting *newp;
newp = emalloc(sizeof(*newp));
newp->data.frequency = rand() % 100;
newp->data.docid = i;
list = add_front(list,newp);
}
printf("Posting list 1\n");
print_posting_list(list);
of1 = ftell(fp);
write_posting_list(list, fp);
freeall(list);
list = NULL;
i = 20;
while(i--){
int n = rand() % 100;
Posting *newp;
newp = emalloc(sizeof(*newp));
newp->data.frequency = rand() % 100;
newp->data.docid = i;
list = add_front(list,newp);
}
printf("Posting list 2\n");
print_posting_list(list);
of2 = ftell(fp);
write_posting_list(list, fp);
freeall(list);
list = NULL;
i = 15;
while(i--){
int n = rand() % 100;
Posting *newp;
newp = emalloc(sizeof(*newp));
newp->data.frequency = rand() % 100;
newp->data.docid = i;
list = add_front(list,newp);
}
printf("Posting list 3\n");
print_posting_list(list);
of3 = ftell(fp);
write_posting_list(list,fp);
freeall(list);
list = NULL;
fclose(fp);
/* Reading postings from file */
printf("Reading postings from postings.dat\n");
fp = open_binary_file("posting.dat", FM_READ);
list = get_posting_list(fp,20,of2);
printf("Posting List 2\n");
print_posting_list(list);
freeall(list);
list = get_posting_list(fp,15,of3);
printf("Posting List 3\n");
print_posting_list(list);
freeall(list);
list = get_posting_list(fp,10,of1);
printf("Posting List 1\n");
print_posting_list(list);
freeall(list);
return 0;
}