Blame


1 e2b5610c 2022-04-11 op /*
2 c00beb4f 2022-04-14 op * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
3 e2b5610c 2022-04-11 op *
4 e2b5610c 2022-04-11 op * Permission to use, copy, modify, and distribute this software for any
5 e2b5610c 2022-04-11 op * purpose with or without fee is hereby granted, provided that the above
6 e2b5610c 2022-04-11 op * copyright notice and this permission notice appear in all copies.
7 e2b5610c 2022-04-11 op *
8 e2b5610c 2022-04-11 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 e2b5610c 2022-04-11 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 e2b5610c 2022-04-11 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 e2b5610c 2022-04-11 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 e2b5610c 2022-04-11 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 e2b5610c 2022-04-11 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 e2b5610c 2022-04-11 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 e2b5610c 2022-04-11 op */
16 e2b5610c 2022-04-11 op
17 e2b5610c 2022-04-11 op #define DB_VERSION 0
18 e2b5610c 2022-04-11 op #define DB_WORDLEN 32
19 e2b5610c 2022-04-11 op
20 e2b5610c 2022-04-11 op struct db {
21 e2b5610c 2022-04-11 op uint8_t *m;
22 e2b5610c 2022-04-11 op off_t len;
23 e2b5610c 2022-04-11 op uint32_t version;
24 e2b5610c 2022-04-11 op uint32_t nwords;
25 e2b5610c 2022-04-11 op
26 e2b5610c 2022-04-11 op uint8_t *idx_start;
27 e2b5610c 2022-04-11 op uint8_t *idx_end;
28 e2b5610c 2022-04-11 op uint8_t *list_start;
29 e2b5610c 2022-04-11 op uint8_t *list_end;
30 e2b5610c 2022-04-11 op uint8_t *docs_start;
31 e2b5610c 2022-04-11 op uint8_t *docs_end;
32 e2b5610c 2022-04-11 op };
33 e2b5610c 2022-04-11 op
34 e2b5610c 2022-04-11 op struct db_stats {
35 e2b5610c 2022-04-11 op size_t nwords;
36 e2b5610c 2022-04-11 op size_t ndocs;
37 e2b5610c 2022-04-11 op const char *longest_word;
38 e2b5610c 2022-04-11 op const char *most_popular;
39 e2b5610c 2022-04-11 op size_t most_popular_ndocs;
40 e2b5610c 2022-04-11 op };
41 e2b5610c 2022-04-11 op
42 e2b5610c 2022-04-11 op struct db_entry {
43 e2b5610c 2022-04-11 op char *name;
44 e2b5610c 2022-04-11 op char *descr;
45 e2b5610c 2022-04-11 op };
46 e2b5610c 2022-04-11 op
47 e2b5610c 2022-04-11 op typedef int (*db_hit_cb)(struct db *, struct db_entry *, void *);
48 e2b5610c 2022-04-11 op
49 e2b5610c 2022-04-11 op struct dictionary;
50 e2b5610c 2022-04-11 op
51 e2b5610c 2022-04-11 op int db_create(FILE *, struct dictionary *, struct db_entry *, size_t);
52 e2b5610c 2022-04-11 op int db_open(struct db *, int);
53 e2b5610c 2022-04-11 op uint32_t *db_word_docs(struct db *, const char *, size_t *);
54 e2b5610c 2022-04-11 op int db_stats(struct db *, struct db_stats *);
55 e2b5610c 2022-04-11 op int db_listall(struct db *, db_hit_cb, void *);
56 e2b5610c 2022-04-11 op int db_doc_by_id(struct db *, int, struct db_entry *);
57 e2b5610c 2022-04-11 op void db_close(struct db *);