typenative 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +17 -1
  3. package/bin/cli.js +25 -11
  4. package/bin/go/convert.js +11 -1
  5. package/bin/index.js +221 -44
  6. package/bin/main.js +35 -14
  7. package/bin/node/assert.js +2 -2
  8. package/bin/node/buffer.js +9 -0
  9. package/bin/node/dns.js +1 -1
  10. package/bin/node/events.js +1 -1
  11. package/bin/node/fs.js +1 -1
  12. package/bin/node/fs_watch.js +407 -0
  13. package/bin/node/http2.js +33 -6
  14. package/bin/node/readline.js +1 -1
  15. package/bin/node/registry.js +2 -1
  16. package/bin/node/stream.js +6 -3
  17. package/bin/node/timers.js +1 -1
  18. package/bin/node/tls.js +3 -1
  19. package/bin/node/typed_arrays.js +608 -0
  20. package/bin/node/util.js +3 -0
  21. package/bin/node/zlib.js +131 -16
  22. package/bin/transpiler.js +684 -62
  23. package/bin/version.js +1 -1
  24. package/conformance.md +16 -4
  25. package/examples/README.md +54 -0
  26. package/examples/fibonacci/README.md +89 -0
  27. package/examples/fibonacci/bench.mjs +87 -0
  28. package/examples/fibonacci/main.ts +21 -0
  29. package/examples/hello-world/README.md +62 -0
  30. package/examples/hello-world/bench.mjs +66 -0
  31. package/examples/hello-world/main.ts +7 -0
  32. package/examples/json-server/README.md +125 -0
  33. package/examples/json-server/bench.mjs +171 -0
  34. package/examples/json-server/main.ts +67 -0
  35. package/govendor/github.com/andybalholm/brotli/LICENSE +19 -0
  36. package/govendor/github.com/andybalholm/brotli/README.md +19 -0
  37. package/govendor/github.com/andybalholm/brotli/backward_references.go +185 -0
  38. package/govendor/github.com/andybalholm/brotli/backward_references_hq.go +796 -0
  39. package/govendor/github.com/andybalholm/brotli/bit_cost.go +436 -0
  40. package/govendor/github.com/andybalholm/brotli/bit_reader.go +266 -0
  41. package/govendor/github.com/andybalholm/brotli/bitwriter.go +56 -0
  42. package/govendor/github.com/andybalholm/brotli/block_splitter.go +144 -0
  43. package/govendor/github.com/andybalholm/brotli/block_splitter_command.go +434 -0
  44. package/govendor/github.com/andybalholm/brotli/block_splitter_distance.go +433 -0
  45. package/govendor/github.com/andybalholm/brotli/block_splitter_literal.go +433 -0
  46. package/govendor/github.com/andybalholm/brotli/brotli_bit_stream.go +1435 -0
  47. package/govendor/github.com/andybalholm/brotli/cluster.go +30 -0
  48. package/govendor/github.com/andybalholm/brotli/cluster_command.go +164 -0
  49. package/govendor/github.com/andybalholm/brotli/cluster_distance.go +326 -0
  50. package/govendor/github.com/andybalholm/brotli/cluster_literal.go +326 -0
  51. package/govendor/github.com/andybalholm/brotli/command.go +254 -0
  52. package/govendor/github.com/andybalholm/brotli/compress_fragment.go +834 -0
  53. package/govendor/github.com/andybalholm/brotli/compress_fragment_two_pass.go +775 -0
  54. package/govendor/github.com/andybalholm/brotli/constants.go +77 -0
  55. package/govendor/github.com/andybalholm/brotli/context.go +2176 -0
  56. package/govendor/github.com/andybalholm/brotli/decode.go +2570 -0
  57. package/govendor/github.com/andybalholm/brotli/dictionary.go +122890 -0
  58. package/govendor/github.com/andybalholm/brotli/dictionary_hash.go +32779 -0
  59. package/govendor/github.com/andybalholm/brotli/encode.go +1220 -0
  60. package/govendor/github.com/andybalholm/brotli/encoder.go +177 -0
  61. package/govendor/github.com/andybalholm/brotli/encoder_dict.go +22 -0
  62. package/govendor/github.com/andybalholm/brotli/encoder_fast.go +201 -0
  63. package/govendor/github.com/andybalholm/brotli/entropy_encode.go +592 -0
  64. package/govendor/github.com/andybalholm/brotli/entropy_encode_static.go +4399 -0
  65. package/govendor/github.com/andybalholm/brotli/fast_log.go +290 -0
  66. package/govendor/github.com/andybalholm/brotli/find_match_length.go +45 -0
  67. package/govendor/github.com/andybalholm/brotli/go.mod +3 -0
  68. package/govendor/github.com/andybalholm/brotli/h10.go +287 -0
  69. package/govendor/github.com/andybalholm/brotli/h5.go +214 -0
  70. package/govendor/github.com/andybalholm/brotli/h6.go +216 -0
  71. package/govendor/github.com/andybalholm/brotli/hash.go +342 -0
  72. package/govendor/github.com/andybalholm/brotli/hash_composite.go +93 -0
  73. package/govendor/github.com/andybalholm/brotli/hash_forgetful_chain.go +252 -0
  74. package/govendor/github.com/andybalholm/brotli/hash_longest_match_quickly.go +214 -0
  75. package/govendor/github.com/andybalholm/brotli/hash_rolling.go +168 -0
  76. package/govendor/github.com/andybalholm/brotli/histogram.go +226 -0
  77. package/govendor/github.com/andybalholm/brotli/http.go +201 -0
  78. package/govendor/github.com/andybalholm/brotli/huffman.go +653 -0
  79. package/govendor/github.com/andybalholm/brotli/literal_cost.go +182 -0
  80. package/govendor/github.com/andybalholm/brotli/matchfinder/bargain1.go +212 -0
  81. package/govendor/github.com/andybalholm/brotli/matchfinder/bargain2.go +248 -0
  82. package/govendor/github.com/andybalholm/brotli/matchfinder/bargain3.go +278 -0
  83. package/govendor/github.com/andybalholm/brotli/matchfinder/emitter.go +34 -0
  84. package/govendor/github.com/andybalholm/brotli/matchfinder/m0.go +175 -0
  85. package/govendor/github.com/andybalholm/brotli/matchfinder/m4.go +339 -0
  86. package/govendor/github.com/andybalholm/brotli/matchfinder/matchfinder.go +103 -0
  87. package/govendor/github.com/andybalholm/brotli/matchfinder/pathfinder.go +328 -0
  88. package/govendor/github.com/andybalholm/brotli/matchfinder/textencoder.go +53 -0
  89. package/govendor/github.com/andybalholm/brotli/matchfinder/trio.go +327 -0
  90. package/govendor/github.com/andybalholm/brotli/matchfinder/zdfast.go +258 -0
  91. package/govendor/github.com/andybalholm/brotli/matchfinder/zfast.go +206 -0
  92. package/govendor/github.com/andybalholm/brotli/matchfinder/zm.go +302 -0
  93. package/govendor/github.com/andybalholm/brotli/memory.go +66 -0
  94. package/govendor/github.com/andybalholm/brotli/metablock.go +574 -0
  95. package/govendor/github.com/andybalholm/brotli/metablock_command.go +165 -0
  96. package/govendor/github.com/andybalholm/brotli/metablock_distance.go +165 -0
  97. package/govendor/github.com/andybalholm/brotli/metablock_literal.go +165 -0
  98. package/govendor/github.com/andybalholm/brotli/params.go +37 -0
  99. package/govendor/github.com/andybalholm/brotli/platform.go +103 -0
  100. package/govendor/github.com/andybalholm/brotli/prefix.go +30 -0
  101. package/govendor/github.com/andybalholm/brotli/prefix_dec.go +723 -0
  102. package/govendor/github.com/andybalholm/brotli/quality.go +196 -0
  103. package/govendor/github.com/andybalholm/brotli/reader.go +127 -0
  104. package/govendor/github.com/andybalholm/brotli/ringbuffer.go +134 -0
  105. package/govendor/github.com/andybalholm/brotli/state.go +313 -0
  106. package/govendor/github.com/andybalholm/brotli/static_dict.go +662 -0
  107. package/govendor/github.com/andybalholm/brotli/static_dict_lut.go +75094 -0
  108. package/govendor/github.com/andybalholm/brotli/symbol_list.go +22 -0
  109. package/govendor/github.com/andybalholm/brotli/transform.go +641 -0
  110. package/govendor/github.com/andybalholm/brotli/utf8_util.go +70 -0
  111. package/govendor/github.com/andybalholm/brotli/util.go +7 -0
  112. package/govendor/github.com/andybalholm/brotli/write_bits.go +52 -0
  113. package/govendor/github.com/andybalholm/brotli/writer.go +162 -0
  114. package/govendor/github.com/fsnotify/fsnotify/.mailmap +2 -0
  115. package/govendor/github.com/fsnotify/fsnotify/CHANGELOG.md +651 -0
  116. package/govendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md +147 -0
  117. package/govendor/github.com/fsnotify/fsnotify/LICENSE +25 -0
  118. package/govendor/github.com/fsnotify/fsnotify/README.md +214 -0
  119. package/govendor/github.com/fsnotify/fsnotify/backend_fen.go +469 -0
  120. package/govendor/github.com/fsnotify/fsnotify/backend_inotify.go +597 -0
  121. package/govendor/github.com/fsnotify/fsnotify/backend_kqueue.go +735 -0
  122. package/govendor/github.com/fsnotify/fsnotify/backend_other.go +22 -0
  123. package/govendor/github.com/fsnotify/fsnotify/backend_windows.go +702 -0
  124. package/govendor/github.com/fsnotify/fsnotify/fsnotify.go +526 -0
  125. package/govendor/github.com/fsnotify/fsnotify/go.mod +3 -0
  126. package/govendor/github.com/fsnotify/fsnotify/internal/darwin.go +20 -0
  127. package/govendor/github.com/fsnotify/fsnotify/internal/debug_darwin.go +15 -0
  128. package/govendor/github.com/fsnotify/fsnotify/internal/debug_dragonfly.go +15 -0
  129. package/govendor/github.com/fsnotify/fsnotify/internal/debug_freebsd.go +20 -0
  130. package/govendor/github.com/fsnotify/fsnotify/internal/debug_kqueue.go +32 -0
  131. package/govendor/github.com/fsnotify/fsnotify/internal/debug_linux.go +56 -0
  132. package/govendor/github.com/fsnotify/fsnotify/internal/debug_netbsd.go +15 -0
  133. package/govendor/github.com/fsnotify/fsnotify/internal/debug_openbsd.go +16 -0
  134. package/govendor/github.com/fsnotify/fsnotify/internal/debug_solaris.go +45 -0
  135. package/govendor/github.com/fsnotify/fsnotify/internal/debug_windows.go +40 -0
  136. package/govendor/github.com/fsnotify/fsnotify/internal/freebsd.go +20 -0
  137. package/govendor/github.com/fsnotify/fsnotify/internal/internal.go +2 -0
  138. package/govendor/github.com/fsnotify/fsnotify/internal/unix.go +20 -0
  139. package/govendor/github.com/fsnotify/fsnotify/internal/unix2.go +25 -0
  140. package/govendor/github.com/fsnotify/fsnotify/internal/windows.go +40 -0
  141. package/govendor/github.com/fsnotify/fsnotify/shared.go +64 -0
  142. package/govendor/github.com/fsnotify/fsnotify/staticcheck.conf +3 -0
  143. package/govendor/github.com/fsnotify/fsnotify/system_bsd.go +7 -0
  144. package/govendor/github.com/fsnotify/fsnotify/system_darwin.go +8 -0
  145. package/govendor/manifest.txt +3 -1
  146. package/package.json +1 -1
  147. package/types/typenative-npm.d.ts +72 -0
  148. package/types/typenative.d.ts +117 -1
@@ -0,0 +1,290 @@
1
+ package brotli
2
+
3
+ import (
4
+ "math"
5
+ "math/bits"
6
+ )
7
+
8
+ /* Copyright 2013 Google Inc. All Rights Reserved.
9
+
10
+ Distributed under MIT license.
11
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
12
+ */
13
+
14
+ /* Utilities for fast computation of logarithms. */
15
+
16
+ func log2FloorNonZero(n uint) uint32 {
17
+ return uint32(bits.Len(n)) - 1
18
+ }
19
+
20
+ /* A lookup table for small values of log2(int) to be used in entropy
21
+ computation.
22
+
23
+ ", ".join(["%.16ff" % x for x in [0.0]+[log2(x) for x in range(1, 256)]]) */
24
+ var kLog2Table = []float32{
25
+ 0.0000000000000000,
26
+ 0.0000000000000000,
27
+ 1.0000000000000000,
28
+ 1.5849625007211563,
29
+ 2.0000000000000000,
30
+ 2.3219280948873622,
31
+ 2.5849625007211561,
32
+ 2.8073549220576042,
33
+ 3.0000000000000000,
34
+ 3.1699250014423126,
35
+ 3.3219280948873626,
36
+ 3.4594316186372978,
37
+ 3.5849625007211565,
38
+ 3.7004397181410922,
39
+ 3.8073549220576037,
40
+ 3.9068905956085187,
41
+ 4.0000000000000000,
42
+ 4.0874628412503400,
43
+ 4.1699250014423122,
44
+ 4.2479275134435852,
45
+ 4.3219280948873626,
46
+ 4.3923174227787607,
47
+ 4.4594316186372973,
48
+ 4.5235619560570131,
49
+ 4.5849625007211570,
50
+ 4.6438561897747244,
51
+ 4.7004397181410926,
52
+ 4.7548875021634691,
53
+ 4.8073549220576037,
54
+ 4.8579809951275728,
55
+ 4.9068905956085187,
56
+ 4.9541963103868758,
57
+ 5.0000000000000000,
58
+ 5.0443941193584534,
59
+ 5.0874628412503400,
60
+ 5.1292830169449664,
61
+ 5.1699250014423122,
62
+ 5.2094533656289501,
63
+ 5.2479275134435852,
64
+ 5.2854022188622487,
65
+ 5.3219280948873626,
66
+ 5.3575520046180838,
67
+ 5.3923174227787607,
68
+ 5.4262647547020979,
69
+ 5.4594316186372973,
70
+ 5.4918530963296748,
71
+ 5.5235619560570131,
72
+ 5.5545888516776376,
73
+ 5.5849625007211570,
74
+ 5.6147098441152083,
75
+ 5.6438561897747244,
76
+ 5.6724253419714961,
77
+ 5.7004397181410926,
78
+ 5.7279204545631996,
79
+ 5.7548875021634691,
80
+ 5.7813597135246599,
81
+ 5.8073549220576046,
82
+ 5.8328900141647422,
83
+ 5.8579809951275719,
84
+ 5.8826430493618416,
85
+ 5.9068905956085187,
86
+ 5.9307373375628867,
87
+ 5.9541963103868758,
88
+ 5.9772799234999168,
89
+ 6.0000000000000000,
90
+ 6.0223678130284544,
91
+ 6.0443941193584534,
92
+ 6.0660891904577721,
93
+ 6.0874628412503400,
94
+ 6.1085244567781700,
95
+ 6.1292830169449672,
96
+ 6.1497471195046822,
97
+ 6.1699250014423122,
98
+ 6.1898245588800176,
99
+ 6.2094533656289510,
100
+ 6.2288186904958804,
101
+ 6.2479275134435861,
102
+ 6.2667865406949019,
103
+ 6.2854022188622487,
104
+ 6.3037807481771031,
105
+ 6.3219280948873617,
106
+ 6.3398500028846252,
107
+ 6.3575520046180847,
108
+ 6.3750394313469254,
109
+ 6.3923174227787598,
110
+ 6.4093909361377026,
111
+ 6.4262647547020979,
112
+ 6.4429434958487288,
113
+ 6.4594316186372982,
114
+ 6.4757334309663976,
115
+ 6.4918530963296748,
116
+ 6.5077946401986964,
117
+ 6.5235619560570131,
118
+ 6.5391588111080319,
119
+ 6.5545888516776376,
120
+ 6.5698556083309478,
121
+ 6.5849625007211561,
122
+ 6.5999128421871278,
123
+ 6.6147098441152092,
124
+ 6.6293566200796095,
125
+ 6.6438561897747253,
126
+ 6.6582114827517955,
127
+ 6.6724253419714952,
128
+ 6.6865005271832185,
129
+ 6.7004397181410917,
130
+ 6.7142455176661224,
131
+ 6.7279204545631988,
132
+ 6.7414669864011465,
133
+ 6.7548875021634691,
134
+ 6.7681843247769260,
135
+ 6.7813597135246599,
136
+ 6.7944158663501062,
137
+ 6.8073549220576037,
138
+ 6.8201789624151887,
139
+ 6.8328900141647422,
140
+ 6.8454900509443757,
141
+ 6.8579809951275719,
142
+ 6.8703647195834048,
143
+ 6.8826430493618416,
144
+ 6.8948177633079437,
145
+ 6.9068905956085187,
146
+ 6.9188632372745955,
147
+ 6.9307373375628867,
148
+ 6.9425145053392399,
149
+ 6.9541963103868758,
150
+ 6.9657842846620879,
151
+ 6.9772799234999168,
152
+ 6.9886846867721664,
153
+ 7.0000000000000000,
154
+ 7.0112272554232540,
155
+ 7.0223678130284544,
156
+ 7.0334230015374501,
157
+ 7.0443941193584534,
158
+ 7.0552824355011898,
159
+ 7.0660891904577721,
160
+ 7.0768155970508317,
161
+ 7.0874628412503400,
162
+ 7.0980320829605272,
163
+ 7.1085244567781700,
164
+ 7.1189410727235076,
165
+ 7.1292830169449664,
166
+ 7.1395513523987937,
167
+ 7.1497471195046822,
168
+ 7.1598713367783891,
169
+ 7.1699250014423130,
170
+ 7.1799090900149345,
171
+ 7.1898245588800176,
172
+ 7.1996723448363644,
173
+ 7.2094533656289492,
174
+ 7.2191685204621621,
175
+ 7.2288186904958804,
176
+ 7.2384047393250794,
177
+ 7.2479275134435861,
178
+ 7.2573878426926521,
179
+ 7.2667865406949019,
180
+ 7.2761244052742384,
181
+ 7.2854022188622487,
182
+ 7.2946207488916270,
183
+ 7.3037807481771031,
184
+ 7.3128829552843557,
185
+ 7.3219280948873617,
186
+ 7.3309168781146177,
187
+ 7.3398500028846243,
188
+ 7.3487281542310781,
189
+ 7.3575520046180847,
190
+ 7.3663222142458151,
191
+ 7.3750394313469254,
192
+ 7.3837042924740528,
193
+ 7.3923174227787607,
194
+ 7.4008794362821844,
195
+ 7.4093909361377026,
196
+ 7.4178525148858991,
197
+ 7.4262647547020979,
198
+ 7.4346282276367255,
199
+ 7.4429434958487288,
200
+ 7.4512111118323299,
201
+ 7.4594316186372973,
202
+ 7.4676055500829976,
203
+ 7.4757334309663976,
204
+ 7.4838157772642564,
205
+ 7.4918530963296748,
206
+ 7.4998458870832057,
207
+ 7.5077946401986964,
208
+ 7.5156998382840436,
209
+ 7.5235619560570131,
210
+ 7.5313814605163119,
211
+ 7.5391588111080319,
212
+ 7.5468944598876373,
213
+ 7.5545888516776376,
214
+ 7.5622424242210728,
215
+ 7.5698556083309478,
216
+ 7.5774288280357487,
217
+ 7.5849625007211561,
218
+ 7.5924570372680806,
219
+ 7.5999128421871278,
220
+ 7.6073303137496113,
221
+ 7.6147098441152075,
222
+ 7.6220518194563764,
223
+ 7.6293566200796095,
224
+ 7.6366246205436488,
225
+ 7.6438561897747244,
226
+ 7.6510516911789290,
227
+ 7.6582114827517955,
228
+ 7.6653359171851765,
229
+ 7.6724253419714952,
230
+ 7.6794800995054464,
231
+ 7.6865005271832185,
232
+ 7.6934869574993252,
233
+ 7.7004397181410926,
234
+ 7.7073591320808825,
235
+ 7.7142455176661224,
236
+ 7.7210991887071856,
237
+ 7.7279204545631996,
238
+ 7.7347096202258392,
239
+ 7.7414669864011465,
240
+ 7.7481928495894596,
241
+ 7.7548875021634691,
242
+ 7.7615512324444795,
243
+ 7.7681843247769260,
244
+ 7.7747870596011737,
245
+ 7.7813597135246608,
246
+ 7.7879025593914317,
247
+ 7.7944158663501062,
248
+ 7.8008998999203047,
249
+ 7.8073549220576037,
250
+ 7.8137811912170374,
251
+ 7.8201789624151887,
252
+ 7.8265484872909159,
253
+ 7.8328900141647422,
254
+ 7.8392037880969445,
255
+ 7.8454900509443757,
256
+ 7.8517490414160571,
257
+ 7.8579809951275719,
258
+ 7.8641861446542798,
259
+ 7.8703647195834048,
260
+ 7.8765169465650002,
261
+ 7.8826430493618425,
262
+ 7.8887432488982601,
263
+ 7.8948177633079446,
264
+ 7.9008668079807496,
265
+ 7.9068905956085187,
266
+ 7.9128893362299619,
267
+ 7.9188632372745955,
268
+ 7.9248125036057813,
269
+ 7.9307373375628867,
270
+ 7.9366379390025719,
271
+ 7.9425145053392399,
272
+ 7.9483672315846778,
273
+ 7.9541963103868758,
274
+ 7.9600019320680806,
275
+ 7.9657842846620870,
276
+ 7.9715435539507720,
277
+ 7.9772799234999168,
278
+ 7.9829935746943104,
279
+ 7.9886846867721664,
280
+ 7.9943534368588578,
281
+ }
282
+
283
+ /* Faster logarithm for small integers, with the property of log2(0) == 0. */
284
+ func fastLog2(v uint) float64 {
285
+ if v < uint(len(kLog2Table)) {
286
+ return float64(kLog2Table[v])
287
+ }
288
+
289
+ return math.Log2(float64(v))
290
+ }
@@ -0,0 +1,45 @@
1
+ package brotli
2
+
3
+ import (
4
+ "encoding/binary"
5
+ "math/bits"
6
+ "runtime"
7
+ )
8
+
9
+ /* Copyright 2010 Google Inc. All Rights Reserved.
10
+
11
+ Distributed under MIT license.
12
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
13
+ */
14
+
15
+ /* Function to find maximal matching prefixes of strings. */
16
+ func findMatchLengthWithLimit(s1 []byte, s2 []byte, limit uint) uint {
17
+ var matched uint = 0
18
+ _, _ = s1[limit-1], s2[limit-1] // bounds check
19
+ switch runtime.GOARCH {
20
+ case "amd64", "arm64":
21
+ // Compare 8 bytes at at time.
22
+ for matched+8 <= limit {
23
+ w1 := binary.LittleEndian.Uint64(s1[matched:])
24
+ w2 := binary.LittleEndian.Uint64(s2[matched:])
25
+ if w1 != w2 {
26
+ return matched + uint(bits.TrailingZeros64(w1^w2)>>3)
27
+ }
28
+ matched += 8
29
+ }
30
+ case "386":
31
+ // Compare 4 bytes at at time.
32
+ for matched+4 <= limit {
33
+ w1 := binary.LittleEndian.Uint32(s1[matched:])
34
+ w2 := binary.LittleEndian.Uint32(s2[matched:])
35
+ if w1 != w2 {
36
+ return matched + uint(bits.TrailingZeros32(w1^w2)>>3)
37
+ }
38
+ matched += 4
39
+ }
40
+ }
41
+ for matched < limit && s1[matched] == s2[matched] {
42
+ matched++
43
+ }
44
+ return matched
45
+ }
@@ -0,0 +1,3 @@
1
+ module github.com/andybalholm/brotli
2
+
3
+ go 1.22
@@ -0,0 +1,287 @@
1
+ package brotli
2
+
3
+ import "encoding/binary"
4
+
5
+ /* Copyright 2016 Google Inc. All Rights Reserved.
6
+
7
+ Distributed under MIT license.
8
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
9
+ */
10
+
11
+ func (*h10) HashTypeLength() uint {
12
+ return 4
13
+ }
14
+
15
+ func (*h10) StoreLookahead() uint {
16
+ return 128
17
+ }
18
+
19
+ func hashBytesH10(data []byte) uint32 {
20
+ var h uint32 = binary.LittleEndian.Uint32(data) * kHashMul32
21
+
22
+ /* The higher bits contain more mixture from the multiplication,
23
+ so we take our results from there. */
24
+ return h >> (32 - 17)
25
+ }
26
+
27
+ /* A (forgetful) hash table where each hash bucket contains a binary tree of
28
+ sequences whose first 4 bytes share the same hash code.
29
+ Each sequence is 128 long and is identified by its starting
30
+ position in the input data. The binary tree is sorted by the lexicographic
31
+ order of the sequences, and it is also a max-heap with respect to the
32
+ starting positions. */
33
+ type h10 struct {
34
+ hasherCommon
35
+ window_mask_ uint
36
+ buckets_ [1 << 17]uint32
37
+ invalid_pos_ uint32
38
+ forest []uint32
39
+ }
40
+
41
+ func (h *h10) Initialize(params *encoderParams) {
42
+ h.window_mask_ = (1 << params.lgwin) - 1
43
+ h.invalid_pos_ = uint32(0 - h.window_mask_)
44
+ var num_nodes uint = uint(1) << params.lgwin
45
+ h.forest = make([]uint32, 2*num_nodes)
46
+ }
47
+
48
+ func (h *h10) Prepare(one_shot bool, input_size uint, data []byte) {
49
+ var invalid_pos uint32 = h.invalid_pos_
50
+ var i uint32
51
+ for i = 0; i < 1<<17; i++ {
52
+ h.buckets_[i] = invalid_pos
53
+ }
54
+ }
55
+
56
+ func leftChildIndexH10(self *h10, pos uint) uint {
57
+ return 2 * (pos & self.window_mask_)
58
+ }
59
+
60
+ func rightChildIndexH10(self *h10, pos uint) uint {
61
+ return 2*(pos&self.window_mask_) + 1
62
+ }
63
+
64
+ /* Stores the hash of the next 4 bytes and in a single tree-traversal, the
65
+ hash bucket's binary tree is searched for matches and is re-rooted at the
66
+ current position.
67
+
68
+ If less than 128 data is available, the hash bucket of the
69
+ current position is searched for matches, but the state of the hash table
70
+ is not changed, since we can not know the final sorting order of the
71
+ current (incomplete) sequence.
72
+
73
+ This function must be called with increasing cur_ix positions. */
74
+ func storeAndFindMatchesH10(self *h10, data []byte, cur_ix uint, ring_buffer_mask uint, max_length uint, max_backward uint, best_len *uint, matches []backwardMatch) []backwardMatch {
75
+ var cur_ix_masked uint = cur_ix & ring_buffer_mask
76
+ var max_comp_len uint = brotli_min_size_t(max_length, 128)
77
+ var should_reroot_tree bool = (max_length >= 128)
78
+ var key uint32 = hashBytesH10(data[cur_ix_masked:])
79
+ var forest []uint32 = self.forest
80
+ var prev_ix uint = uint(self.buckets_[key])
81
+ var node_left uint = leftChildIndexH10(self, cur_ix)
82
+ var node_right uint = rightChildIndexH10(self, cur_ix)
83
+ var best_len_left uint = 0
84
+ var best_len_right uint = 0
85
+ var depth_remaining uint
86
+ /* The forest index of the rightmost node of the left subtree of the new
87
+ root, updated as we traverse and re-root the tree of the hash bucket. */
88
+
89
+ /* The forest index of the leftmost node of the right subtree of the new
90
+ root, updated as we traverse and re-root the tree of the hash bucket. */
91
+
92
+ /* The match length of the rightmost node of the left subtree of the new
93
+ root, updated as we traverse and re-root the tree of the hash bucket. */
94
+
95
+ /* The match length of the leftmost node of the right subtree of the new
96
+ root, updated as we traverse and re-root the tree of the hash bucket. */
97
+ if should_reroot_tree {
98
+ self.buckets_[key] = uint32(cur_ix)
99
+ }
100
+
101
+ for depth_remaining = 64; ; depth_remaining-- {
102
+ var backward uint = cur_ix - prev_ix
103
+ var prev_ix_masked uint = prev_ix & ring_buffer_mask
104
+ if backward == 0 || backward > max_backward || depth_remaining == 0 {
105
+ if should_reroot_tree {
106
+ forest[node_left] = self.invalid_pos_
107
+ forest[node_right] = self.invalid_pos_
108
+ }
109
+
110
+ break
111
+ }
112
+ {
113
+ var cur_len uint = brotli_min_size_t(best_len_left, best_len_right)
114
+ var len uint
115
+ assert(cur_len <= 128)
116
+ len = cur_len + findMatchLengthWithLimit(data[cur_ix_masked+cur_len:], data[prev_ix_masked+cur_len:], max_length-cur_len)
117
+ if matches != nil && len > *best_len {
118
+ *best_len = uint(len)
119
+ initBackwardMatch(&matches[0], backward, uint(len))
120
+ matches = matches[1:]
121
+ }
122
+
123
+ if len >= max_comp_len {
124
+ if should_reroot_tree {
125
+ forest[node_left] = forest[leftChildIndexH10(self, prev_ix)]
126
+ forest[node_right] = forest[rightChildIndexH10(self, prev_ix)]
127
+ }
128
+
129
+ break
130
+ }
131
+
132
+ if data[cur_ix_masked+len] > data[prev_ix_masked+len] {
133
+ best_len_left = uint(len)
134
+ if should_reroot_tree {
135
+ forest[node_left] = uint32(prev_ix)
136
+ }
137
+
138
+ node_left = rightChildIndexH10(self, prev_ix)
139
+ prev_ix = uint(forest[node_left])
140
+ } else {
141
+ best_len_right = uint(len)
142
+ if should_reroot_tree {
143
+ forest[node_right] = uint32(prev_ix)
144
+ }
145
+
146
+ node_right = leftChildIndexH10(self, prev_ix)
147
+ prev_ix = uint(forest[node_right])
148
+ }
149
+ }
150
+ }
151
+
152
+ return matches
153
+ }
154
+
155
+ /* Finds all backward matches of &data[cur_ix & ring_buffer_mask] up to the
156
+ length of max_length and stores the position cur_ix in the hash table.
157
+
158
+ Sets *num_matches to the number of matches found, and stores the found
159
+ matches in matches[0] to matches[*num_matches - 1]. The matches will be
160
+ sorted by strictly increasing length and (non-strictly) increasing
161
+ distance. */
162
+ func findAllMatchesH10(handle *h10, dictionary *encoderDictionary, data []byte, ring_buffer_mask uint, cur_ix uint, max_length uint, max_backward uint, gap uint, params *encoderParams, matches []backwardMatch) uint {
163
+ var orig_matches []backwardMatch = matches
164
+ var cur_ix_masked uint = cur_ix & ring_buffer_mask
165
+ var best_len uint = 1
166
+ var short_match_max_backward uint
167
+ if params.quality != hqZopflificationQuality {
168
+ short_match_max_backward = 16
169
+ } else {
170
+ short_match_max_backward = 64
171
+ }
172
+ var stop uint = cur_ix - short_match_max_backward
173
+ var dict_matches [maxStaticDictionaryMatchLen + 1]uint32
174
+ var i uint
175
+ if cur_ix < short_match_max_backward {
176
+ stop = 0
177
+ }
178
+ for i = cur_ix - 1; i > stop && best_len <= 2; i-- {
179
+ var prev_ix uint = i
180
+ var backward uint = cur_ix - prev_ix
181
+ if backward > max_backward {
182
+ break
183
+ }
184
+
185
+ prev_ix &= ring_buffer_mask
186
+ if data[cur_ix_masked] != data[prev_ix] || data[cur_ix_masked+1] != data[prev_ix+1] {
187
+ continue
188
+ }
189
+ {
190
+ var len uint = findMatchLengthWithLimit(data[prev_ix:], data[cur_ix_masked:], max_length)
191
+ if len > best_len {
192
+ best_len = uint(len)
193
+ initBackwardMatch(&matches[0], backward, uint(len))
194
+ matches = matches[1:]
195
+ }
196
+ }
197
+ }
198
+
199
+ if best_len < max_length {
200
+ matches = storeAndFindMatchesH10(handle, data, cur_ix, ring_buffer_mask, max_length, max_backward, &best_len, matches)
201
+ }
202
+
203
+ for i = 0; i <= maxStaticDictionaryMatchLen; i++ {
204
+ dict_matches[i] = kInvalidMatch
205
+ }
206
+ {
207
+ var minlen uint = brotli_max_size_t(4, best_len+1)
208
+ if findAllStaticDictionaryMatches(dictionary, data[cur_ix_masked:], minlen, max_length, dict_matches[0:]) {
209
+ var maxlen uint = brotli_min_size_t(maxStaticDictionaryMatchLen, max_length)
210
+ var l uint
211
+ for l = minlen; l <= maxlen; l++ {
212
+ var dict_id uint32 = dict_matches[l]
213
+ if dict_id < kInvalidMatch {
214
+ var distance uint = max_backward + gap + uint(dict_id>>5) + 1
215
+ if distance <= params.dist.max_distance {
216
+ initDictionaryBackwardMatch(&matches[0], distance, l, uint(dict_id&31))
217
+ matches = matches[1:]
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ return uint(-cap(matches) + cap(orig_matches))
225
+ }
226
+
227
+ /* Stores the hash of the next 4 bytes and re-roots the binary tree at the
228
+ current sequence, without returning any matches.
229
+ REQUIRES: ix + 128 <= end-of-current-block */
230
+ func (h *h10) Store(data []byte, mask uint, ix uint) {
231
+ var max_backward uint = h.window_mask_ - windowGap + 1
232
+ /* Maximum distance is window size - 16, see section 9.1. of the spec. */
233
+ storeAndFindMatchesH10(h, data, ix, mask, 128, max_backward, nil, nil)
234
+ }
235
+
236
+ func (h *h10) StoreRange(data []byte, mask uint, ix_start uint, ix_end uint) {
237
+ var i uint = ix_start
238
+ var j uint = ix_start
239
+ if ix_start+63 <= ix_end {
240
+ i = ix_end - 63
241
+ }
242
+
243
+ if ix_start+512 <= i {
244
+ for ; j < i; j += 8 {
245
+ h.Store(data, mask, j)
246
+ }
247
+ }
248
+
249
+ for ; i < ix_end; i++ {
250
+ h.Store(data, mask, i)
251
+ }
252
+ }
253
+
254
+ func (h *h10) StitchToPreviousBlock(num_bytes uint, position uint, ringbuffer []byte, ringbuffer_mask uint) {
255
+ if num_bytes >= h.HashTypeLength()-1 && position >= 128 {
256
+ var i_start uint = position - 128 + 1
257
+ var i_end uint = brotli_min_size_t(position, i_start+num_bytes)
258
+ /* Store the last `128 - 1` positions in the hasher.
259
+ These could not be calculated before, since they require knowledge
260
+ of both the previous and the current block. */
261
+
262
+ var i uint
263
+ for i = i_start; i < i_end; i++ {
264
+ /* Maximum distance is window size - 16, see section 9.1. of the spec.
265
+ Furthermore, we have to make sure that we don't look further back
266
+ from the start of the next block than the window size, otherwise we
267
+ could access already overwritten areas of the ring-buffer. */
268
+ var max_backward uint = h.window_mask_ - brotli_max_size_t(windowGap-1, position-i)
269
+
270
+ /* We know that i + 128 <= position + num_bytes, i.e. the
271
+ end of the current block and that we have at least
272
+ 128 tail in the ring-buffer. */
273
+ storeAndFindMatchesH10(h, ringbuffer, i, ringbuffer_mask, 128, max_backward, nil, nil)
274
+ }
275
+ }
276
+ }
277
+
278
+ /* MAX_NUM_MATCHES == 64 + MAX_TREE_SEARCH_DEPTH */
279
+ const maxNumMatchesH10 = 128
280
+
281
+ func (*h10) FindLongestMatch(dictionary *encoderDictionary, data []byte, ring_buffer_mask uint, distance_cache []int, cur_ix uint, max_length uint, max_backward uint, gap uint, max_distance uint, out *hasherSearchResult) {
282
+ panic("unimplemented")
283
+ }
284
+
285
+ func (*h10) PrepareDistanceCache(distance_cache []int) {
286
+ panic("unimplemented")
287
+ }