compound_dictionary.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright 2017 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. #ifndef BROTLI_ENC_PREPARED_DICTIONARY_H_
  6. #define BROTLI_ENC_PREPARED_DICTIONARY_H_
  7. #include <brotli/shared_dictionary.h>
  8. #include <brotli/types.h>
  9. #include "../common/platform.h"
  10. #include "../common/constants.h"
  11. #include "memory.h"
  12. /* "Fat" prepared dictionary, could be cooked outside of C implementation,
  13. * e.g. on Java side. LZ77 data is copied inside PreparedDictionary struct. */
  14. static const uint32_t kPreparedDictionaryMagic = 0xDEBCEDE0;
  15. static const uint32_t kSharedDictionaryMagic = 0xDEBCEDE1;
  16. static const uint32_t kManagedDictionaryMagic = 0xDEBCEDE2;
  17. /* "Lean" prepared dictionary. LZ77 data is referenced. It is the responsibility
  18. * of caller of "prepare dictionary" to keep the LZ77 data while prepared
  19. * dictionary is in use. */
  20. static const uint32_t kLeanPreparedDictionaryMagic = 0xDEBCEDE3;
  21. static const uint64_t kPreparedDictionaryHashMul64Long =
  22. BROTLI_MAKE_UINT64_T(0x1FE35A7Bu, 0xD3579BD3u);
  23. typedef struct PreparedDictionary {
  24. uint32_t magic;
  25. uint32_t num_items;
  26. uint32_t source_size;
  27. uint32_t hash_bits;
  28. uint32_t bucket_bits;
  29. uint32_t slot_bits;
  30. /* --- Dynamic size members --- */
  31. /* uint32_t slot_offsets[1 << slot_bits]; */
  32. /* uint16_t heads[1 << bucket_bits]; */
  33. /* uint32_t items[variable]; */
  34. /* [maybe] uint8_t* source_ref, depending on magic. */
  35. /* [maybe] uint8_t source[source_size], depending on magic. */
  36. } PreparedDictionary;
  37. BROTLI_INTERNAL PreparedDictionary* CreatePreparedDictionary(MemoryManager* m,
  38. const uint8_t* source, size_t source_size);
  39. BROTLI_INTERNAL void DestroyPreparedDictionary(MemoryManager* m,
  40. PreparedDictionary* dictionary);
  41. typedef struct CompoundDictionary {
  42. /* LZ77 prefix, compound dictionary */
  43. size_t num_chunks;
  44. size_t total_size;
  45. /* Client instances. */
  46. const PreparedDictionary* chunks[SHARED_BROTLI_MAX_COMPOUND_DICTS + 1];
  47. const uint8_t* chunk_source[SHARED_BROTLI_MAX_COMPOUND_DICTS + 1];
  48. size_t chunk_offsets[SHARED_BROTLI_MAX_COMPOUND_DICTS + 1];
  49. size_t num_prepared_instances_;
  50. /* Owned instances. */
  51. PreparedDictionary* prepared_instances_[SHARED_BROTLI_MAX_COMPOUND_DICTS + 1];
  52. } CompoundDictionary;
  53. BROTLI_INTERNAL BROTLI_BOOL AttachPreparedDictionary(
  54. CompoundDictionary* compound, const PreparedDictionary* dictionary);
  55. #endif /* BROTLI_ENC_PREPARED_DICTIONARY */