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,190 @@
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
+ /* This class models a sequence of literals and a backward reference copy. */
8
+
9
+ #ifndef BROTLI_ENC_COMMAND_H_
10
+ #define BROTLI_ENC_COMMAND_H_
11
+
12
+ #include "brotli_common_constants.h"
13
+ #include "brotli_common_platform.h"
14
+ #include "brotli_types.h"
15
+ #include "brotli_enc_fast_log.h"
16
+ #include "brotli_enc_params.h"
17
+ #include "brotli_enc_prefix.h"
18
+
19
+ #if defined(__cplusplus) || defined(c_plusplus)
20
+ extern "C" {
21
+ #endif
22
+
23
+ BROTLI_INTERNAL extern const uint32_t
24
+ kBrotliInsBase[BROTLI_NUM_INS_COPY_CODES];
25
+ BROTLI_INTERNAL extern const uint32_t
26
+ kBrotliInsExtra[BROTLI_NUM_INS_COPY_CODES];
27
+ BROTLI_INTERNAL extern const uint32_t
28
+ kBrotliCopyBase[BROTLI_NUM_INS_COPY_CODES];
29
+ BROTLI_INTERNAL extern const uint32_t
30
+ kBrotliCopyExtra[BROTLI_NUM_INS_COPY_CODES];
31
+
32
+ static BROTLI_INLINE uint16_t GetInsertLengthCode(size_t insertlen) {
33
+ if (insertlen < 6) {
34
+ return (uint16_t)insertlen;
35
+ } else if (insertlen < 130) {
36
+ uint32_t nbits = Log2FloorNonZero(insertlen - 2) - 1u;
37
+ return (uint16_t)((nbits << 1) + ((insertlen - 2) >> nbits) + 2);
38
+ } else if (insertlen < 2114) {
39
+ return (uint16_t)(Log2FloorNonZero(insertlen - 66) + 10);
40
+ } else if (insertlen < 6210) {
41
+ return 21u;
42
+ } else if (insertlen < 22594) {
43
+ return 22u;
44
+ } else {
45
+ return 23u;
46
+ }
47
+ }
48
+
49
+ static BROTLI_INLINE uint16_t GetCopyLengthCode(size_t copylen) {
50
+ if (copylen < 10) {
51
+ return (uint16_t)(copylen - 2);
52
+ } else if (copylen < 134) {
53
+ uint32_t nbits = Log2FloorNonZero(copylen - 6) - 1u;
54
+ return (uint16_t)((nbits << 1) + ((copylen - 6) >> nbits) + 4);
55
+ } else if (copylen < 2118) {
56
+ return (uint16_t)(Log2FloorNonZero(copylen - 70) + 12);
57
+ } else {
58
+ return 23u;
59
+ }
60
+ }
61
+
62
+ static BROTLI_INLINE uint16_t CombineLengthCodes(
63
+ uint16_t inscode, uint16_t copycode, BROTLI_BOOL use_last_distance) {
64
+ uint16_t bits64 =
65
+ (uint16_t)((copycode & 0x7u) | ((inscode & 0x7u) << 3u));
66
+ if (use_last_distance && inscode < 8u && copycode < 16u) {
67
+ return (copycode < 8u) ? bits64 : (bits64 | 64u);
68
+ } else {
69
+ /* Specification: 5 Encoding of ... (last table) */
70
+ /* offset = 2 * index, where index is in range [0..8] */
71
+ uint32_t offset = 2u * ((copycode >> 3u) + 3u * (inscode >> 3u));
72
+ /* All values in specification are K * 64,
73
+ where K = [2, 3, 6, 4, 5, 8, 7, 9, 10],
74
+ i + 1 = [1, 2, 3, 4, 5, 6, 7, 8, 9],
75
+ K - i - 1 = [1, 1, 3, 0, 0, 2, 0, 1, 2] = D.
76
+ All values in D require only 2 bits to encode.
77
+ Magic constant is shifted 6 bits left, to avoid final multiplication. */
78
+ offset = (offset << 5u) + 0x40u + ((0x520D40u >> offset) & 0xC0u);
79
+ return (uint16_t)(offset | bits64);
80
+ }
81
+ }
82
+
83
+ static BROTLI_INLINE void GetLengthCode(size_t insertlen, size_t copylen,
84
+ BROTLI_BOOL use_last_distance,
85
+ uint16_t* code) {
86
+ uint16_t inscode = GetInsertLengthCode(insertlen);
87
+ uint16_t copycode = GetCopyLengthCode(copylen);
88
+ *code = CombineLengthCodes(inscode, copycode, use_last_distance);
89
+ }
90
+
91
+ static BROTLI_INLINE uint32_t GetInsertBase(uint16_t inscode) {
92
+ return kBrotliInsBase[inscode];
93
+ }
94
+
95
+ static BROTLI_INLINE uint32_t GetInsertExtra(uint16_t inscode) {
96
+ return kBrotliInsExtra[inscode];
97
+ }
98
+
99
+ static BROTLI_INLINE uint32_t GetCopyBase(uint16_t copycode) {
100
+ return kBrotliCopyBase[copycode];
101
+ }
102
+
103
+ static BROTLI_INLINE uint32_t GetCopyExtra(uint16_t copycode) {
104
+ return kBrotliCopyExtra[copycode];
105
+ }
106
+
107
+ typedef struct Command {
108
+ uint32_t insert_len_;
109
+ /* Stores copy_len in low 25 bits and copy_code - copy_len in high 7 bit. */
110
+ uint32_t copy_len_;
111
+ /* Stores distance extra bits. */
112
+ uint32_t dist_extra_;
113
+ uint16_t cmd_prefix_;
114
+ /* Stores distance code in low 10 bits
115
+ and number of extra bits in high 6 bits. */
116
+ uint16_t dist_prefix_;
117
+ } Command;
118
+
119
+ /* distance_code is e.g. 0 for same-as-last short code, or 16 for offset 1. */
120
+ static BROTLI_INLINE void InitCommand(Command* self,
121
+ const BrotliDistanceParams* dist, size_t insertlen,
122
+ size_t copylen, int copylen_code_delta, size_t distance_code) {
123
+ /* Don't rely on signed int representation, use honest casts. */
124
+ uint32_t delta = (uint8_t)((int8_t)copylen_code_delta);
125
+ self->insert_len_ = (uint32_t)insertlen;
126
+ self->copy_len_ = (uint32_t)(copylen | (delta << 25));
127
+ /* The distance prefix and extra bits are stored in this Command as if
128
+ npostfix and ndirect were 0, they are only recomputed later after the
129
+ clustering if needed. */
130
+ PrefixEncodeCopyDistance(
131
+ distance_code, dist->num_direct_distance_codes,
132
+ dist->distance_postfix_bits, &self->dist_prefix_, &self->dist_extra_);
133
+ GetLengthCode(
134
+ insertlen, (size_t)((int)copylen + copylen_code_delta),
135
+ TO_BROTLI_BOOL((self->dist_prefix_ & 0x3FF) == 0), &self->cmd_prefix_);
136
+ }
137
+
138
+ static BROTLI_INLINE void InitInsertCommand(Command* self, size_t insertlen) {
139
+ self->insert_len_ = (uint32_t)insertlen;
140
+ self->copy_len_ = 4 << 25;
141
+ self->dist_extra_ = 0;
142
+ self->dist_prefix_ = BROTLI_NUM_DISTANCE_SHORT_CODES;
143
+ GetLengthCode(insertlen, 4, BROTLI_FALSE, &self->cmd_prefix_);
144
+ }
145
+
146
+ static BROTLI_INLINE uint32_t CommandRestoreDistanceCode(
147
+ const Command* self, const BrotliDistanceParams* dist) {
148
+ if ((self->dist_prefix_ & 0x3FFu) <
149
+ BROTLI_NUM_DISTANCE_SHORT_CODES + dist->num_direct_distance_codes) {
150
+ return self->dist_prefix_ & 0x3FFu;
151
+ } else {
152
+ uint32_t dcode = self->dist_prefix_ & 0x3FFu;
153
+ uint32_t nbits = self->dist_prefix_ >> 10;
154
+ uint32_t extra = self->dist_extra_;
155
+ uint32_t postfix_mask = (1U << dist->distance_postfix_bits) - 1U;
156
+ uint32_t hcode = (dcode - dist->num_direct_distance_codes -
157
+ BROTLI_NUM_DISTANCE_SHORT_CODES) >>
158
+ dist->distance_postfix_bits;
159
+ uint32_t lcode = (dcode - dist->num_direct_distance_codes -
160
+ BROTLI_NUM_DISTANCE_SHORT_CODES) & postfix_mask;
161
+ uint32_t offset = ((2U + (hcode & 1U)) << nbits) - 4U;
162
+ return ((offset + extra) << dist->distance_postfix_bits) + lcode +
163
+ dist->num_direct_distance_codes + BROTLI_NUM_DISTANCE_SHORT_CODES;
164
+ }
165
+ }
166
+
167
+ static BROTLI_INLINE uint32_t CommandDistanceContext(const Command* self) {
168
+ uint32_t r = self->cmd_prefix_ >> 6;
169
+ uint32_t c = self->cmd_prefix_ & 7;
170
+ if ((r == 0 || r == 2 || r == 4 || r == 7) && (c <= 2)) {
171
+ return c;
172
+ }
173
+ return 3;
174
+ }
175
+
176
+ static BROTLI_INLINE uint32_t CommandCopyLen(const Command* self) {
177
+ return self->copy_len_ & 0x1FFFFFF;
178
+ }
179
+
180
+ static BROTLI_INLINE uint32_t CommandCopyLenCode(const Command* self) {
181
+ uint32_t modifier = self->copy_len_ >> 25;
182
+ int32_t delta = (int8_t)((uint8_t)(modifier | ((modifier & 0x40) << 1)));
183
+ return (uint32_t)((int32_t)(self->copy_len_ & 0x1FFFFFF) + delta);
184
+ }
185
+
186
+ #if defined(__cplusplus) || defined(c_plusplus)
187
+ } /* extern "C" */
188
+ #endif
189
+
190
+ #endif /* BROTLI_ENC_COMMAND_H_ */