]> git.sesse.net Git - plocate/blob - db.h
Correct the man page.
[plocate] / db.h
1 #ifndef DB_H
2 #define DB_H 1
3
4 #include <stdint.h>
5
6 struct Header {
7         char magic[8];  // "\0plocate";
8         uint32_t version;  // 1.
9         uint32_t hashtable_size;
10         uint32_t extra_ht_slots;
11         uint32_t num_docids;
12         uint64_t hash_table_offset_bytes;
13         uint64_t filename_index_offset_bytes;
14
15         // Version 1 and up only.
16         uint32_t max_version;  // Nominally 1 or 2, but can be increased if more features are added in a backward-compatible way.
17         uint32_t zstd_dictionary_length_bytes;
18         uint64_t zstd_dictionary_offset_bytes;
19
20         // Only if max_version >= 2, and only relevant for updatedb.
21         uint64_t directory_data_length_bytes;
22         uint64_t directory_data_offset_bytes;
23         uint64_t next_zstd_dictionary_length_bytes;
24         uint64_t next_zstd_dictionary_offset_bytes;
25         uint64_t conf_block_length_bytes;
26         uint64_t conf_block_offset_bytes;
27
28         // Only if max_version >= 2.
29         bool check_visibility;
30 };
31
32 struct Trigram {
33         uint32_t trgm;
34         uint32_t num_docids;
35         uint64_t offset;
36
37         bool operator==(const Trigram &other) const
38         {
39                 return trgm == other.trgm;
40         }
41         bool operator<(const Trigram &other) const
42         {
43                 return trgm < other.trgm;
44         }
45 };
46
47 inline uint32_t hash_trigram(uint32_t trgm, uint32_t ht_size)
48 {
49         // CRC-like computation.
50         uint32_t crc = trgm;
51         for (int i = 0; i < 32; i++) {
52                 bool bit = crc & 0x80000000;
53                 crc <<= 1;
54                 if (bit) {
55                         crc ^= 0x1edc6f41;
56                 }
57         }
58         return crc % ht_size;
59 }
60
61 #endif  // !defined(DB_H)