-
Notifications
You must be signed in to change notification settings - Fork 13
/
dump.c
114 lines (89 loc) · 3.07 KB
/
dump.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
108
109
110
111
112
113
#include <stdio.h>
#include "whistlepig.h"
#define isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2)
#define isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1)
#define KEY(h, i) &(h->pool[h->keys[i]])
RAISING_STATIC(dump_posting_list(wp_segment* s, posting_list_header* plh)) {
posting po;
docid_t last_doc_id = 0;
int started = 0;
uint32_t offset = plh->next_offset;
printf("[%u entries]\n", plh->count);
while(offset != OFFSET_NONE) {
RELAY_ERROR(wp_segment_read_posting(s, offset, &po, 1));
printf(" @%u doc %u:", offset, po.doc_id);
for(uint32_t i = 0; i < po.num_positions; i++) printf(" %d", po.positions[i]);
if((po.doc_id == 0) || (started && (po.doc_id >= last_doc_id))) printf(" <-- BROKEN");
started = 1;
last_doc_id = po.doc_id;
printf("\n");
offset = po.next_offset;
free(po.positions);
}
return NO_ERROR;
}
RAISING_STATIC(dump_label_posting_list(wp_segment* s, posting_list_header* plh)) {
posting po;
docid_t last_doc_id = 0;
int started = 0;
uint32_t offset = plh->next_offset;
printf("[%u entries]\n", plh->count);
while(offset != OFFSET_NONE) {
RELAY_ERROR(wp_segment_read_label(s, offset, &po));
printf(" @%u doc %u", offset, po.doc_id);
if((po.doc_id == 0) || (started && (po.doc_id >= last_doc_id))) printf(" <-- BROKEN");
started = 1;
last_doc_id = po.doc_id;
printf("\n");
offset = po.next_offset;
free(po.positions);
}
return NO_ERROR;
}
RAISING_STATIC(dump(wp_segment* segment)) {
termhash* th = MMAP_OBJ(segment->termhash, termhash);
stringmap* sh = MMAP_OBJ(segment->stringmap, stringmap);
stringpool* sp = MMAP_OBJ(segment->stringpool, stringpool);
uint32_t* thflags = TERMHASH_FLAGS(th);
term* thkeys = TERMHASH_KEYS(th);
posting_list_header* thvals = TERMHASH_VALS(th);
for(uint32_t i = 0; i < th->n_buckets; i++) {
if(isempty(thflags, i)); // do nothing
else if(isdel(thflags, i)) printf("%u: [deleted]", i);
else {
term t = thkeys[i];
if(t.field_s == 0) { // sentinel label value
if(t.word_s == 0) { // sentinel dead list value
printf("%u: (dead list)\n", i);
}
else {
const char* label = stringmap_int_to_string(sh, sp, t.word_s);
printf("%u: ~%s\n", i, label);
}
RELAY_ERROR(dump_label_posting_list(segment, &thvals[i]));
}
else {
const char* field = stringmap_int_to_string(sh, sp, t.field_s);
const char* word = stringmap_int_to_string(sh, sp, t.word_s);
printf("%u: %s:'%s'\n", i, field, word);
RELAY_ERROR(dump_posting_list(segment, &thvals[i]));
}
}
}
return NO_ERROR;
}
int main(int argc, char* argv[]) {
if(argc != 2) {
fprintf(stderr, "Usage: %s <segment filename>\n", argv[0]);
return -1;
}
wp_index* index;
DIE_IF_ERROR(wp_index_load(&index, argv[1]));
DIE_IF_ERROR(wp_index_dumpinfo(index, stdout));
for(int i = 0; i < index->num_segments; i++) {
printf("\nsegment %d details:\n", i);
DIE_IF_ERROR(dump(&index->segments[i]));
}
DIE_IF_ERROR(wp_index_unload(index));
return 0;
}