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