Change the magic number used to introduce a trie file, so that instead
[sgt/agedu] / index.h
CommitLineData
70322ae3 1/*
2 * index.h: Manage indexes for agedu.
3 */
4
5#include <sys/types.h>
6
7/*
8 * Given the size of an existing data file and the number of
522edd92 9 * entries required in the index, return the file size required to
10 * store the fixed initial fragment of the index before the
11 * indexbuild functions are invoked.
70322ae3 12 */
522edd92 13off_t index_initial_size(off_t currentsize, int nodecount);
70322ae3 14
15/*
16 * Build an index, given the address of a memory-mapped data file
17 * and the starting offset within it.
18 *
19 * trie_file structures passed to tf must of course be within the
20 * bounds of the memory-mapped file.
21 *
522edd92 22 * The "delta" parameter to indexbuild_new is filled in with the
23 * maximum size by which the index can ever grow in a single
24 * indexbuild_add call. This can be used, together with
25 * indexbuild_realsize, to detect when the index is about to get
26 * too big for its file and the file needs resizing.
27 *
28 * indexbuild_add adds a trie_file structure to the index.
29 * indexbuild_tag, called after that, causes the current state of
30 * the index to be preserved so that it can be queried later. It's
31 * idempotent, and will safely do nothing if called before
32 * indexbuild_add.
33 *
70322ae3 34 * indexbuild_realsize returns the total amount of data _actually_
522edd92 35 * written into the file, to allow it to be truncated afterwards,
36 * and to allow the caller of the indexbuild functions to know
37 * when the file is about to need to grow bigger during index
38 * building.
39 *
40 * indexbuild_rebase is used when the file has been
41 * re-memory-mapped at a different address (because it needs to
42 * grow).
70322ae3 43 */
44typedef struct indexbuild indexbuild;
522edd92 45indexbuild *indexbuild_new(void *t, off_t startoff, int nodecount,
46 size_t *delta);
70322ae3 47void indexbuild_add(indexbuild *ib, const struct trie_file *tf);
14601b5d 48void indexbuild_tag(indexbuild *ib);
522edd92 49void indexbuild_rebase(indexbuild *ib, void *t);
70322ae3 50off_t indexbuild_realsize(indexbuild *ib);
51void indexbuild_free(indexbuild *ib);
52
53/*
92d3b326 54 * Check to see if a name index has an index tree root available
55 * (i.e. represents a directory rather than a file).
56 */
57int index_has_root(const void *t, int n);
58
59/*
70322ae3 60 * Query an index to find the total size of records with name
61 * index strictly less than n, with atime less than at.
62 */
63unsigned long long index_query(const void *t, int n, unsigned long long at);
64
65/*
66 * Retrieve an order statistic from the index: given a fraction f,
67 * return an atime such that (at most) the requested fraction of
68 * the total data is older than it.
69 */
70unsigned long long index_order_stat(const void *t, double f);