11cb0ef41Sopenharmony_ci/* Copyright 2013 Google Inc. All Rights Reserved.
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci   Distributed under MIT license.
41cb0ef41Sopenharmony_ci   See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
51cb0ef41Sopenharmony_ci*/
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci/* Collection of static dictionary words. */
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#ifndef BROTLI_COMMON_DICTIONARY_H_
101cb0ef41Sopenharmony_ci#define BROTLI_COMMON_DICTIONARY_H_
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci#include <brotli/port.h>
131cb0ef41Sopenharmony_ci#include <brotli/types.h>
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci#if defined(__cplusplus) || defined(c_plusplus)
161cb0ef41Sopenharmony_ciextern "C" {
171cb0ef41Sopenharmony_ci#endif
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_citypedef struct BrotliDictionary {
201cb0ef41Sopenharmony_ci  /**
211cb0ef41Sopenharmony_ci   * Number of bits to encode index of dictionary word in a bucket.
221cb0ef41Sopenharmony_ci   *
231cb0ef41Sopenharmony_ci   * Specification: Appendix A. Static Dictionary Data
241cb0ef41Sopenharmony_ci   *
251cb0ef41Sopenharmony_ci   * Words in a dictionary are bucketed by length.
261cb0ef41Sopenharmony_ci   * @c 0 means that there are no words of a given length.
271cb0ef41Sopenharmony_ci   * Dictionary consists of words with length of [4..24] bytes.
281cb0ef41Sopenharmony_ci   * Values at [0..3] and [25..31] indices should not be addressed.
291cb0ef41Sopenharmony_ci   */
301cb0ef41Sopenharmony_ci  uint8_t size_bits_by_length[32];
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  /* assert(offset[i + 1] == offset[i] + (bits[i] ? (i << bits[i]) : 0)) */
331cb0ef41Sopenharmony_ci  uint32_t offsets_by_length[32];
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  /* assert(data_size == offsets_by_length[31]) */
361cb0ef41Sopenharmony_ci  size_t data_size;
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  /* Data array is not bound, and should obey to size_bits_by_length values.
391cb0ef41Sopenharmony_ci     Specified size matches default (RFC 7932) dictionary. Its size is
401cb0ef41Sopenharmony_ci     defined by data_size */
411cb0ef41Sopenharmony_ci  const uint8_t* data;
421cb0ef41Sopenharmony_ci} BrotliDictionary;
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ciBROTLI_COMMON_API const BrotliDictionary* BrotliGetDictionary(void);
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci/**
471cb0ef41Sopenharmony_ci * Sets dictionary data.
481cb0ef41Sopenharmony_ci *
491cb0ef41Sopenharmony_ci * When dictionary data is already set / present, this method is no-op.
501cb0ef41Sopenharmony_ci *
511cb0ef41Sopenharmony_ci * Dictionary data MUST be provided before BrotliGetDictionary is invoked.
521cb0ef41Sopenharmony_ci * This method is used ONLY in multi-client environment (e.g. C + Java),
531cb0ef41Sopenharmony_ci * to reduce storage by sharing single dictionary between implementations.
541cb0ef41Sopenharmony_ci */
551cb0ef41Sopenharmony_ciBROTLI_COMMON_API void BrotliSetDictionaryData(const uint8_t* data);
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci#define BROTLI_MIN_DICTIONARY_WORD_LENGTH 4
581cb0ef41Sopenharmony_ci#define BROTLI_MAX_DICTIONARY_WORD_LENGTH 24
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci#if defined(__cplusplus) || defined(c_plusplus)
611cb0ef41Sopenharmony_ci}  /* extern "C" */
621cb0ef41Sopenharmony_ci#endif
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci#endif  /* BROTLI_COMMON_DICTIONARY_H_ */
65