isomorfeus-ferret 0.12.4 → 0.12.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +612 -612
  3. data/README.md +77 -48
  4. data/ext/isomorfeus_ferret_ext/bm_hash.c +9 -6
  5. data/ext/isomorfeus_ferret_ext/bm_micro_string.c +4 -2
  6. data/ext/isomorfeus_ferret_ext/brotli_common_constants.c +15 -0
  7. data/ext/isomorfeus_ferret_ext/brotli_common_constants.h +200 -0
  8. data/ext/isomorfeus_ferret_ext/brotli_common_context.c +156 -0
  9. data/ext/isomorfeus_ferret_ext/brotli_common_context.h +113 -0
  10. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.c +5914 -0
  11. data/ext/isomorfeus_ferret_ext/brotli_common_dictionary.h +64 -0
  12. data/ext/isomorfeus_ferret_ext/brotli_common_platform.c +22 -0
  13. data/ext/isomorfeus_ferret_ext/brotli_common_platform.h +594 -0
  14. data/ext/isomorfeus_ferret_ext/brotli_common_transform.c +291 -0
  15. data/ext/isomorfeus_ferret_ext/brotli_common_transform.h +85 -0
  16. data/ext/isomorfeus_ferret_ext/brotli_common_version.h +26 -0
  17. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.c +76 -0
  18. data/ext/isomorfeus_ferret_ext/brotli_dec_bit_reader.h +351 -0
  19. data/ext/isomorfeus_ferret_ext/brotli_dec_decode.c +2608 -0
  20. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.c +339 -0
  21. data/ext/isomorfeus_ferret_ext/brotli_dec_huffman.h +121 -0
  22. data/ext/isomorfeus_ferret_ext/brotli_dec_prefix.h +732 -0
  23. data/ext/isomorfeus_ferret_ext/brotli_dec_state.c +159 -0
  24. data/ext/isomorfeus_ferret_ext/brotli_dec_state.h +365 -0
  25. data/ext/isomorfeus_ferret_ext/brotli_decode.h +344 -0
  26. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.c +145 -0
  27. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references.h +39 -0
  28. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.c +843 -0
  29. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_hq.h +95 -0
  30. data/ext/isomorfeus_ferret_ext/brotli_enc_backward_references_inc.h +163 -0
  31. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.c +35 -0
  32. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost.h +63 -0
  33. data/ext/isomorfeus_ferret_ext/brotli_enc_bit_cost_inc.h +127 -0
  34. data/ext/isomorfeus_ferret_ext/brotli_enc_block_encoder_inc.h +34 -0
  35. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.c +194 -0
  36. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter.h +51 -0
  37. data/ext/isomorfeus_ferret_ext/brotli_enc_block_splitter_inc.h +440 -0
  38. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.c +1314 -0
  39. data/ext/isomorfeus_ferret_ext/brotli_enc_brotli_bit_stream.h +84 -0
  40. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.c +56 -0
  41. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster.h +48 -0
  42. data/ext/isomorfeus_ferret_ext/brotli_enc_cluster_inc.h +320 -0
  43. data/ext/isomorfeus_ferret_ext/brotli_enc_command.c +28 -0
  44. data/ext/isomorfeus_ferret_ext/brotli_enc_command.h +190 -0
  45. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.c +790 -0
  46. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment.h +61 -0
  47. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.c +645 -0
  48. data/ext/isomorfeus_ferret_ext/brotli_enc_compress_fragment_two_pass.h +54 -0
  49. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.c +1846 -0
  50. data/ext/isomorfeus_ferret_ext/brotli_enc_dictionary_hash.h +25 -0
  51. data/ext/isomorfeus_ferret_ext/brotli_enc_encode.c +1927 -0
  52. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.c +33 -0
  53. data/ext/isomorfeus_ferret_ext/brotli_enc_encoder_dict.h +43 -0
  54. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.c +503 -0
  55. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode.h +122 -0
  56. data/ext/isomorfeus_ferret_ext/brotli_enc_entropy_encode_static.h +539 -0
  57. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.c +105 -0
  58. data/ext/isomorfeus_ferret_ext/brotli_enc_fast_log.h +66 -0
  59. data/ext/isomorfeus_ferret_ext/brotli_enc_find_match_length.h +79 -0
  60. data/ext/isomorfeus_ferret_ext/brotli_enc_hash.h +488 -0
  61. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_composite_inc.h +125 -0
  62. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_forgetful_chain_inc.h +293 -0
  63. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match64_inc.h +267 -0
  64. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_inc.h +262 -0
  65. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_longest_match_quickly_inc.h +266 -0
  66. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_rolling_inc.h +212 -0
  67. data/ext/isomorfeus_ferret_ext/brotli_enc_hash_to_binary_tree_inc.h +329 -0
  68. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.c +100 -0
  69. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram.h +63 -0
  70. data/ext/isomorfeus_ferret_ext/brotli_enc_histogram_inc.h +51 -0
  71. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.c +175 -0
  72. data/ext/isomorfeus_ferret_ext/brotli_enc_literal_cost.h +30 -0
  73. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.c +170 -0
  74. data/ext/isomorfeus_ferret_ext/brotli_enc_memory.h +114 -0
  75. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.c +663 -0
  76. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock.h +105 -0
  77. data/ext/isomorfeus_ferret_ext/brotli_enc_metablock_inc.h +183 -0
  78. data/ext/isomorfeus_ferret_ext/brotli_enc_params.h +46 -0
  79. data/ext/isomorfeus_ferret_ext/brotli_enc_prefix.h +53 -0
  80. data/ext/isomorfeus_ferret_ext/brotli_enc_quality.h +165 -0
  81. data/ext/isomorfeus_ferret_ext/brotli_enc_ringbuffer.h +167 -0
  82. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.c +486 -0
  83. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict.h +40 -0
  84. data/ext/isomorfeus_ferret_ext/brotli_enc_static_dict_lut.h +5864 -0
  85. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.c +85 -0
  86. data/ext/isomorfeus_ferret_ext/brotli_enc_utf8_util.h +32 -0
  87. data/ext/isomorfeus_ferret_ext/brotli_enc_write_bits.h +87 -0
  88. data/ext/isomorfeus_ferret_ext/brotli_encode.h +448 -0
  89. data/ext/isomorfeus_ferret_ext/brotli_port.h +288 -0
  90. data/ext/isomorfeus_ferret_ext/brotli_types.h +83 -0
  91. data/ext/isomorfeus_ferret_ext/frb_index.c +35 -4
  92. data/ext/isomorfeus_ferret_ext/frb_store.c +34 -5
  93. data/ext/isomorfeus_ferret_ext/frt_document.h +1 -0
  94. data/ext/isomorfeus_ferret_ext/frt_fs_store.c +1 -0
  95. data/ext/isomorfeus_ferret_ext/frt_index.c +174 -25
  96. data/ext/isomorfeus_ferret_ext/frt_index.h +6 -3
  97. data/ext/isomorfeus_ferret_ext/frt_posh.h +11 -19
  98. data/ext/isomorfeus_ferret_ext/frt_q_parser.c +1844 -1911
  99. data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +12 -15
  100. data/ext/isomorfeus_ferret_ext/frt_ram_store.c +1 -0
  101. data/ext/isomorfeus_ferret_ext/frt_scanner.c +1 -0
  102. data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +1 -0
  103. data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +1 -0
  104. data/ext/isomorfeus_ferret_ext/frt_search.h +1 -1
  105. data/ext/isomorfeus_ferret_ext/libstemmer.c +14 -11
  106. data/ext/isomorfeus_ferret_ext/libstemmer.h +4 -9
  107. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.c +1167 -0
  108. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_basque.h +6 -0
  109. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.c +1433 -0
  110. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_catalan.h +6 -0
  111. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +120 -143
  112. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +1 -2
  113. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +217 -237
  114. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +1 -1
  115. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +377 -432
  116. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +1 -1
  117. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +298 -342
  118. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +1 -2
  119. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +530 -524
  120. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +1 -1
  121. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +201 -214
  122. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +1 -1
  123. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1 -1
  124. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.c +394 -0
  125. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_indonesian.h +6 -0
  126. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.c +457 -0
  127. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_irish.h +6 -0
  128. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +396 -439
  129. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +1 -1
  130. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +104 -128
  131. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +1 -1
  132. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +242 -273
  133. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +1 -1
  134. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +406 -461
  135. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +1 -2
  136. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +405 -456
  137. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +1 -1
  138. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +108 -126
  139. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +1 -1
  140. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.c +849 -0
  141. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_hungarian.h +6 -0
  142. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +373 -405
  143. data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +1 -1
  144. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +288 -305
  145. data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +1 -1
  146. data/ext/isomorfeus_ferret_ext/stem_UTF_8_arabic.c +1651 -0
  147. data/ext/isomorfeus_ferret_ext/stem_UTF_8_arabic.h +6 -0
  148. data/ext/isomorfeus_ferret_ext/stem_UTF_8_armenian.c +546 -0
  149. data/ext/isomorfeus_ferret_ext/stem_UTF_8_armenian.h +6 -0
  150. data/ext/isomorfeus_ferret_ext/stem_UTF_8_basque.c +1171 -0
  151. data/ext/isomorfeus_ferret_ext/stem_UTF_8_basque.h +6 -0
  152. data/ext/isomorfeus_ferret_ext/stem_UTF_8_catalan.c +1436 -0
  153. data/ext/isomorfeus_ferret_ext/stem_UTF_8_catalan.h +6 -0
  154. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +121 -141
  155. data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +1 -1
  156. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +221 -241
  157. data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +1 -1
  158. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +381 -431
  159. data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +1 -1
  160. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +300 -345
  161. data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +1 -1
  162. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +518 -511
  163. data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +1 -1
  164. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +201 -209
  165. data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +1 -1
  166. data/ext/isomorfeus_ferret_ext/stem_UTF_8_greek.c +3660 -0
  167. data/ext/isomorfeus_ferret_ext/stem_UTF_8_greek.h +6 -0
  168. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hindi.c +309 -0
  169. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hindi.h +6 -0
  170. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +306 -671
  171. data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +1 -1
  172. data/ext/isomorfeus_ferret_ext/stem_UTF_8_indonesian.c +394 -0
  173. data/ext/isomorfeus_ferret_ext/stem_UTF_8_indonesian.h +6 -0
  174. data/ext/isomorfeus_ferret_ext/stem_UTF_8_irish.c +457 -0
  175. data/ext/isomorfeus_ferret_ext/stem_UTF_8_irish.h +6 -0
  176. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +400 -442
  177. data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +1 -1
  178. data/ext/isomorfeus_ferret_ext/stem_UTF_8_lithuanian.c +824 -0
  179. data/ext/isomorfeus_ferret_ext/stem_UTF_8_lithuanian.h +6 -0
  180. data/ext/isomorfeus_ferret_ext/stem_UTF_8_nepali.c +408 -0
  181. data/ext/isomorfeus_ferret_ext/stem_UTF_8_nepali.h +6 -0
  182. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +105 -127
  183. data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +1 -1
  184. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +245 -276
  185. data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +1 -1
  186. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +409 -464
  187. data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +1 -1
  188. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +376 -408
  189. data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +1 -1
  190. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +272 -287
  191. data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +1 -1
  192. data/ext/isomorfeus_ferret_ext/stem_UTF_8_serbian.c +6530 -0
  193. data/ext/isomorfeus_ferret_ext/stem_UTF_8_serbian.h +6 -0
  194. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +407 -458
  195. data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +1 -1
  196. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +110 -125
  197. data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +1 -1
  198. data/ext/isomorfeus_ferret_ext/stem_UTF_8_tamil.c +1865 -0
  199. data/ext/isomorfeus_ferret_ext/stem_UTF_8_tamil.h +6 -0
  200. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +698 -806
  201. data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +1 -1
  202. data/ext/isomorfeus_ferret_ext/stem_UTF_8_yiddish.c +1220 -0
  203. data/ext/isomorfeus_ferret_ext/stem_UTF_8_yiddish.h +6 -0
  204. data/ext/isomorfeus_ferret_ext/stem_api.c +1 -9
  205. data/ext/isomorfeus_ferret_ext/stem_api.h +1 -3
  206. data/ext/isomorfeus_ferret_ext/stem_header.h +30 -26
  207. data/ext/isomorfeus_ferret_ext/stem_modules.h +113 -26
  208. data/ext/isomorfeus_ferret_ext/stem_modules.txt +18 -5
  209. data/ext/isomorfeus_ferret_ext/stem_utilities.c +167 -132
  210. data/ext/isomorfeus_ferret_ext/test.c +7 -1
  211. data/ext/isomorfeus_ferret_ext/test_fields.c +57 -45
  212. data/ext/isomorfeus_ferret_ext/test_index.c +4 -1
  213. data/ext/isomorfeus_ferret_ext/test_search.c +0 -1
  214. data/lib/isomorfeus/ferret/version.rb +1 -1
  215. metadata +125 -5
  216. data/ext/isomorfeus_ferret_ext/q_parser.y +0 -1366
@@ -0,0 +1,344 @@
1
+ /* Copyright 2013 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
+ /**
8
+ * @file
9
+ * API for Brotli decompression.
10
+ */
11
+
12
+ #ifndef BROTLI_DEC_DECODE_H_
13
+ #define BROTLI_DEC_DECODE_H_
14
+
15
+ #include "brotli_port.h"
16
+ #include "brotli_types.h"
17
+
18
+ #if defined(__cplusplus) || defined(c_plusplus)
19
+ extern "C" {
20
+ #endif
21
+
22
+ /**
23
+ * Opaque structure that holds decoder state.
24
+ *
25
+ * Allocated and initialized with ::BrotliDecoderCreateInstance.
26
+ * Cleaned up and deallocated with ::BrotliDecoderDestroyInstance.
27
+ */
28
+ typedef struct BrotliDecoderStateStruct BrotliDecoderState;
29
+
30
+ /**
31
+ * Result type for ::BrotliDecoderDecompress and
32
+ * ::BrotliDecoderDecompressStream functions.
33
+ */
34
+ typedef enum {
35
+ /** Decoding error, e.g. corrupted input or memory allocation problem. */
36
+ BROTLI_DECODER_RESULT_ERROR = 0,
37
+ /** Decoding successfully completed. */
38
+ BROTLI_DECODER_RESULT_SUCCESS = 1,
39
+ /** Partially done; should be called again with more input. */
40
+ BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT = 2,
41
+ /** Partially done; should be called again with more output. */
42
+ BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT = 3
43
+ } BrotliDecoderResult;
44
+
45
+ /**
46
+ * Template that evaluates items of ::BrotliDecoderErrorCode.
47
+ *
48
+ * Example: @code {.cpp}
49
+ * // Log Brotli error code.
50
+ * switch (brotliDecoderErrorCode) {
51
+ * #define CASE_(PREFIX, NAME, CODE) \
52
+ * case BROTLI_DECODER ## PREFIX ## NAME: \
53
+ * LOG(INFO) << "error code:" << #NAME; \
54
+ * break;
55
+ * #define NEWLINE_
56
+ * BROTLI_DECODER_ERROR_CODES_LIST(CASE_, NEWLINE_)
57
+ * #undef CASE_
58
+ * #undef NEWLINE_
59
+ * default: LOG(FATAL) << "unknown brotli error code";
60
+ * }
61
+ * @endcode
62
+ */
63
+ #define BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE, SEPARATOR) \
64
+ BROTLI_ERROR_CODE(_, NO_ERROR, 0) SEPARATOR \
65
+ /* Same as BrotliDecoderResult values */ \
66
+ BROTLI_ERROR_CODE(_, SUCCESS, 1) SEPARATOR \
67
+ BROTLI_ERROR_CODE(_, NEEDS_MORE_INPUT, 2) SEPARATOR \
68
+ BROTLI_ERROR_CODE(_, NEEDS_MORE_OUTPUT, 3) SEPARATOR \
69
+ \
70
+ /* Errors caused by invalid input */ \
71
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_NIBBLE, -1) SEPARATOR \
72
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, RESERVED, -2) SEPARATOR \
73
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, EXUBERANT_META_NIBBLE, -3) SEPARATOR \
74
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_ALPHABET, -4) SEPARATOR \
75
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, SIMPLE_HUFFMAN_SAME, -5) SEPARATOR \
76
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, CL_SPACE, -6) SEPARATOR \
77
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, HUFFMAN_SPACE, -7) SEPARATOR \
78
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, CONTEXT_MAP_REPEAT, -8) SEPARATOR \
79
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_1, -9) SEPARATOR \
80
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, BLOCK_LENGTH_2, -10) SEPARATOR \
81
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, TRANSFORM, -11) SEPARATOR \
82
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, DICTIONARY, -12) SEPARATOR \
83
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, WINDOW_BITS, -13) SEPARATOR \
84
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_1, -14) SEPARATOR \
85
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \
86
+ BROTLI_ERROR_CODE(_ERROR_FORMAT_, DISTANCE, -16) SEPARATOR \
87
+ \
88
+ /* -17..-18 codes are reserved */ \
89
+ \
90
+ BROTLI_ERROR_CODE(_ERROR_, DICTIONARY_NOT_SET, -19) SEPARATOR \
91
+ BROTLI_ERROR_CODE(_ERROR_, INVALID_ARGUMENTS, -20) SEPARATOR \
92
+ \
93
+ /* Memory allocation problems */ \
94
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MODES, -21) SEPARATOR \
95
+ /* Literal, insert and distance trees together */ \
96
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, TREE_GROUPS, -22) SEPARATOR \
97
+ /* -23..-24 codes are reserved for distinct tree groups */ \
98
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, CONTEXT_MAP, -25) SEPARATOR \
99
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_1, -26) SEPARATOR \
100
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, RING_BUFFER_2, -27) SEPARATOR \
101
+ /* -28..-29 codes are reserved for dynamic ring-buffer allocation */ \
102
+ BROTLI_ERROR_CODE(_ERROR_ALLOC_, BLOCK_TYPE_TREES, -30) SEPARATOR \
103
+ \
104
+ /* "Impossible" states */ \
105
+ BROTLI_ERROR_CODE(_ERROR_, UNREACHABLE, -31)
106
+
107
+ /**
108
+ * Error code for detailed logging / production debugging.
109
+ *
110
+ * See ::BrotliDecoderGetErrorCode and ::BROTLI_LAST_ERROR_CODE.
111
+ */
112
+ typedef enum {
113
+ #define BROTLI_COMMA_ ,
114
+ #define BROTLI_ERROR_CODE_ENUM_ITEM_(PREFIX, NAME, CODE) \
115
+ BROTLI_DECODER ## PREFIX ## NAME = CODE
116
+ BROTLI_DECODER_ERROR_CODES_LIST(BROTLI_ERROR_CODE_ENUM_ITEM_, BROTLI_COMMA_)
117
+ } BrotliDecoderErrorCode;
118
+ #undef BROTLI_ERROR_CODE_ENUM_ITEM_
119
+ #undef BROTLI_COMMA_
120
+
121
+ /**
122
+ * The value of the last error code, negative integer.
123
+ *
124
+ * All other error code values are in the range from ::BROTLI_LAST_ERROR_CODE
125
+ * to @c -1. There are also 4 other possible non-error codes @c 0 .. @c 3 in
126
+ * ::BrotliDecoderErrorCode enumeration.
127
+ */
128
+ #define BROTLI_LAST_ERROR_CODE BROTLI_DECODER_ERROR_UNREACHABLE
129
+
130
+ /** Options to be used with ::BrotliDecoderSetParameter. */
131
+ typedef enum BrotliDecoderParameter {
132
+ /**
133
+ * Disable "canny" ring buffer allocation strategy.
134
+ *
135
+ * Ring buffer is allocated according to window size, despite the real size of
136
+ * the content.
137
+ */
138
+ BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION = 0,
139
+ /**
140
+ * Flag that determines if "Large Window Brotli" is used.
141
+ */
142
+ BROTLI_DECODER_PARAM_LARGE_WINDOW = 1
143
+ } BrotliDecoderParameter;
144
+
145
+ /**
146
+ * Sets the specified parameter to the given decoder instance.
147
+ *
148
+ * @param state decoder instance
149
+ * @param param parameter to set
150
+ * @param value new parameter value
151
+ * @returns ::BROTLI_FALSE if parameter is unrecognized, or value is invalid
152
+ * @returns ::BROTLI_TRUE if value is accepted
153
+ */
154
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderSetParameter(
155
+ BrotliDecoderState* state, BrotliDecoderParameter param, uint32_t value);
156
+
157
+ /**
158
+ * Creates an instance of ::BrotliDecoderState and initializes it.
159
+ *
160
+ * The instance can be used once for decoding and should then be destroyed with
161
+ * ::BrotliDecoderDestroyInstance, it cannot be reused for a new decoding
162
+ * session.
163
+ *
164
+ * @p alloc_func and @p free_func @b MUST be both zero or both non-zero. In the
165
+ * case they are both zero, default memory allocators are used. @p opaque is
166
+ * passed to @p alloc_func and @p free_func when they are called. @p free_func
167
+ * has to return without doing anything when asked to free a NULL pointer.
168
+ *
169
+ * @param alloc_func custom memory allocation function
170
+ * @param free_func custom memory free function
171
+ * @param opaque custom memory manager handle
172
+ * @returns @c 0 if instance can not be allocated or initialized
173
+ * @returns pointer to initialized ::BrotliDecoderState otherwise
174
+ */
175
+ BROTLI_DEC_API BrotliDecoderState* BrotliDecoderCreateInstance(
176
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);
177
+
178
+ /**
179
+ * Deinitializes and frees ::BrotliDecoderState instance.
180
+ *
181
+ * @param state decoder instance to be cleaned up and deallocated
182
+ */
183
+ BROTLI_DEC_API void BrotliDecoderDestroyInstance(BrotliDecoderState* state);
184
+
185
+ /**
186
+ * Performs one-shot memory-to-memory decompression.
187
+ *
188
+ * Decompresses the data in @p encoded_buffer into @p decoded_buffer, and sets
189
+ * @p *decoded_size to the decompressed length.
190
+ *
191
+ * @param encoded_size size of @p encoded_buffer
192
+ * @param encoded_buffer compressed data buffer with at least @p encoded_size
193
+ * addressable bytes
194
+ * @param[in, out] decoded_size @b in: size of @p decoded_buffer; \n
195
+ * @b out: length of decompressed data written to
196
+ * @p decoded_buffer
197
+ * @param decoded_buffer decompressed data destination buffer
198
+ * @returns ::BROTLI_DECODER_RESULT_ERROR if input is corrupted, memory
199
+ * allocation failed, or @p decoded_buffer is not large enough;
200
+ * @returns ::BROTLI_DECODER_RESULT_SUCCESS otherwise
201
+ */
202
+ BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompress(
203
+ size_t encoded_size,
204
+ const uint8_t encoded_buffer[BROTLI_ARRAY_PARAM(encoded_size)],
205
+ size_t* decoded_size,
206
+ uint8_t decoded_buffer[BROTLI_ARRAY_PARAM(*decoded_size)]);
207
+
208
+ /**
209
+ * Decompresses the input stream to the output stream.
210
+ *
211
+ * The values @p *available_in and @p *available_out must specify the number of
212
+ * bytes addressable at @p *next_in and @p *next_out respectively.
213
+ * When @p *available_out is @c 0, @p next_out is allowed to be @c NULL.
214
+ *
215
+ * After each call, @p *available_in will be decremented by the amount of input
216
+ * bytes consumed, and the @p *next_in pointer will be incremented by that
217
+ * amount. Similarly, @p *available_out will be decremented by the amount of
218
+ * output bytes written, and the @p *next_out pointer will be incremented by
219
+ * that amount.
220
+ *
221
+ * @p total_out, if it is not a null-pointer, will be set to the number
222
+ * of bytes decompressed since the last @p state initialization.
223
+ *
224
+ * @note Input is never overconsumed, so @p next_in and @p available_in could be
225
+ * passed to the next consumer after decoding is complete.
226
+ *
227
+ * @param state decoder instance
228
+ * @param[in, out] available_in @b in: amount of available input; \n
229
+ * @b out: amount of unused input
230
+ * @param[in, out] next_in pointer to the next compressed byte
231
+ * @param[in, out] available_out @b in: length of output buffer; \n
232
+ * @b out: remaining size of output buffer
233
+ * @param[in, out] next_out output buffer cursor;
234
+ * can be @c NULL if @p available_out is @c 0
235
+ * @param[out] total_out number of bytes decompressed so far; can be @c NULL
236
+ * @returns ::BROTLI_DECODER_RESULT_ERROR if input is corrupted, memory
237
+ * allocation failed, arguments were invalid, etc.;
238
+ * use ::BrotliDecoderGetErrorCode to get detailed error code
239
+ * @returns ::BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT decoding is blocked until
240
+ * more input data is provided
241
+ * @returns ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT decoding is blocked until
242
+ * more output space is provided
243
+ * @returns ::BROTLI_DECODER_RESULT_SUCCESS decoding is finished, no more
244
+ * input might be consumed and no more output will be produced
245
+ */
246
+ BROTLI_DEC_API BrotliDecoderResult BrotliDecoderDecompressStream(
247
+ BrotliDecoderState* state, size_t* available_in, const uint8_t** next_in,
248
+ size_t* available_out, uint8_t** next_out, size_t* total_out);
249
+
250
+ /**
251
+ * Checks if decoder has more output.
252
+ *
253
+ * @param state decoder instance
254
+ * @returns ::BROTLI_TRUE, if decoder has some unconsumed output
255
+ * @returns ::BROTLI_FALSE otherwise
256
+ */
257
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderHasMoreOutput(
258
+ const BrotliDecoderState* state);
259
+
260
+ /**
261
+ * Acquires pointer to internal output buffer.
262
+ *
263
+ * This method is used to make language bindings easier and more efficient:
264
+ * -# push data to ::BrotliDecoderDecompressStream,
265
+ * until ::BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT is reported
266
+ * -# use ::BrotliDecoderTakeOutput to peek bytes and copy to language-specific
267
+ * entity
268
+ *
269
+ * Also this could be useful if there is an output stream that is able to
270
+ * consume all the provided data (e.g. when data is saved to file system).
271
+ *
272
+ * @attention After every call to ::BrotliDecoderTakeOutput @p *size bytes of
273
+ * output are considered consumed for all consecutive calls to the
274
+ * instance methods; returned pointer becomes invalidated as well.
275
+ *
276
+ * @note Decoder output is not guaranteed to be contiguous. This means that
277
+ * after the size-unrestricted call to ::BrotliDecoderTakeOutput,
278
+ * immediate next call to ::BrotliDecoderTakeOutput may return more data.
279
+ *
280
+ * @param state decoder instance
281
+ * @param[in, out] size @b in: number of bytes caller is ready to take, @c 0 if
282
+ * any amount could be handled; \n
283
+ * @b out: amount of data pointed by returned pointer and
284
+ * considered consumed; \n
285
+ * out value is never greater than in value, unless it is @c 0
286
+ * @returns pointer to output data
287
+ */
288
+ BROTLI_DEC_API const uint8_t* BrotliDecoderTakeOutput(
289
+ BrotliDecoderState* state, size_t* size);
290
+
291
+ /**
292
+ * Checks if instance has already consumed input.
293
+ *
294
+ * Instance that returns ::BROTLI_FALSE is considered "fresh" and could be
295
+ * reused.
296
+ *
297
+ * @param state decoder instance
298
+ * @returns ::BROTLI_TRUE if decoder has already used some input bytes
299
+ * @returns ::BROTLI_FALSE otherwise
300
+ */
301
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsUsed(const BrotliDecoderState* state);
302
+
303
+ /**
304
+ * Checks if decoder instance reached the final state.
305
+ *
306
+ * @param state decoder instance
307
+ * @returns ::BROTLI_TRUE if decoder is in a state where it reached the end of
308
+ * the input and produced all of the output
309
+ * @returns ::BROTLI_FALSE otherwise
310
+ */
311
+ BROTLI_DEC_API BROTLI_BOOL BrotliDecoderIsFinished(
312
+ const BrotliDecoderState* state);
313
+
314
+ /**
315
+ * Acquires a detailed error code.
316
+ *
317
+ * Should be used only after ::BrotliDecoderDecompressStream returns
318
+ * ::BROTLI_DECODER_RESULT_ERROR.
319
+ *
320
+ * See also ::BrotliDecoderErrorString
321
+ *
322
+ * @param state decoder instance
323
+ * @returns last saved error code
324
+ */
325
+ BROTLI_DEC_API BrotliDecoderErrorCode BrotliDecoderGetErrorCode(
326
+ const BrotliDecoderState* state);
327
+
328
+ /**
329
+ * Converts error code to a c-string.
330
+ */
331
+ BROTLI_DEC_API const char* BrotliDecoderErrorString(BrotliDecoderErrorCode c);
332
+
333
+ /**
334
+ * Gets a decoder library version.
335
+ *
336
+ * Look at BROTLI_VERSION for more information.
337
+ */
338
+ BROTLI_DEC_API uint32_t BrotliDecoderVersion(void);
339
+
340
+ #if defined(__cplusplus) || defined(c_plusplus)
341
+ } /* extern "C" */
342
+ #endif
343
+
344
+ #endif /* BROTLI_DEC_DECODE_H_ */
@@ -0,0 +1,145 @@
1
+ /* Copyright 2013 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
+ /* Function to find backward reference copies. */
8
+
9
+ #include "brotli_enc_backward_references.h"
10
+
11
+ #include "brotli_common_constants.h"
12
+ #include "brotli_common_context.h"
13
+ #include "brotli_common_dictionary.h"
14
+ #include "brotli_common_platform.h"
15
+ #include "brotli_types.h"
16
+ #include "brotli_enc_command.h"
17
+ #include "brotli_enc_dictionary_hash.h"
18
+ #include "brotli_enc_memory.h"
19
+ #include "brotli_enc_quality.h"
20
+
21
+ #if defined(__cplusplus) || defined(c_plusplus)
22
+ extern "C" {
23
+ #endif
24
+
25
+ static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance,
26
+ size_t max_distance,
27
+ const int* dist_cache) {
28
+ if (distance <= max_distance) {
29
+ size_t distance_plus_3 = distance + 3;
30
+ size_t offset0 = distance_plus_3 - (size_t)dist_cache[0];
31
+ size_t offset1 = distance_plus_3 - (size_t)dist_cache[1];
32
+ if (distance == (size_t)dist_cache[0]) {
33
+ return 0;
34
+ } else if (distance == (size_t)dist_cache[1]) {
35
+ return 1;
36
+ } else if (offset0 < 7) {
37
+ return (0x9750468 >> (4 * offset0)) & 0xF;
38
+ } else if (offset1 < 7) {
39
+ return (0xFDB1ACE >> (4 * offset1)) & 0xF;
40
+ } else if (distance == (size_t)dist_cache[2]) {
41
+ return 2;
42
+ } else if (distance == (size_t)dist_cache[3]) {
43
+ return 3;
44
+ }
45
+ }
46
+ return distance + BROTLI_NUM_DISTANCE_SHORT_CODES - 1;
47
+ }
48
+
49
+ #define EXPAND_CAT(a, b) CAT(a, b)
50
+ #define CAT(a, b) a ## b
51
+ #define FN(X) EXPAND_CAT(X, HASHER())
52
+ #define EXPORT_FN(X) EXPAND_CAT(X, EXPAND_CAT(PREFIX(), HASHER()))
53
+
54
+ #define PREFIX() N
55
+
56
+ #define HASHER() H2
57
+ /* NOLINTNEXTLINE(build/include) */
58
+ #include "brotli_enc_backward_references_inc.h"
59
+ #undef HASHER
60
+
61
+ #define HASHER() H3
62
+ /* NOLINTNEXTLINE(build/include) */
63
+ #include "brotli_enc_backward_references_inc.h"
64
+ #undef HASHER
65
+
66
+ #define HASHER() H4
67
+ /* NOLINTNEXTLINE(build/include) */
68
+ #include "brotli_enc_backward_references_inc.h"
69
+ #undef HASHER
70
+
71
+ #define HASHER() H5
72
+ /* NOLINTNEXTLINE(build/include) */
73
+ #include "brotli_enc_backward_references_inc.h"
74
+ #undef HASHER
75
+
76
+ #define HASHER() H6
77
+ /* NOLINTNEXTLINE(build/include) */
78
+ #include "brotli_enc_backward_references_inc.h"
79
+ #undef HASHER
80
+
81
+ #define HASHER() H40
82
+ /* NOLINTNEXTLINE(build/include) */
83
+ #include "brotli_enc_backward_references_inc.h"
84
+ #undef HASHER
85
+
86
+ #define HASHER() H41
87
+ /* NOLINTNEXTLINE(build/include) */
88
+ #include "brotli_enc_backward_references_inc.h"
89
+ #undef HASHER
90
+
91
+ #define HASHER() H42
92
+ /* NOLINTNEXTLINE(build/include) */
93
+ #include "brotli_enc_backward_references_inc.h"
94
+ #undef HASHER
95
+
96
+ #define HASHER() H54
97
+ /* NOLINTNEXTLINE(build/include) */
98
+ #include "brotli_enc_backward_references_inc.h"
99
+ #undef HASHER
100
+
101
+ #define HASHER() H35
102
+ /* NOLINTNEXTLINE(build/include) */
103
+ #include "brotli_enc_backward_references_inc.h"
104
+ #undef HASHER
105
+
106
+ #define HASHER() H55
107
+ /* NOLINTNEXTLINE(build/include) */
108
+ #include "brotli_enc_backward_references_inc.h"
109
+ #undef HASHER
110
+
111
+ #define HASHER() H65
112
+ /* NOLINTNEXTLINE(build/include) */
113
+ #include "brotli_enc_backward_references_inc.h"
114
+ #undef HASHER
115
+
116
+ #undef PREFIX
117
+
118
+ #undef EXPORT_FN
119
+ #undef FN
120
+ #undef CAT
121
+ #undef EXPAND_CAT
122
+
123
+ void BrotliCreateBackwardReferences(size_t num_bytes,
124
+ size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
125
+ ContextLut literal_context_lut, const BrotliEncoderParams* params,
126
+ Hasher* hasher, int* dist_cache, size_t* last_insert_len,
127
+ Command* commands, size_t* num_commands, size_t* num_literals) {
128
+ switch (params->hasher.type) {
129
+ #define CASE_(N) \
130
+ case N: \
131
+ CreateBackwardReferencesNH ## N(num_bytes, \
132
+ position, ringbuffer, ringbuffer_mask, \
133
+ literal_context_lut, params, hasher, dist_cache, \
134
+ last_insert_len, commands, num_commands, num_literals); \
135
+ return;
136
+ FOR_GENERIC_HASHERS(CASE_)
137
+ #undef CASE_
138
+ default:
139
+ break;
140
+ }
141
+ }
142
+
143
+ #if defined(__cplusplus) || defined(c_plusplus)
144
+ } /* extern "C" */
145
+ #endif
@@ -0,0 +1,39 @@
1
+ /* Copyright 2013 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
+ /* Function to find backward reference copies. */
8
+
9
+ #ifndef BROTLI_ENC_BACKWARD_REFERENCES_H_
10
+ #define BROTLI_ENC_BACKWARD_REFERENCES_H_
11
+
12
+ #include "brotli_common_constants.h"
13
+ #include "brotli_common_context.h"
14
+ #include "brotli_common_dictionary.h"
15
+ #include "brotli_common_platform.h"
16
+ #include "brotli_types.h"
17
+ #include "brotli_enc_command.h"
18
+ #include "brotli_enc_hash.h"
19
+ #include "brotli_enc_quality.h"
20
+
21
+ #if defined(__cplusplus) || defined(c_plusplus)
22
+ extern "C" {
23
+ #endif
24
+
25
+ /* "commands" points to the next output command to write to, "*num_commands" is
26
+ initially the total amount of commands output by previous
27
+ CreateBackwardReferences calls, and must be incremented by the amount written
28
+ by this call. */
29
+ BROTLI_INTERNAL void BrotliCreateBackwardReferences(size_t num_bytes,
30
+ size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
31
+ ContextLut literal_context_lut, const BrotliEncoderParams* params,
32
+ Hasher* hasher, int* dist_cache, size_t* last_insert_len,
33
+ Command* commands, size_t* num_commands, size_t* num_literals);
34
+
35
+ #if defined(__cplusplus) || defined(c_plusplus)
36
+ } /* extern "C" */
37
+ #endif
38
+
39
+ #endif /* BROTLI_ENC_BACKWARD_REFERENCES_H_ */