context.go 13 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176
  1. package brotli
  2. /* Lookup table to map the previous two bytes to a context id.
  3. There are four different context modeling modes defined here:
  4. contextLSB6: context id is the least significant 6 bits of the last byte,
  5. contextMSB6: context id is the most significant 6 bits of the last byte,
  6. contextUTF8: second-order context model tuned for UTF8-encoded text,
  7. contextSigned: second-order context model tuned for signed integers.
  8. If |p1| and |p2| are the previous two bytes, and |mode| is current context
  9. mode, we calculate the context as:
  10. context = ContextLut(mode)[p1] | ContextLut(mode)[p2 + 256].
  11. For contextUTF8 mode, if the previous two bytes are ASCII characters
  12. (i.e. < 128), this will be equivalent to
  13. context = 4 * context1(p1) + context2(p2),
  14. where context1 is based on the previous byte in the following way:
  15. 0 : non-ASCII control
  16. 1 : \t, \n, \r
  17. 2 : space
  18. 3 : other punctuation
  19. 4 : " '
  20. 5 : %
  21. 6 : ( < [ {
  22. 7 : ) > ] }
  23. 8 : , ; :
  24. 9 : .
  25. 10 : =
  26. 11 : number
  27. 12 : upper-case vowel
  28. 13 : upper-case consonant
  29. 14 : lower-case vowel
  30. 15 : lower-case consonant
  31. and context2 is based on the second last byte:
  32. 0 : control, space
  33. 1 : punctuation
  34. 2 : upper-case letter, number
  35. 3 : lower-case letter
  36. If the last byte is ASCII, and the second last byte is not (in a valid UTF8
  37. stream it will be a continuation byte, value between 128 and 191), the
  38. context is the same as if the second last byte was an ASCII control or space.
  39. If the last byte is a UTF8 lead byte (value >= 192), then the next byte will
  40. be a continuation byte and the context id is 2 or 3 depending on the LSB of
  41. the last byte and to a lesser extent on the second last byte if it is ASCII.
  42. If the last byte is a UTF8 continuation byte, the second last byte can be:
  43. - continuation byte: the next byte is probably ASCII or lead byte (assuming
  44. 4-byte UTF8 characters are rare) and the context id is 0 or 1.
  45. - lead byte (192 - 207): next byte is ASCII or lead byte, context is 0 or 1
  46. - lead byte (208 - 255): next byte is continuation byte, context is 2 or 3
  47. The possible value combinations of the previous two bytes, the range of
  48. context ids and the type of the next byte is summarized in the table below:
  49. |--------\-----------------------------------------------------------------|
  50. | \ Last byte |
  51. | Second \---------------------------------------------------------------|
  52. | last byte \ ASCII | cont. byte | lead byte |
  53. | \ (0-127) | (128-191) | (192-) |
  54. |=============|===================|=====================|==================|
  55. | ASCII | next: ASCII/lead | not valid | next: cont. |
  56. | (0-127) | context: 4 - 63 | | context: 2 - 3 |
  57. |-------------|-------------------|---------------------|------------------|
  58. | cont. byte | next: ASCII/lead | next: ASCII/lead | next: cont. |
  59. | (128-191) | context: 4 - 63 | context: 0 - 1 | context: 2 - 3 |
  60. |-------------|-------------------|---------------------|------------------|
  61. | lead byte | not valid | next: ASCII/lead | not valid |
  62. | (192-207) | | context: 0 - 1 | |
  63. |-------------|-------------------|---------------------|------------------|
  64. | lead byte | not valid | next: cont. | not valid |
  65. | (208-) | | context: 2 - 3 | |
  66. |-------------|-------------------|---------------------|------------------|
  67. */
  68. const (
  69. contextLSB6 = 0
  70. contextMSB6 = 1
  71. contextUTF8 = 2
  72. contextSigned = 3
  73. )
  74. /* Common context lookup table for all context modes. */
  75. var kContextLookup = [2048]byte{
  76. /* CONTEXT_LSB6, last byte. */
  77. 0,
  78. 1,
  79. 2,
  80. 3,
  81. 4,
  82. 5,
  83. 6,
  84. 7,
  85. 8,
  86. 9,
  87. 10,
  88. 11,
  89. 12,
  90. 13,
  91. 14,
  92. 15,
  93. 16,
  94. 17,
  95. 18,
  96. 19,
  97. 20,
  98. 21,
  99. 22,
  100. 23,
  101. 24,
  102. 25,
  103. 26,
  104. 27,
  105. 28,
  106. 29,
  107. 30,
  108. 31,
  109. 32,
  110. 33,
  111. 34,
  112. 35,
  113. 36,
  114. 37,
  115. 38,
  116. 39,
  117. 40,
  118. 41,
  119. 42,
  120. 43,
  121. 44,
  122. 45,
  123. 46,
  124. 47,
  125. 48,
  126. 49,
  127. 50,
  128. 51,
  129. 52,
  130. 53,
  131. 54,
  132. 55,
  133. 56,
  134. 57,
  135. 58,
  136. 59,
  137. 60,
  138. 61,
  139. 62,
  140. 63,
  141. 0,
  142. 1,
  143. 2,
  144. 3,
  145. 4,
  146. 5,
  147. 6,
  148. 7,
  149. 8,
  150. 9,
  151. 10,
  152. 11,
  153. 12,
  154. 13,
  155. 14,
  156. 15,
  157. 16,
  158. 17,
  159. 18,
  160. 19,
  161. 20,
  162. 21,
  163. 22,
  164. 23,
  165. 24,
  166. 25,
  167. 26,
  168. 27,
  169. 28,
  170. 29,
  171. 30,
  172. 31,
  173. 32,
  174. 33,
  175. 34,
  176. 35,
  177. 36,
  178. 37,
  179. 38,
  180. 39,
  181. 40,
  182. 41,
  183. 42,
  184. 43,
  185. 44,
  186. 45,
  187. 46,
  188. 47,
  189. 48,
  190. 49,
  191. 50,
  192. 51,
  193. 52,
  194. 53,
  195. 54,
  196. 55,
  197. 56,
  198. 57,
  199. 58,
  200. 59,
  201. 60,
  202. 61,
  203. 62,
  204. 63,
  205. 0,
  206. 1,
  207. 2,
  208. 3,
  209. 4,
  210. 5,
  211. 6,
  212. 7,
  213. 8,
  214. 9,
  215. 10,
  216. 11,
  217. 12,
  218. 13,
  219. 14,
  220. 15,
  221. 16,
  222. 17,
  223. 18,
  224. 19,
  225. 20,
  226. 21,
  227. 22,
  228. 23,
  229. 24,
  230. 25,
  231. 26,
  232. 27,
  233. 28,
  234. 29,
  235. 30,
  236. 31,
  237. 32,
  238. 33,
  239. 34,
  240. 35,
  241. 36,
  242. 37,
  243. 38,
  244. 39,
  245. 40,
  246. 41,
  247. 42,
  248. 43,
  249. 44,
  250. 45,
  251. 46,
  252. 47,
  253. 48,
  254. 49,
  255. 50,
  256. 51,
  257. 52,
  258. 53,
  259. 54,
  260. 55,
  261. 56,
  262. 57,
  263. 58,
  264. 59,
  265. 60,
  266. 61,
  267. 62,
  268. 63,
  269. 0,
  270. 1,
  271. 2,
  272. 3,
  273. 4,
  274. 5,
  275. 6,
  276. 7,
  277. 8,
  278. 9,
  279. 10,
  280. 11,
  281. 12,
  282. 13,
  283. 14,
  284. 15,
  285. 16,
  286. 17,
  287. 18,
  288. 19,
  289. 20,
  290. 21,
  291. 22,
  292. 23,
  293. 24,
  294. 25,
  295. 26,
  296. 27,
  297. 28,
  298. 29,
  299. 30,
  300. 31,
  301. 32,
  302. 33,
  303. 34,
  304. 35,
  305. 36,
  306. 37,
  307. 38,
  308. 39,
  309. 40,
  310. 41,
  311. 42,
  312. 43,
  313. 44,
  314. 45,
  315. 46,
  316. 47,
  317. 48,
  318. 49,
  319. 50,
  320. 51,
  321. 52,
  322. 53,
  323. 54,
  324. 55,
  325. 56,
  326. 57,
  327. 58,
  328. 59,
  329. 60,
  330. 61,
  331. 62,
  332. 63,
  333. /* CONTEXT_LSB6, second last byte, */
  334. 0,
  335. 0,
  336. 0,
  337. 0,
  338. 0,
  339. 0,
  340. 0,
  341. 0,
  342. 0,
  343. 0,
  344. 0,
  345. 0,
  346. 0,
  347. 0,
  348. 0,
  349. 0,
  350. 0,
  351. 0,
  352. 0,
  353. 0,
  354. 0,
  355. 0,
  356. 0,
  357. 0,
  358. 0,
  359. 0,
  360. 0,
  361. 0,
  362. 0,
  363. 0,
  364. 0,
  365. 0,
  366. 0,
  367. 0,
  368. 0,
  369. 0,
  370. 0,
  371. 0,
  372. 0,
  373. 0,
  374. 0,
  375. 0,
  376. 0,
  377. 0,
  378. 0,
  379. 0,
  380. 0,
  381. 0,
  382. 0,
  383. 0,
  384. 0,
  385. 0,
  386. 0,
  387. 0,
  388. 0,
  389. 0,
  390. 0,
  391. 0,
  392. 0,
  393. 0,
  394. 0,
  395. 0,
  396. 0,
  397. 0,
  398. 0,
  399. 0,
  400. 0,
  401. 0,
  402. 0,
  403. 0,
  404. 0,
  405. 0,
  406. 0,
  407. 0,
  408. 0,
  409. 0,
  410. 0,
  411. 0,
  412. 0,
  413. 0,
  414. 0,
  415. 0,
  416. 0,
  417. 0,
  418. 0,
  419. 0,
  420. 0,
  421. 0,
  422. 0,
  423. 0,
  424. 0,
  425. 0,
  426. 0,
  427. 0,
  428. 0,
  429. 0,
  430. 0,
  431. 0,
  432. 0,
  433. 0,
  434. 0,
  435. 0,
  436. 0,
  437. 0,
  438. 0,
  439. 0,
  440. 0,
  441. 0,
  442. 0,
  443. 0,
  444. 0,
  445. 0,
  446. 0,
  447. 0,
  448. 0,
  449. 0,
  450. 0,
  451. 0,
  452. 0,
  453. 0,
  454. 0,
  455. 0,
  456. 0,
  457. 0,
  458. 0,
  459. 0,
  460. 0,
  461. 0,
  462. 0,
  463. 0,
  464. 0,
  465. 0,
  466. 0,
  467. 0,
  468. 0,
  469. 0,
  470. 0,
  471. 0,
  472. 0,
  473. 0,
  474. 0,
  475. 0,
  476. 0,
  477. 0,
  478. 0,
  479. 0,
  480. 0,
  481. 0,
  482. 0,
  483. 0,
  484. 0,
  485. 0,
  486. 0,
  487. 0,
  488. 0,
  489. 0,
  490. 0,
  491. 0,
  492. 0,
  493. 0,
  494. 0,
  495. 0,
  496. 0,
  497. 0,
  498. 0,
  499. 0,
  500. 0,
  501. 0,
  502. 0,
  503. 0,
  504. 0,
  505. 0,
  506. 0,
  507. 0,
  508. 0,
  509. 0,
  510. 0,
  511. 0,
  512. 0,
  513. 0,
  514. 0,
  515. 0,
  516. 0,
  517. 0,
  518. 0,
  519. 0,
  520. 0,
  521. 0,
  522. 0,
  523. 0,
  524. 0,
  525. 0,
  526. 0,
  527. 0,
  528. 0,
  529. 0,
  530. 0,
  531. 0,
  532. 0,
  533. 0,
  534. 0,
  535. 0,
  536. 0,
  537. 0,
  538. 0,
  539. 0,
  540. 0,
  541. 0,
  542. 0,
  543. 0,
  544. 0,
  545. 0,
  546. 0,
  547. 0,
  548. 0,
  549. 0,
  550. 0,
  551. 0,
  552. 0,
  553. 0,
  554. 0,
  555. 0,
  556. 0,
  557. 0,
  558. 0,
  559. 0,
  560. 0,
  561. 0,
  562. 0,
  563. 0,
  564. 0,
  565. 0,
  566. 0,
  567. 0,
  568. 0,
  569. 0,
  570. 0,
  571. 0,
  572. 0,
  573. 0,
  574. 0,
  575. 0,
  576. 0,
  577. 0,
  578. 0,
  579. 0,
  580. 0,
  581. 0,
  582. 0,
  583. 0,
  584. 0,
  585. 0,
  586. 0,
  587. 0,
  588. 0,
  589. 0,
  590. /* CONTEXT_MSB6, last byte. */
  591. 0,
  592. 0,
  593. 0,
  594. 0,
  595. 1,
  596. 1,
  597. 1,
  598. 1,
  599. 2,
  600. 2,
  601. 2,
  602. 2,
  603. 3,
  604. 3,
  605. 3,
  606. 3,
  607. 4,
  608. 4,
  609. 4,
  610. 4,
  611. 5,
  612. 5,
  613. 5,
  614. 5,
  615. 6,
  616. 6,
  617. 6,
  618. 6,
  619. 7,
  620. 7,
  621. 7,
  622. 7,
  623. 8,
  624. 8,
  625. 8,
  626. 8,
  627. 9,
  628. 9,
  629. 9,
  630. 9,
  631. 10,
  632. 10,
  633. 10,
  634. 10,
  635. 11,
  636. 11,
  637. 11,
  638. 11,
  639. 12,
  640. 12,
  641. 12,
  642. 12,
  643. 13,
  644. 13,
  645. 13,
  646. 13,
  647. 14,
  648. 14,
  649. 14,
  650. 14,
  651. 15,
  652. 15,
  653. 15,
  654. 15,
  655. 16,
  656. 16,
  657. 16,
  658. 16,
  659. 17,
  660. 17,
  661. 17,
  662. 17,
  663. 18,
  664. 18,
  665. 18,
  666. 18,
  667. 19,
  668. 19,
  669. 19,
  670. 19,
  671. 20,
  672. 20,
  673. 20,
  674. 20,
  675. 21,
  676. 21,
  677. 21,
  678. 21,
  679. 22,
  680. 22,
  681. 22,
  682. 22,
  683. 23,
  684. 23,
  685. 23,
  686. 23,
  687. 24,
  688. 24,
  689. 24,
  690. 24,
  691. 25,
  692. 25,
  693. 25,
  694. 25,
  695. 26,
  696. 26,
  697. 26,
  698. 26,
  699. 27,
  700. 27,
  701. 27,
  702. 27,
  703. 28,
  704. 28,
  705. 28,
  706. 28,
  707. 29,
  708. 29,
  709. 29,
  710. 29,
  711. 30,
  712. 30,
  713. 30,
  714. 30,
  715. 31,
  716. 31,
  717. 31,
  718. 31,
  719. 32,
  720. 32,
  721. 32,
  722. 32,
  723. 33,
  724. 33,
  725. 33,
  726. 33,
  727. 34,
  728. 34,
  729. 34,
  730. 34,
  731. 35,
  732. 35,
  733. 35,
  734. 35,
  735. 36,
  736. 36,
  737. 36,
  738. 36,
  739. 37,
  740. 37,
  741. 37,
  742. 37,
  743. 38,
  744. 38,
  745. 38,
  746. 38,
  747. 39,
  748. 39,
  749. 39,
  750. 39,
  751. 40,
  752. 40,
  753. 40,
  754. 40,
  755. 41,
  756. 41,
  757. 41,
  758. 41,
  759. 42,
  760. 42,
  761. 42,
  762. 42,
  763. 43,
  764. 43,
  765. 43,
  766. 43,
  767. 44,
  768. 44,
  769. 44,
  770. 44,
  771. 45,
  772. 45,
  773. 45,
  774. 45,
  775. 46,
  776. 46,
  777. 46,
  778. 46,
  779. 47,
  780. 47,
  781. 47,
  782. 47,
  783. 48,
  784. 48,
  785. 48,
  786. 48,
  787. 49,
  788. 49,
  789. 49,
  790. 49,
  791. 50,
  792. 50,
  793. 50,
  794. 50,
  795. 51,
  796. 51,
  797. 51,
  798. 51,
  799. 52,
  800. 52,
  801. 52,
  802. 52,
  803. 53,
  804. 53,
  805. 53,
  806. 53,
  807. 54,
  808. 54,
  809. 54,
  810. 54,
  811. 55,
  812. 55,
  813. 55,
  814. 55,
  815. 56,
  816. 56,
  817. 56,
  818. 56,
  819. 57,
  820. 57,
  821. 57,
  822. 57,
  823. 58,
  824. 58,
  825. 58,
  826. 58,
  827. 59,
  828. 59,
  829. 59,
  830. 59,
  831. 60,
  832. 60,
  833. 60,
  834. 60,
  835. 61,
  836. 61,
  837. 61,
  838. 61,
  839. 62,
  840. 62,
  841. 62,
  842. 62,
  843. 63,
  844. 63,
  845. 63,
  846. 63,
  847. /* CONTEXT_MSB6, second last byte, */
  848. 0,
  849. 0,
  850. 0,
  851. 0,
  852. 0,
  853. 0,
  854. 0,
  855. 0,
  856. 0,
  857. 0,
  858. 0,
  859. 0,
  860. 0,
  861. 0,
  862. 0,
  863. 0,
  864. 0,
  865. 0,
  866. 0,
  867. 0,
  868. 0,
  869. 0,
  870. 0,
  871. 0,
  872. 0,
  873. 0,
  874. 0,
  875. 0,
  876. 0,
  877. 0,
  878. 0,
  879. 0,
  880. 0,
  881. 0,
  882. 0,
  883. 0,
  884. 0,
  885. 0,
  886. 0,
  887. 0,
  888. 0,
  889. 0,
  890. 0,
  891. 0,
  892. 0,
  893. 0,
  894. 0,
  895. 0,
  896. 0,
  897. 0,
  898. 0,
  899. 0,
  900. 0,
  901. 0,
  902. 0,
  903. 0,
  904. 0,
  905. 0,
  906. 0,
  907. 0,
  908. 0,
  909. 0,
  910. 0,
  911. 0,
  912. 0,
  913. 0,
  914. 0,
  915. 0,
  916. 0,
  917. 0,
  918. 0,
  919. 0,
  920. 0,
  921. 0,
  922. 0,
  923. 0,
  924. 0,
  925. 0,
  926. 0,
  927. 0,
  928. 0,
  929. 0,
  930. 0,
  931. 0,
  932. 0,
  933. 0,
  934. 0,
  935. 0,
  936. 0,
  937. 0,
  938. 0,
  939. 0,
  940. 0,
  941. 0,
  942. 0,
  943. 0,
  944. 0,
  945. 0,
  946. 0,
  947. 0,
  948. 0,
  949. 0,
  950. 0,
  951. 0,
  952. 0,
  953. 0,
  954. 0,
  955. 0,
  956. 0,
  957. 0,
  958. 0,
  959. 0,
  960. 0,
  961. 0,
  962. 0,
  963. 0,
  964. 0,
  965. 0,
  966. 0,
  967. 0,
  968. 0,
  969. 0,
  970. 0,
  971. 0,
  972. 0,
  973. 0,
  974. 0,
  975. 0,
  976. 0,
  977. 0,
  978. 0,
  979. 0,
  980. 0,
  981. 0,
  982. 0,
  983. 0,
  984. 0,
  985. 0,
  986. 0,
  987. 0,
  988. 0,
  989. 0,
  990. 0,
  991. 0,
  992. 0,
  993. 0,
  994. 0,
  995. 0,
  996. 0,
  997. 0,
  998. 0,
  999. 0,
  1000. 0,
  1001. 0,
  1002. 0,
  1003. 0,
  1004. 0,
  1005. 0,
  1006. 0,
  1007. 0,
  1008. 0,
  1009. 0,
  1010. 0,
  1011. 0,
  1012. 0,
  1013. 0,
  1014. 0,
  1015. 0,
  1016. 0,
  1017. 0,
  1018. 0,
  1019. 0,
  1020. 0,
  1021. 0,
  1022. 0,
  1023. 0,
  1024. 0,
  1025. 0,
  1026. 0,
  1027. 0,
  1028. 0,
  1029. 0,
  1030. 0,
  1031. 0,
  1032. 0,
  1033. 0,
  1034. 0,
  1035. 0,
  1036. 0,
  1037. 0,
  1038. 0,
  1039. 0,
  1040. 0,
  1041. 0,
  1042. 0,
  1043. 0,
  1044. 0,
  1045. 0,
  1046. 0,
  1047. 0,
  1048. 0,
  1049. 0,
  1050. 0,
  1051. 0,
  1052. 0,
  1053. 0,
  1054. 0,
  1055. 0,
  1056. 0,
  1057. 0,
  1058. 0,
  1059. 0,
  1060. 0,
  1061. 0,
  1062. 0,
  1063. 0,
  1064. 0,
  1065. 0,
  1066. 0,
  1067. 0,
  1068. 0,
  1069. 0,
  1070. 0,
  1071. 0,
  1072. 0,
  1073. 0,
  1074. 0,
  1075. 0,
  1076. 0,
  1077. 0,
  1078. 0,
  1079. 0,
  1080. 0,
  1081. 0,
  1082. 0,
  1083. 0,
  1084. 0,
  1085. 0,
  1086. 0,
  1087. 0,
  1088. 0,
  1089. 0,
  1090. 0,
  1091. 0,
  1092. 0,
  1093. 0,
  1094. 0,
  1095. 0,
  1096. 0,
  1097. 0,
  1098. 0,
  1099. 0,
  1100. 0,
  1101. 0,
  1102. 0,
  1103. 0,
  1104. /* CONTEXT_UTF8, last byte. */
  1105. /* ASCII range. */
  1106. 0,
  1107. 0,
  1108. 0,
  1109. 0,
  1110. 0,
  1111. 0,
  1112. 0,
  1113. 0,
  1114. 0,
  1115. 4,
  1116. 4,
  1117. 0,
  1118. 0,
  1119. 4,
  1120. 0,
  1121. 0,
  1122. 0,
  1123. 0,
  1124. 0,
  1125. 0,
  1126. 0,
  1127. 0,
  1128. 0,
  1129. 0,
  1130. 0,
  1131. 0,
  1132. 0,
  1133. 0,
  1134. 0,
  1135. 0,
  1136. 0,
  1137. 0,
  1138. 8,
  1139. 12,
  1140. 16,
  1141. 12,
  1142. 12,
  1143. 20,
  1144. 12,
  1145. 16,
  1146. 24,
  1147. 28,
  1148. 12,
  1149. 12,
  1150. 32,
  1151. 12,
  1152. 36,
  1153. 12,
  1154. 44,
  1155. 44,
  1156. 44,
  1157. 44,
  1158. 44,
  1159. 44,
  1160. 44,
  1161. 44,
  1162. 44,
  1163. 44,
  1164. 32,
  1165. 32,
  1166. 24,
  1167. 40,
  1168. 28,
  1169. 12,
  1170. 12,
  1171. 48,
  1172. 52,
  1173. 52,
  1174. 52,
  1175. 48,
  1176. 52,
  1177. 52,
  1178. 52,
  1179. 48,
  1180. 52,
  1181. 52,
  1182. 52,
  1183. 52,
  1184. 52,
  1185. 48,
  1186. 52,
  1187. 52,
  1188. 52,
  1189. 52,
  1190. 52,
  1191. 48,
  1192. 52,
  1193. 52,
  1194. 52,
  1195. 52,
  1196. 52,
  1197. 24,
  1198. 12,
  1199. 28,
  1200. 12,
  1201. 12,
  1202. 12,
  1203. 56,
  1204. 60,
  1205. 60,
  1206. 60,
  1207. 56,
  1208. 60,
  1209. 60,
  1210. 60,
  1211. 56,
  1212. 60,
  1213. 60,
  1214. 60,
  1215. 60,
  1216. 60,
  1217. 56,
  1218. 60,
  1219. 60,
  1220. 60,
  1221. 60,
  1222. 60,
  1223. 56,
  1224. 60,
  1225. 60,
  1226. 60,
  1227. 60,
  1228. 60,
  1229. 24,
  1230. 12,
  1231. 28,
  1232. 12,
  1233. 0,
  1234. /* UTF8 continuation byte range. */
  1235. 0,
  1236. 1,
  1237. 0,
  1238. 1,
  1239. 0,
  1240. 1,
  1241. 0,
  1242. 1,
  1243. 0,
  1244. 1,
  1245. 0,
  1246. 1,
  1247. 0,
  1248. 1,
  1249. 0,
  1250. 1,
  1251. 0,
  1252. 1,
  1253. 0,
  1254. 1,
  1255. 0,
  1256. 1,
  1257. 0,
  1258. 1,
  1259. 0,
  1260. 1,
  1261. 0,
  1262. 1,
  1263. 0,
  1264. 1,
  1265. 0,
  1266. 1,
  1267. 0,
  1268. 1,
  1269. 0,
  1270. 1,
  1271. 0,
  1272. 1,
  1273. 0,
  1274. 1,
  1275. 0,
  1276. 1,
  1277. 0,
  1278. 1,
  1279. 0,
  1280. 1,
  1281. 0,
  1282. 1,
  1283. 0,
  1284. 1,
  1285. 0,
  1286. 1,
  1287. 0,
  1288. 1,
  1289. 0,
  1290. 1,
  1291. 0,
  1292. 1,
  1293. 0,
  1294. 1,
  1295. 0,
  1296. 1,
  1297. 0,
  1298. 1,
  1299. /* UTF8 lead byte range. */
  1300. 2,
  1301. 3,
  1302. 2,
  1303. 3,
  1304. 2,
  1305. 3,
  1306. 2,
  1307. 3,
  1308. 2,
  1309. 3,
  1310. 2,
  1311. 3,
  1312. 2,
  1313. 3,
  1314. 2,
  1315. 3,
  1316. 2,
  1317. 3,
  1318. 2,
  1319. 3,
  1320. 2,
  1321. 3,
  1322. 2,
  1323. 3,
  1324. 2,
  1325. 3,
  1326. 2,
  1327. 3,
  1328. 2,
  1329. 3,
  1330. 2,
  1331. 3,
  1332. 2,
  1333. 3,
  1334. 2,
  1335. 3,
  1336. 2,
  1337. 3,
  1338. 2,
  1339. 3,
  1340. 2,
  1341. 3,
  1342. 2,
  1343. 3,
  1344. 2,
  1345. 3,
  1346. 2,
  1347. 3,
  1348. 2,
  1349. 3,
  1350. 2,
  1351. 3,
  1352. 2,
  1353. 3,
  1354. 2,
  1355. 3,
  1356. 2,
  1357. 3,
  1358. 2,
  1359. 3,
  1360. 2,
  1361. 3,
  1362. 2,
  1363. 3,
  1364. /* CONTEXT_UTF8 second last byte. */
  1365. /* ASCII range. */
  1366. 0,
  1367. 0,
  1368. 0,
  1369. 0,
  1370. 0,
  1371. 0,
  1372. 0,
  1373. 0,
  1374. 0,
  1375. 0,
  1376. 0,
  1377. 0,
  1378. 0,
  1379. 0,
  1380. 0,
  1381. 0,
  1382. 0,
  1383. 0,
  1384. 0,
  1385. 0,
  1386. 0,
  1387. 0,
  1388. 0,
  1389. 0,
  1390. 0,
  1391. 0,
  1392. 0,
  1393. 0,
  1394. 0,
  1395. 0,
  1396. 0,
  1397. 0,
  1398. 0,
  1399. 1,
  1400. 1,
  1401. 1,
  1402. 1,
  1403. 1,
  1404. 1,
  1405. 1,
  1406. 1,
  1407. 1,
  1408. 1,
  1409. 1,
  1410. 1,
  1411. 1,
  1412. 1,
  1413. 1,
  1414. 2,
  1415. 2,
  1416. 2,
  1417. 2,
  1418. 2,
  1419. 2,
  1420. 2,
  1421. 2,
  1422. 2,
  1423. 2,
  1424. 1,
  1425. 1,
  1426. 1,
  1427. 1,
  1428. 1,
  1429. 1,
  1430. 1,
  1431. 2,
  1432. 2,
  1433. 2,
  1434. 2,
  1435. 2,
  1436. 2,
  1437. 2,
  1438. 2,
  1439. 2,
  1440. 2,
  1441. 2,
  1442. 2,
  1443. 2,
  1444. 2,
  1445. 2,
  1446. 2,
  1447. 2,
  1448. 2,
  1449. 2,
  1450. 2,
  1451. 2,
  1452. 2,
  1453. 2,
  1454. 2,
  1455. 2,
  1456. 2,
  1457. 1,
  1458. 1,
  1459. 1,
  1460. 1,
  1461. 1,
  1462. 1,
  1463. 3,
  1464. 3,
  1465. 3,
  1466. 3,
  1467. 3,
  1468. 3,
  1469. 3,
  1470. 3,
  1471. 3,
  1472. 3,
  1473. 3,
  1474. 3,
  1475. 3,
  1476. 3,
  1477. 3,
  1478. 3,
  1479. 3,
  1480. 3,
  1481. 3,
  1482. 3,
  1483. 3,
  1484. 3,
  1485. 3,
  1486. 3,
  1487. 3,
  1488. 3,
  1489. 1,
  1490. 1,
  1491. 1,
  1492. 1,
  1493. 0,
  1494. /* UTF8 continuation byte range. */
  1495. 0,
  1496. 0,
  1497. 0,
  1498. 0,
  1499. 0,
  1500. 0,
  1501. 0,
  1502. 0,
  1503. 0,
  1504. 0,
  1505. 0,
  1506. 0,
  1507. 0,
  1508. 0,
  1509. 0,
  1510. 0,
  1511. 0,
  1512. 0,
  1513. 0,
  1514. 0,
  1515. 0,
  1516. 0,
  1517. 0,
  1518. 0,
  1519. 0,
  1520. 0,
  1521. 0,
  1522. 0,
  1523. 0,
  1524. 0,
  1525. 0,
  1526. 0,
  1527. 0,
  1528. 0,
  1529. 0,
  1530. 0,
  1531. 0,
  1532. 0,
  1533. 0,
  1534. 0,
  1535. 0,
  1536. 0,
  1537. 0,
  1538. 0,
  1539. 0,
  1540. 0,
  1541. 0,
  1542. 0,
  1543. 0,
  1544. 0,
  1545. 0,
  1546. 0,
  1547. 0,
  1548. 0,
  1549. 0,
  1550. 0,
  1551. 0,
  1552. 0,
  1553. 0,
  1554. 0,
  1555. 0,
  1556. 0,
  1557. 0,
  1558. 0,
  1559. 0,
  1560. 0,
  1561. 0,
  1562. 0,
  1563. 0,
  1564. 0,
  1565. 0,
  1566. 0,
  1567. 0,
  1568. 0,
  1569. 0,
  1570. 0,
  1571. 0,
  1572. 0,
  1573. 0,
  1574. 0,
  1575. /* UTF8 lead byte range. */
  1576. 0,
  1577. 0,
  1578. 0,
  1579. 0,
  1580. 0,
  1581. 0,
  1582. 0,
  1583. 0,
  1584. 0,
  1585. 0,
  1586. 0,
  1587. 0,
  1588. 0,
  1589. 0,
  1590. 0,
  1591. 0,
  1592. 2,
  1593. 2,
  1594. 2,
  1595. 2,
  1596. 2,
  1597. 2,
  1598. 2,
  1599. 2,
  1600. 2,
  1601. 2,
  1602. 2,
  1603. 2,
  1604. 2,
  1605. 2,
  1606. 2,
  1607. 2,
  1608. 2,
  1609. 2,
  1610. 2,
  1611. 2,
  1612. 2,
  1613. 2,
  1614. 2,
  1615. 2,
  1616. 2,
  1617. 2,
  1618. 2,
  1619. 2,
  1620. 2,
  1621. 2,
  1622. 2,
  1623. 2,
  1624. /* CONTEXT_SIGNED, last byte, same as the above values shifted by 3 bits. */
  1625. 0,
  1626. 8,
  1627. 8,
  1628. 8,
  1629. 8,
  1630. 8,
  1631. 8,
  1632. 8,
  1633. 8,
  1634. 8,
  1635. 8,
  1636. 8,
  1637. 8,
  1638. 8,
  1639. 8,
  1640. 8,
  1641. 16,
  1642. 16,
  1643. 16,
  1644. 16,
  1645. 16,
  1646. 16,
  1647. 16,
  1648. 16,
  1649. 16,
  1650. 16,
  1651. 16,
  1652. 16,
  1653. 16,
  1654. 16,
  1655. 16,
  1656. 16,
  1657. 16,
  1658. 16,
  1659. 16,
  1660. 16,
  1661. 16,
  1662. 16,
  1663. 16,
  1664. 16,
  1665. 16,
  1666. 16,
  1667. 16,
  1668. 16,
  1669. 16,
  1670. 16,
  1671. 16,
  1672. 16,
  1673. 16,
  1674. 16,
  1675. 16,
  1676. 16,
  1677. 16,
  1678. 16,
  1679. 16,
  1680. 16,
  1681. 16,
  1682. 16,
  1683. 16,
  1684. 16,
  1685. 16,
  1686. 16,
  1687. 16,
  1688. 16,
  1689. 24,
  1690. 24,
  1691. 24,
  1692. 24,
  1693. 24,
  1694. 24,
  1695. 24,
  1696. 24,
  1697. 24,
  1698. 24,
  1699. 24,
  1700. 24,
  1701. 24,
  1702. 24,
  1703. 24,
  1704. 24,
  1705. 24,
  1706. 24,
  1707. 24,
  1708. 24,
  1709. 24,
  1710. 24,
  1711. 24,
  1712. 24,
  1713. 24,
  1714. 24,
  1715. 24,
  1716. 24,
  1717. 24,
  1718. 24,
  1719. 24,
  1720. 24,
  1721. 24,
  1722. 24,
  1723. 24,
  1724. 24,
  1725. 24,
  1726. 24,
  1727. 24,
  1728. 24,
  1729. 24,
  1730. 24,
  1731. 24,
  1732. 24,
  1733. 24,
  1734. 24,
  1735. 24,
  1736. 24,
  1737. 24,
  1738. 24,
  1739. 24,
  1740. 24,
  1741. 24,
  1742. 24,
  1743. 24,
  1744. 24,
  1745. 24,
  1746. 24,
  1747. 24,
  1748. 24,
  1749. 24,
  1750. 24,
  1751. 24,
  1752. 24,
  1753. 32,
  1754. 32,
  1755. 32,
  1756. 32,
  1757. 32,
  1758. 32,
  1759. 32,
  1760. 32,
  1761. 32,
  1762. 32,
  1763. 32,
  1764. 32,
  1765. 32,
  1766. 32,
  1767. 32,
  1768. 32,
  1769. 32,
  1770. 32,
  1771. 32,
  1772. 32,
  1773. 32,
  1774. 32,
  1775. 32,
  1776. 32,
  1777. 32,
  1778. 32,
  1779. 32,
  1780. 32,
  1781. 32,
  1782. 32,
  1783. 32,
  1784. 32,
  1785. 32,
  1786. 32,
  1787. 32,
  1788. 32,
  1789. 32,
  1790. 32,
  1791. 32,
  1792. 32,
  1793. 32,
  1794. 32,
  1795. 32,
  1796. 32,
  1797. 32,
  1798. 32,
  1799. 32,
  1800. 32,
  1801. 32,
  1802. 32,
  1803. 32,
  1804. 32,
  1805. 32,
  1806. 32,
  1807. 32,
  1808. 32,
  1809. 32,
  1810. 32,
  1811. 32,
  1812. 32,
  1813. 32,
  1814. 32,
  1815. 32,
  1816. 32,
  1817. 40,
  1818. 40,
  1819. 40,
  1820. 40,
  1821. 40,
  1822. 40,
  1823. 40,
  1824. 40,
  1825. 40,
  1826. 40,
  1827. 40,
  1828. 40,
  1829. 40,
  1830. 40,
  1831. 40,
  1832. 40,
  1833. 40,
  1834. 40,
  1835. 40,
  1836. 40,
  1837. 40,
  1838. 40,
  1839. 40,
  1840. 40,
  1841. 40,
  1842. 40,
  1843. 40,
  1844. 40,
  1845. 40,
  1846. 40,
  1847. 40,
  1848. 40,
  1849. 40,
  1850. 40,
  1851. 40,
  1852. 40,
  1853. 40,
  1854. 40,
  1855. 40,
  1856. 40,
  1857. 40,
  1858. 40,
  1859. 40,
  1860. 40,
  1861. 40,
  1862. 40,
  1863. 40,
  1864. 40,
  1865. 48,
  1866. 48,
  1867. 48,
  1868. 48,
  1869. 48,
  1870. 48,
  1871. 48,
  1872. 48,
  1873. 48,
  1874. 48,
  1875. 48,
  1876. 48,
  1877. 48,
  1878. 48,
  1879. 48,
  1880. 56,
  1881. /* CONTEXT_SIGNED, second last byte. */
  1882. 0,
  1883. 1,
  1884. 1,
  1885. 1,
  1886. 1,
  1887. 1,
  1888. 1,
  1889. 1,
  1890. 1,
  1891. 1,
  1892. 1,
  1893. 1,
  1894. 1,
  1895. 1,
  1896. 1,
  1897. 1,
  1898. 2,
  1899. 2,
  1900. 2,
  1901. 2,
  1902. 2,
  1903. 2,
  1904. 2,
  1905. 2,
  1906. 2,
  1907. 2,
  1908. 2,
  1909. 2,
  1910. 2,
  1911. 2,
  1912. 2,
  1913. 2,
  1914. 2,
  1915. 2,
  1916. 2,
  1917. 2,
  1918. 2,
  1919. 2,
  1920. 2,
  1921. 2,
  1922. 2,
  1923. 2,
  1924. 2,
  1925. 2,
  1926. 2,
  1927. 2,
  1928. 2,
  1929. 2,
  1930. 2,
  1931. 2,
  1932. 2,
  1933. 2,
  1934. 2,
  1935. 2,
  1936. 2,
  1937. 2,
  1938. 2,
  1939. 2,
  1940. 2,
  1941. 2,
  1942. 2,
  1943. 2,
  1944. 2,
  1945. 2,
  1946. 3,
  1947. 3,
  1948. 3,
  1949. 3,
  1950. 3,
  1951. 3,
  1952. 3,
  1953. 3,
  1954. 3,
  1955. 3,
  1956. 3,
  1957. 3,
  1958. 3,
  1959. 3,
  1960. 3,
  1961. 3,
  1962. 3,
  1963. 3,
  1964. 3,
  1965. 3,
  1966. 3,
  1967. 3,
  1968. 3,
  1969. 3,
  1970. 3,
  1971. 3,
  1972. 3,
  1973. 3,
  1974. 3,
  1975. 3,
  1976. 3,
  1977. 3,
  1978. 3,
  1979. 3,
  1980. 3,
  1981. 3,
  1982. 3,
  1983. 3,
  1984. 3,
  1985. 3,
  1986. 3,
  1987. 3,
  1988. 3,
  1989. 3,
  1990. 3,
  1991. 3,
  1992. 3,
  1993. 3,
  1994. 3,
  1995. 3,
  1996. 3,
  1997. 3,
  1998. 3,
  1999. 3,
  2000. 3,
  2001. 3,
  2002. 3,
  2003. 3,
  2004. 3,
  2005. 3,
  2006. 3,
  2007. 3,
  2008. 3,
  2009. 3,
  2010. 4,
  2011. 4,
  2012. 4,
  2013. 4,
  2014. 4,
  2015. 4,
  2016. 4,
  2017. 4,
  2018. 4,
  2019. 4,
  2020. 4,
  2021. 4,
  2022. 4,
  2023. 4,
  2024. 4,
  2025. 4,
  2026. 4,
  2027. 4,
  2028. 4,
  2029. 4,
  2030. 4,
  2031. 4,
  2032. 4,
  2033. 4,
  2034. 4,
  2035. 4,
  2036. 4,
  2037. 4,
  2038. 4,
  2039. 4,
  2040. 4,
  2041. 4,
  2042. 4,
  2043. 4,
  2044. 4,
  2045. 4,
  2046. 4,
  2047. 4,
  2048. 4,
  2049. 4,
  2050. 4,
  2051. 4,
  2052. 4,
  2053. 4,
  2054. 4,
  2055. 4,
  2056. 4,
  2057. 4,
  2058. 4,
  2059. 4,
  2060. 4,
  2061. 4,
  2062. 4,
  2063. 4,
  2064. 4,
  2065. 4,
  2066. 4,
  2067. 4,
  2068. 4,
  2069. 4,
  2070. 4,
  2071. 4,
  2072. 4,
  2073. 4,
  2074. 5,
  2075. 5,
  2076. 5,
  2077. 5,
  2078. 5,
  2079. 5,
  2080. 5,
  2081. 5,
  2082. 5,
  2083. 5,
  2084. 5,
  2085. 5,
  2086. 5,
  2087. 5,
  2088. 5,
  2089. 5,
  2090. 5,
  2091. 5,
  2092. 5,
  2093. 5,
  2094. 5,
  2095. 5,
  2096. 5,
  2097. 5,
  2098. 5,
  2099. 5,
  2100. 5,
  2101. 5,
  2102. 5,
  2103. 5,
  2104. 5,
  2105. 5,
  2106. 5,
  2107. 5,
  2108. 5,
  2109. 5,
  2110. 5,
  2111. 5,
  2112. 5,
  2113. 5,
  2114. 5,
  2115. 5,
  2116. 5,
  2117. 5,
  2118. 5,
  2119. 5,
  2120. 5,
  2121. 5,
  2122. 6,
  2123. 6,
  2124. 6,
  2125. 6,
  2126. 6,
  2127. 6,
  2128. 6,
  2129. 6,
  2130. 6,
  2131. 6,
  2132. 6,
  2133. 6,
  2134. 6,
  2135. 6,
  2136. 6,
  2137. 7,
  2138. }
  2139. type contextLUT []byte
  2140. func getContextLUT(mode int) contextLUT {
  2141. return kContextLookup[mode<<9:]
  2142. }
  2143. func getContext(p1 byte, p2 byte, lut contextLUT) byte {
  2144. return lut[p1] | lut[256+int(p2)]
  2145. }