forked from wmorgan/whistlepig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.h
62 lines (45 loc) · 1.86 KB
/
entry.h
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
#ifndef WP_ENTRY_H_
#define WP_ENTRY_H_
// whistlepig entry
// (c) 2011 William Morgan. See COPYING for license terms.
//
// an entry is a document before being added to the index. it's nothig more
// than a map of (field,term) pairs to a (sorted) list of positions. you can
// use this to incrementally build up a document in memory before adding it to
// the index.
#include "defaults.h"
#include "error.h"
#include "segment.h"
#include "khash.h"
#include "rarray.h"
typedef struct fielded_term {
char* field;
char* term;
} fielded_term;
khint_t fielded_term_hash(fielded_term ft);
khint_t fielded_term_equals(fielded_term a, fielded_term b);
RARRAY_DECLARE(pos_t);
KHASH_INIT(entries, fielded_term, RARRAY(pos_t), 1, fielded_term_hash, fielded_term_equals);
typedef struct wp_entry {
khash_t(entries)* entries;
pos_t next_offset;
} wp_entry;
struct wp_segment;
// API methods
// public: make a new entry
wp_entry* wp_entry_new();
// public: return the number of tokens occurrences in the entry
uint32_t wp_entry_size(wp_entry* entry);
// public: add an individual token
wp_error* wp_entry_add_token(wp_entry* entry, const char* field, const char* term) RAISES_ERROR;
// public: add a string, which will be tokenized at spaces only
wp_error* wp_entry_add_string(wp_entry* entry, const char* field, const char* string) RAISES_ERROR;
// public: add a file, which will be tokenized at spaces only
wp_error* wp_entry_add_file(wp_entry* entry, const char* field, FILE* f) RAISES_ERROR;
// public: free an entry.
wp_error* wp_entry_free(wp_entry* entry) RAISES_ERROR;
// private: write to a segment
wp_error* wp_entry_write_to_segment(wp_entry* entry, struct wp_segment* seg, docid_t doc_id) RAISES_ERROR;
// private: calculate the size needed for a postings region
wp_error* wp_entry_sizeof_postings_region(wp_entry* entry, struct wp_segment* seg, uint32_t* size) RAISES_ERROR;
#endif