dictionary.h 1.9 KB

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