xref: /aosp_15_r20/external/brotli/c/common/dictionary.h (revision f4ee7fba7774faf2a30f13154332c0a06550dbc4)
1*f4ee7fbaSAndroid Build Coastguard Worker /* Copyright 2013 Google Inc. All Rights Reserved.
2*f4ee7fbaSAndroid Build Coastguard Worker 
3*f4ee7fbaSAndroid Build Coastguard Worker    Distributed under MIT license.
4*f4ee7fbaSAndroid Build Coastguard Worker    See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5*f4ee7fbaSAndroid Build Coastguard Worker */
6*f4ee7fbaSAndroid Build Coastguard Worker 
7*f4ee7fbaSAndroid Build Coastguard Worker /* Collection of static dictionary words. */
8*f4ee7fbaSAndroid Build Coastguard Worker 
9*f4ee7fbaSAndroid Build Coastguard Worker #ifndef BROTLI_COMMON_DICTIONARY_H_
10*f4ee7fbaSAndroid Build Coastguard Worker #define BROTLI_COMMON_DICTIONARY_H_
11*f4ee7fbaSAndroid Build Coastguard Worker 
12*f4ee7fbaSAndroid Build Coastguard Worker #include <brotli/port.h>
13*f4ee7fbaSAndroid Build Coastguard Worker #include <brotli/types.h>
14*f4ee7fbaSAndroid Build Coastguard Worker 
15*f4ee7fbaSAndroid Build Coastguard Worker #if defined(__cplusplus) || defined(c_plusplus)
16*f4ee7fbaSAndroid Build Coastguard Worker extern "C" {
17*f4ee7fbaSAndroid Build Coastguard Worker #endif
18*f4ee7fbaSAndroid Build Coastguard Worker 
19*f4ee7fbaSAndroid Build Coastguard Worker typedef struct BrotliDictionary {
20*f4ee7fbaSAndroid Build Coastguard Worker   /**
21*f4ee7fbaSAndroid Build Coastguard Worker    * Number of bits to encode index of dictionary word in a bucket.
22*f4ee7fbaSAndroid Build Coastguard Worker    *
23*f4ee7fbaSAndroid Build Coastguard Worker    * Specification: Appendix A. Static Dictionary Data
24*f4ee7fbaSAndroid Build Coastguard Worker    *
25*f4ee7fbaSAndroid Build Coastguard Worker    * Words in a dictionary are bucketed by length.
26*f4ee7fbaSAndroid Build Coastguard Worker    * @c 0 means that there are no words of a given length.
27*f4ee7fbaSAndroid Build Coastguard Worker    * Dictionary consists of words with length of [4..24] bytes.
28*f4ee7fbaSAndroid Build Coastguard Worker    * Values at [0..3] and [25..31] indices should not be addressed.
29*f4ee7fbaSAndroid Build Coastguard Worker    */
30*f4ee7fbaSAndroid Build Coastguard Worker   uint8_t size_bits_by_length[32];
31*f4ee7fbaSAndroid Build Coastguard Worker 
32*f4ee7fbaSAndroid Build Coastguard Worker   /* assert(offset[i + 1] == offset[i] + (bits[i] ? (i << bits[i]) : 0)) */
33*f4ee7fbaSAndroid Build Coastguard Worker   uint32_t offsets_by_length[32];
34*f4ee7fbaSAndroid Build Coastguard Worker 
35*f4ee7fbaSAndroid Build Coastguard Worker   /* assert(data_size == offsets_by_length[31]) */
36*f4ee7fbaSAndroid Build Coastguard Worker   size_t data_size;
37*f4ee7fbaSAndroid Build Coastguard Worker 
38*f4ee7fbaSAndroid Build Coastguard Worker   /* Data array is not bound, and should obey to size_bits_by_length values.
39*f4ee7fbaSAndroid Build Coastguard Worker      Specified size matches default (RFC 7932) dictionary. Its size is
40*f4ee7fbaSAndroid Build Coastguard Worker      defined by data_size */
41*f4ee7fbaSAndroid Build Coastguard Worker   const uint8_t* data;
42*f4ee7fbaSAndroid Build Coastguard Worker } BrotliDictionary;
43*f4ee7fbaSAndroid Build Coastguard Worker 
44*f4ee7fbaSAndroid Build Coastguard Worker BROTLI_COMMON_API const BrotliDictionary* BrotliGetDictionary(void);
45*f4ee7fbaSAndroid Build Coastguard Worker 
46*f4ee7fbaSAndroid Build Coastguard Worker /**
47*f4ee7fbaSAndroid Build Coastguard Worker  * Sets dictionary data.
48*f4ee7fbaSAndroid Build Coastguard Worker  *
49*f4ee7fbaSAndroid Build Coastguard Worker  * When dictionary data is already set / present, this method is no-op.
50*f4ee7fbaSAndroid Build Coastguard Worker  *
51*f4ee7fbaSAndroid Build Coastguard Worker  * Dictionary data MUST be provided before BrotliGetDictionary is invoked.
52*f4ee7fbaSAndroid Build Coastguard Worker  * This method is used ONLY in multi-client environment (e.g. C + Java),
53*f4ee7fbaSAndroid Build Coastguard Worker  * to reduce storage by sharing single dictionary between implementations.
54*f4ee7fbaSAndroid Build Coastguard Worker  */
55*f4ee7fbaSAndroid Build Coastguard Worker BROTLI_COMMON_API void BrotliSetDictionaryData(const uint8_t* data);
56*f4ee7fbaSAndroid Build Coastguard Worker 
57*f4ee7fbaSAndroid Build Coastguard Worker #define BROTLI_MIN_DICTIONARY_WORD_LENGTH 4
58*f4ee7fbaSAndroid Build Coastguard Worker #define BROTLI_MAX_DICTIONARY_WORD_LENGTH 24
59*f4ee7fbaSAndroid Build Coastguard Worker 
60*f4ee7fbaSAndroid Build Coastguard Worker #if defined(__cplusplus) || defined(c_plusplus)
61*f4ee7fbaSAndroid Build Coastguard Worker }  /* extern "C" */
62*f4ee7fbaSAndroid Build Coastguard Worker #endif
63*f4ee7fbaSAndroid Build Coastguard Worker 
64*f4ee7fbaSAndroid Build Coastguard Worker #endif  /* BROTLI_COMMON_DICTIONARY_H_ */
65