2 e2b5610c 2022-04-11 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
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.
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.
17 e2b5610c 2022-04-11 op #define DB_VERSION 0
18 e2b5610c 2022-04-11 op #define DB_WORDLEN 32
23 e2b5610c 2022-04-11 op uint32_t version;
24 e2b5610c 2022-04-11 op uint32_t nwords;
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;
34 e2b5610c 2022-04-11 op struct db_stats {
35 e2b5610c 2022-04-11 op size_t nwords;
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;
42 e2b5610c 2022-04-11 op struct db_entry {
47 e2b5610c 2022-04-11 op typedef int (*db_hit_cb)(struct db *, struct db_entry *, void *);
49 e2b5610c 2022-04-11 op struct dictionary;
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 *);