xref: /aosp_15_r20/external/cronet/third_party/brotli/enc/compound_dictionary.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 /* Copyright 2017 Google Inc. All Rights Reserved.
2 
3    Distributed under MIT license.
4    See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6 
7 #ifndef BROTLI_ENC_PREPARED_DICTIONARY_H_
8 #define BROTLI_ENC_PREPARED_DICTIONARY_H_
9 
10 #include "../common/platform.h"
11 #include "../common/constants.h"
12 #include <brotli/shared_dictionary.h>
13 #include <brotli/types.h>
14 #include "memory.h"
15 
16 static const uint32_t kPreparedDictionaryMagic = 0xDEBCEDE0;
17 static const uint64_t kPreparedDictionaryHashMul64Long =
18     BROTLI_MAKE_UINT64_T(0x1FE35A7Bu, 0xD3579BD3u);
19 
20 typedef struct PreparedDictionary {
21   uint32_t magic;
22   uint32_t source_offset;
23   uint32_t source_size;
24   uint32_t hash_bits;
25   uint32_t bucket_bits;
26   uint32_t slot_bits;
27 
28   /* --- Dynamic size members --- */
29 
30   /* uint32_t slot_offsets[1 << slot_bits]; */
31   /* uint16_t heads[1 << bucket_bits]; */
32   /* uint32_t items[variable]; */
33 
34   /* uint8_t source[source_size] */
35 } PreparedDictionary;
36 
37 BROTLI_INTERNAL PreparedDictionary* CreatePreparedDictionary(MemoryManager* m,
38     const uint8_t* source, size_t source_size);
39 
40 BROTLI_INTERNAL void DestroyPreparedDictionary(MemoryManager* m,
41     PreparedDictionary* dictionary);
42 
43 typedef struct CompoundDictionary {
44   /* LZ77 prefix, compound dictionary */
45   size_t num_chunks;
46   size_t total_size;
47   /* Client instances. */
48   const PreparedDictionary* chunks[SHARED_BROTLI_MAX_COMPOUND_DICTS + 1];
49   const uint8_t* chunk_source[SHARED_BROTLI_MAX_COMPOUND_DICTS + 1];
50   size_t chunk_offsets[SHARED_BROTLI_MAX_COMPOUND_DICTS + 1];
51 
52   size_t num_prepared_instances_;
53   /* Owned instances. */
54   PreparedDictionary* prepared_instances_[SHARED_BROTLI_MAX_COMPOUND_DICTS + 1];
55 } CompoundDictionary;
56 
57 BROTLI_INTERNAL BROTLI_BOOL AttachPreparedDictionary(
58     CompoundDictionary* compound, const PreparedDictionary* dictionary);
59 
60 #endif /* BROTLI_ENC_PREPARED_DICTIONARY */
61