github.com/andybalholm/brotli@v1.0.6/context.go (about)

     1  package brotli
     2  
     3  /* Lookup table to map the previous two bytes to a context id.
     4  
     5  There are four different context modeling modes defined here:
     6    contextLSB6: context id is the least significant 6 bits of the last byte,
     7    contextMSB6: context id is the most significant 6 bits of the last byte,
     8    contextUTF8: second-order context model tuned for UTF8-encoded text,
     9    contextSigned: second-order context model tuned for signed integers.
    10  
    11  If |p1| and |p2| are the previous two bytes, and |mode| is current context
    12  mode, we calculate the context as:
    13  
    14    context = ContextLut(mode)[p1] | ContextLut(mode)[p2 + 256].
    15  
    16  For contextUTF8 mode, if the previous two bytes are ASCII characters
    17  (i.e. < 128), this will be equivalent to
    18  
    19    context = 4 * context1(p1) + context2(p2),
    20  
    21  where context1 is based on the previous byte in the following way:
    22  
    23    0  : non-ASCII control
    24    1  : \t, \n, \r
    25    2  : space
    26    3  : other punctuation
    27    4  : " '
    28    5  : %
    29    6  : ( < [ {
    30    7  : ) > ] }
    31    8  : , ; :
    32    9  : .
    33    10 : =
    34    11 : number
    35    12 : upper-case vowel
    36    13 : upper-case consonant
    37    14 : lower-case vowel
    38    15 : lower-case consonant
    39  
    40  and context2 is based on the second last byte:
    41  
    42    0 : control, space
    43    1 : punctuation
    44    2 : upper-case letter, number
    45    3 : lower-case letter
    46  
    47  If the last byte is ASCII, and the second last byte is not (in a valid UTF8
    48  stream it will be a continuation byte, value between 128 and 191), the
    49  context is the same as if the second last byte was an ASCII control or space.
    50  
    51  If the last byte is a UTF8 lead byte (value >= 192), then the next byte will
    52  be a continuation byte and the context id is 2 or 3 depending on the LSB of
    53  the last byte and to a lesser extent on the second last byte if it is ASCII.
    54  
    55  If the last byte is a UTF8 continuation byte, the second last byte can be:
    56    - continuation byte: the next byte is probably ASCII or lead byte (assuming
    57      4-byte UTF8 characters are rare) and the context id is 0 or 1.
    58    - lead byte (192 - 207): next byte is ASCII or lead byte, context is 0 or 1
    59    - lead byte (208 - 255): next byte is continuation byte, context is 2 or 3
    60  
    61  The possible value combinations of the previous two bytes, the range of
    62  context ids and the type of the next byte is summarized in the table below:
    63  
    64  |--------\-----------------------------------------------------------------|
    65  |         \                         Last byte                              |
    66  | Second   \---------------------------------------------------------------|
    67  | last byte \    ASCII            |   cont. byte        |   lead byte      |
    68  |            \   (0-127)          |   (128-191)         |   (192-)         |
    69  |=============|===================|=====================|==================|
    70  |  ASCII      | next: ASCII/lead  |  not valid          |  next: cont.     |
    71  |  (0-127)    | context: 4 - 63   |                     |  context: 2 - 3  |
    72  |-------------|-------------------|---------------------|------------------|
    73  |  cont. byte | next: ASCII/lead  |  next: ASCII/lead   |  next: cont.     |
    74  |  (128-191)  | context: 4 - 63   |  context: 0 - 1     |  context: 2 - 3  |
    75  |-------------|-------------------|---------------------|------------------|
    76  |  lead byte  | not valid         |  next: ASCII/lead   |  not valid       |
    77  |  (192-207)  |                   |  context: 0 - 1     |                  |
    78  |-------------|-------------------|---------------------|------------------|
    79  |  lead byte  | not valid         |  next: cont.        |  not valid       |
    80  |  (208-)     |                   |  context: 2 - 3     |                  |
    81  |-------------|-------------------|---------------------|------------------|
    82  */
    83  
    84  const (
    85  	contextLSB6   = 0
    86  	contextMSB6   = 1
    87  	contextUTF8   = 2
    88  	contextSigned = 3
    89  )
    90  
    91  /* Common context lookup table for all context modes. */
    92  var kContextLookup = [2048]byte{
    93  	/* CONTEXT_LSB6, last byte. */
    94  	0,
    95  	1,
    96  	2,
    97  	3,
    98  	4,
    99  	5,
   100  	6,
   101  	7,
   102  	8,
   103  	9,
   104  	10,
   105  	11,
   106  	12,
   107  	13,
   108  	14,
   109  	15,
   110  	16,
   111  	17,
   112  	18,
   113  	19,
   114  	20,
   115  	21,
   116  	22,
   117  	23,
   118  	24,
   119  	25,
   120  	26,
   121  	27,
   122  	28,
   123  	29,
   124  	30,
   125  	31,
   126  	32,
   127  	33,
   128  	34,
   129  	35,
   130  	36,
   131  	37,
   132  	38,
   133  	39,
   134  	40,
   135  	41,
   136  	42,
   137  	43,
   138  	44,
   139  	45,
   140  	46,
   141  	47,
   142  	48,
   143  	49,
   144  	50,
   145  	51,
   146  	52,
   147  	53,
   148  	54,
   149  	55,
   150  	56,
   151  	57,
   152  	58,
   153  	59,
   154  	60,
   155  	61,
   156  	62,
   157  	63,
   158  	0,
   159  	1,
   160  	2,
   161  	3,
   162  	4,
   163  	5,
   164  	6,
   165  	7,
   166  	8,
   167  	9,
   168  	10,
   169  	11,
   170  	12,
   171  	13,
   172  	14,
   173  	15,
   174  	16,
   175  	17,
   176  	18,
   177  	19,
   178  	20,
   179  	21,
   180  	22,
   181  	23,
   182  	24,
   183  	25,
   184  	26,
   185  	27,
   186  	28,
   187  	29,
   188  	30,
   189  	31,
   190  	32,
   191  	33,
   192  	34,
   193  	35,
   194  	36,
   195  	37,
   196  	38,
   197  	39,
   198  	40,
   199  	41,
   200  	42,
   201  	43,
   202  	44,
   203  	45,
   204  	46,
   205  	47,
   206  	48,
   207  	49,
   208  	50,
   209  	51,
   210  	52,
   211  	53,
   212  	54,
   213  	55,
   214  	56,
   215  	57,
   216  	58,
   217  	59,
   218  	60,
   219  	61,
   220  	62,
   221  	63,
   222  	0,
   223  	1,
   224  	2,
   225  	3,
   226  	4,
   227  	5,
   228  	6,
   229  	7,
   230  	8,
   231  	9,
   232  	10,
   233  	11,
   234  	12,
   235  	13,
   236  	14,
   237  	15,
   238  	16,
   239  	17,
   240  	18,
   241  	19,
   242  	20,
   243  	21,
   244  	22,
   245  	23,
   246  	24,
   247  	25,
   248  	26,
   249  	27,
   250  	28,
   251  	29,
   252  	30,
   253  	31,
   254  	32,
   255  	33,
   256  	34,
   257  	35,
   258  	36,
   259  	37,
   260  	38,
   261  	39,
   262  	40,
   263  	41,
   264  	42,
   265  	43,
   266  	44,
   267  	45,
   268  	46,
   269  	47,
   270  	48,
   271  	49,
   272  	50,
   273  	51,
   274  	52,
   275  	53,
   276  	54,
   277  	55,
   278  	56,
   279  	57,
   280  	58,
   281  	59,
   282  	60,
   283  	61,
   284  	62,
   285  	63,
   286  	0,
   287  	1,
   288  	2,
   289  	3,
   290  	4,
   291  	5,
   292  	6,
   293  	7,
   294  	8,
   295  	9,
   296  	10,
   297  	11,
   298  	12,
   299  	13,
   300  	14,
   301  	15,
   302  	16,
   303  	17,
   304  	18,
   305  	19,
   306  	20,
   307  	21,
   308  	22,
   309  	23,
   310  	24,
   311  	25,
   312  	26,
   313  	27,
   314  	28,
   315  	29,
   316  	30,
   317  	31,
   318  	32,
   319  	33,
   320  	34,
   321  	35,
   322  	36,
   323  	37,
   324  	38,
   325  	39,
   326  	40,
   327  	41,
   328  	42,
   329  	43,
   330  	44,
   331  	45,
   332  	46,
   333  	47,
   334  	48,
   335  	49,
   336  	50,
   337  	51,
   338  	52,
   339  	53,
   340  	54,
   341  	55,
   342  	56,
   343  	57,
   344  	58,
   345  	59,
   346  	60,
   347  	61,
   348  	62,
   349  	63,
   350  
   351  	/* CONTEXT_LSB6, second last byte, */
   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  	0,
   591  	0,
   592  	0,
   593  	0,
   594  	0,
   595  	0,
   596  	0,
   597  	0,
   598  	0,
   599  	0,
   600  	0,
   601  	0,
   602  	0,
   603  	0,
   604  	0,
   605  	0,
   606  	0,
   607  	0,
   608  
   609  	/* CONTEXT_MSB6, last byte. */
   610  	0,
   611  	0,
   612  	0,
   613  	0,
   614  	1,
   615  	1,
   616  	1,
   617  	1,
   618  	2,
   619  	2,
   620  	2,
   621  	2,
   622  	3,
   623  	3,
   624  	3,
   625  	3,
   626  	4,
   627  	4,
   628  	4,
   629  	4,
   630  	5,
   631  	5,
   632  	5,
   633  	5,
   634  	6,
   635  	6,
   636  	6,
   637  	6,
   638  	7,
   639  	7,
   640  	7,
   641  	7,
   642  	8,
   643  	8,
   644  	8,
   645  	8,
   646  	9,
   647  	9,
   648  	9,
   649  	9,
   650  	10,
   651  	10,
   652  	10,
   653  	10,
   654  	11,
   655  	11,
   656  	11,
   657  	11,
   658  	12,
   659  	12,
   660  	12,
   661  	12,
   662  	13,
   663  	13,
   664  	13,
   665  	13,
   666  	14,
   667  	14,
   668  	14,
   669  	14,
   670  	15,
   671  	15,
   672  	15,
   673  	15,
   674  	16,
   675  	16,
   676  	16,
   677  	16,
   678  	17,
   679  	17,
   680  	17,
   681  	17,
   682  	18,
   683  	18,
   684  	18,
   685  	18,
   686  	19,
   687  	19,
   688  	19,
   689  	19,
   690  	20,
   691  	20,
   692  	20,
   693  	20,
   694  	21,
   695  	21,
   696  	21,
   697  	21,
   698  	22,
   699  	22,
   700  	22,
   701  	22,
   702  	23,
   703  	23,
   704  	23,
   705  	23,
   706  	24,
   707  	24,
   708  	24,
   709  	24,
   710  	25,
   711  	25,
   712  	25,
   713  	25,
   714  	26,
   715  	26,
   716  	26,
   717  	26,
   718  	27,
   719  	27,
   720  	27,
   721  	27,
   722  	28,
   723  	28,
   724  	28,
   725  	28,
   726  	29,
   727  	29,
   728  	29,
   729  	29,
   730  	30,
   731  	30,
   732  	30,
   733  	30,
   734  	31,
   735  	31,
   736  	31,
   737  	31,
   738  	32,
   739  	32,
   740  	32,
   741  	32,
   742  	33,
   743  	33,
   744  	33,
   745  	33,
   746  	34,
   747  	34,
   748  	34,
   749  	34,
   750  	35,
   751  	35,
   752  	35,
   753  	35,
   754  	36,
   755  	36,
   756  	36,
   757  	36,
   758  	37,
   759  	37,
   760  	37,
   761  	37,
   762  	38,
   763  	38,
   764  	38,
   765  	38,
   766  	39,
   767  	39,
   768  	39,
   769  	39,
   770  	40,
   771  	40,
   772  	40,
   773  	40,
   774  	41,
   775  	41,
   776  	41,
   777  	41,
   778  	42,
   779  	42,
   780  	42,
   781  	42,
   782  	43,
   783  	43,
   784  	43,
   785  	43,
   786  	44,
   787  	44,
   788  	44,
   789  	44,
   790  	45,
   791  	45,
   792  	45,
   793  	45,
   794  	46,
   795  	46,
   796  	46,
   797  	46,
   798  	47,
   799  	47,
   800  	47,
   801  	47,
   802  	48,
   803  	48,
   804  	48,
   805  	48,
   806  	49,
   807  	49,
   808  	49,
   809  	49,
   810  	50,
   811  	50,
   812  	50,
   813  	50,
   814  	51,
   815  	51,
   816  	51,
   817  	51,
   818  	52,
   819  	52,
   820  	52,
   821  	52,
   822  	53,
   823  	53,
   824  	53,
   825  	53,
   826  	54,
   827  	54,
   828  	54,
   829  	54,
   830  	55,
   831  	55,
   832  	55,
   833  	55,
   834  	56,
   835  	56,
   836  	56,
   837  	56,
   838  	57,
   839  	57,
   840  	57,
   841  	57,
   842  	58,
   843  	58,
   844  	58,
   845  	58,
   846  	59,
   847  	59,
   848  	59,
   849  	59,
   850  	60,
   851  	60,
   852  	60,
   853  	60,
   854  	61,
   855  	61,
   856  	61,
   857  	61,
   858  	62,
   859  	62,
   860  	62,
   861  	62,
   862  	63,
   863  	63,
   864  	63,
   865  	63,
   866  
   867  	/* CONTEXT_MSB6, second last byte, */
   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  	0,
  1105  	0,
  1106  	0,
  1107  	0,
  1108  	0,
  1109  	0,
  1110  	0,
  1111  	0,
  1112  	0,
  1113  	0,
  1114  	0,
  1115  	0,
  1116  	0,
  1117  	0,
  1118  	0,
  1119  	0,
  1120  	0,
  1121  	0,
  1122  	0,
  1123  	0,
  1124  
  1125  	/* CONTEXT_UTF8, last byte. */
  1126  	/* ASCII range. */
  1127  	0,
  1128  	0,
  1129  	0,
  1130  	0,
  1131  	0,
  1132  	0,
  1133  	0,
  1134  	0,
  1135  	0,
  1136  	4,
  1137  	4,
  1138  	0,
  1139  	0,
  1140  	4,
  1141  	0,
  1142  	0,
  1143  	0,
  1144  	0,
  1145  	0,
  1146  	0,
  1147  	0,
  1148  	0,
  1149  	0,
  1150  	0,
  1151  	0,
  1152  	0,
  1153  	0,
  1154  	0,
  1155  	0,
  1156  	0,
  1157  	0,
  1158  	0,
  1159  	8,
  1160  	12,
  1161  	16,
  1162  	12,
  1163  	12,
  1164  	20,
  1165  	12,
  1166  	16,
  1167  	24,
  1168  	28,
  1169  	12,
  1170  	12,
  1171  	32,
  1172  	12,
  1173  	36,
  1174  	12,
  1175  	44,
  1176  	44,
  1177  	44,
  1178  	44,
  1179  	44,
  1180  	44,
  1181  	44,
  1182  	44,
  1183  	44,
  1184  	44,
  1185  	32,
  1186  	32,
  1187  	24,
  1188  	40,
  1189  	28,
  1190  	12,
  1191  	12,
  1192  	48,
  1193  	52,
  1194  	52,
  1195  	52,
  1196  	48,
  1197  	52,
  1198  	52,
  1199  	52,
  1200  	48,
  1201  	52,
  1202  	52,
  1203  	52,
  1204  	52,
  1205  	52,
  1206  	48,
  1207  	52,
  1208  	52,
  1209  	52,
  1210  	52,
  1211  	52,
  1212  	48,
  1213  	52,
  1214  	52,
  1215  	52,
  1216  	52,
  1217  	52,
  1218  	24,
  1219  	12,
  1220  	28,
  1221  	12,
  1222  	12,
  1223  	12,
  1224  	56,
  1225  	60,
  1226  	60,
  1227  	60,
  1228  	56,
  1229  	60,
  1230  	60,
  1231  	60,
  1232  	56,
  1233  	60,
  1234  	60,
  1235  	60,
  1236  	60,
  1237  	60,
  1238  	56,
  1239  	60,
  1240  	60,
  1241  	60,
  1242  	60,
  1243  	60,
  1244  	56,
  1245  	60,
  1246  	60,
  1247  	60,
  1248  	60,
  1249  	60,
  1250  	24,
  1251  	12,
  1252  	28,
  1253  	12,
  1254  	0,
  1255  
  1256  	/* UTF8 continuation byte range. */
  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  	0,
  1300  	1,
  1301  	0,
  1302  	1,
  1303  	0,
  1304  	1,
  1305  	0,
  1306  	1,
  1307  	0,
  1308  	1,
  1309  	0,
  1310  	1,
  1311  	0,
  1312  	1,
  1313  	0,
  1314  	1,
  1315  	0,
  1316  	1,
  1317  	0,
  1318  	1,
  1319  	0,
  1320  	1,
  1321  
  1322  	/* UTF8 lead byte range. */
  1323  	2,
  1324  	3,
  1325  	2,
  1326  	3,
  1327  	2,
  1328  	3,
  1329  	2,
  1330  	3,
  1331  	2,
  1332  	3,
  1333  	2,
  1334  	3,
  1335  	2,
  1336  	3,
  1337  	2,
  1338  	3,
  1339  	2,
  1340  	3,
  1341  	2,
  1342  	3,
  1343  	2,
  1344  	3,
  1345  	2,
  1346  	3,
  1347  	2,
  1348  	3,
  1349  	2,
  1350  	3,
  1351  	2,
  1352  	3,
  1353  	2,
  1354  	3,
  1355  	2,
  1356  	3,
  1357  	2,
  1358  	3,
  1359  	2,
  1360  	3,
  1361  	2,
  1362  	3,
  1363  	2,
  1364  	3,
  1365  	2,
  1366  	3,
  1367  	2,
  1368  	3,
  1369  	2,
  1370  	3,
  1371  	2,
  1372  	3,
  1373  	2,
  1374  	3,
  1375  	2,
  1376  	3,
  1377  	2,
  1378  	3,
  1379  	2,
  1380  	3,
  1381  	2,
  1382  	3,
  1383  	2,
  1384  	3,
  1385  	2,
  1386  	3,
  1387  
  1388  	/* CONTEXT_UTF8 second last byte. */
  1389  	/* ASCII range. */
  1390  	0,
  1391  	0,
  1392  	0,
  1393  	0,
  1394  	0,
  1395  	0,
  1396  	0,
  1397  	0,
  1398  	0,
  1399  	0,
  1400  	0,
  1401  	0,
  1402  	0,
  1403  	0,
  1404  	0,
  1405  	0,
  1406  	0,
  1407  	0,
  1408  	0,
  1409  	0,
  1410  	0,
  1411  	0,
  1412  	0,
  1413  	0,
  1414  	0,
  1415  	0,
  1416  	0,
  1417  	0,
  1418  	0,
  1419  	0,
  1420  	0,
  1421  	0,
  1422  	0,
  1423  	1,
  1424  	1,
  1425  	1,
  1426  	1,
  1427  	1,
  1428  	1,
  1429  	1,
  1430  	1,
  1431  	1,
  1432  	1,
  1433  	1,
  1434  	1,
  1435  	1,
  1436  	1,
  1437  	1,
  1438  	2,
  1439  	2,
  1440  	2,
  1441  	2,
  1442  	2,
  1443  	2,
  1444  	2,
  1445  	2,
  1446  	2,
  1447  	2,
  1448  	1,
  1449  	1,
  1450  	1,
  1451  	1,
  1452  	1,
  1453  	1,
  1454  	1,
  1455  	2,
  1456  	2,
  1457  	2,
  1458  	2,
  1459  	2,
  1460  	2,
  1461  	2,
  1462  	2,
  1463  	2,
  1464  	2,
  1465  	2,
  1466  	2,
  1467  	2,
  1468  	2,
  1469  	2,
  1470  	2,
  1471  	2,
  1472  	2,
  1473  	2,
  1474  	2,
  1475  	2,
  1476  	2,
  1477  	2,
  1478  	2,
  1479  	2,
  1480  	2,
  1481  	1,
  1482  	1,
  1483  	1,
  1484  	1,
  1485  	1,
  1486  	1,
  1487  	3,
  1488  	3,
  1489  	3,
  1490  	3,
  1491  	3,
  1492  	3,
  1493  	3,
  1494  	3,
  1495  	3,
  1496  	3,
  1497  	3,
  1498  	3,
  1499  	3,
  1500  	3,
  1501  	3,
  1502  	3,
  1503  	3,
  1504  	3,
  1505  	3,
  1506  	3,
  1507  	3,
  1508  	3,
  1509  	3,
  1510  	3,
  1511  	3,
  1512  	3,
  1513  	1,
  1514  	1,
  1515  	1,
  1516  	1,
  1517  	0,
  1518  
  1519  	/* UTF8 continuation byte range. */
  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  	0,
  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  	0,
  1593  	0,
  1594  	0,
  1595  	0,
  1596  	0,
  1597  	0,
  1598  	0,
  1599  	0,
  1600  
  1601  	/* UTF8 lead byte range. */
  1602  	0,
  1603  	0,
  1604  	0,
  1605  	0,
  1606  	0,
  1607  	0,
  1608  	0,
  1609  	0,
  1610  	0,
  1611  	0,
  1612  	0,
  1613  	0,
  1614  	0,
  1615  	0,
  1616  	0,
  1617  	0,
  1618  	2,
  1619  	2,
  1620  	2,
  1621  	2,
  1622  	2,
  1623  	2,
  1624  	2,
  1625  	2,
  1626  	2,
  1627  	2,
  1628  	2,
  1629  	2,
  1630  	2,
  1631  	2,
  1632  	2,
  1633  	2,
  1634  	2,
  1635  	2,
  1636  	2,
  1637  	2,
  1638  	2,
  1639  	2,
  1640  	2,
  1641  	2,
  1642  	2,
  1643  	2,
  1644  	2,
  1645  	2,
  1646  	2,
  1647  	2,
  1648  	2,
  1649  	2,
  1650  
  1651  	/* CONTEXT_SIGNED, last byte, same as the above values shifted by 3 bits. */
  1652  	0,
  1653  	8,
  1654  	8,
  1655  	8,
  1656  	8,
  1657  	8,
  1658  	8,
  1659  	8,
  1660  	8,
  1661  	8,
  1662  	8,
  1663  	8,
  1664  	8,
  1665  	8,
  1666  	8,
  1667  	8,
  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  	16,
  1690  	16,
  1691  	16,
  1692  	16,
  1693  	16,
  1694  	16,
  1695  	16,
  1696  	16,
  1697  	16,
  1698  	16,
  1699  	16,
  1700  	16,
  1701  	16,
  1702  	16,
  1703  	16,
  1704  	16,
  1705  	16,
  1706  	16,
  1707  	16,
  1708  	16,
  1709  	16,
  1710  	16,
  1711  	16,
  1712  	16,
  1713  	16,
  1714  	16,
  1715  	16,
  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  	24,
  1754  	24,
  1755  	24,
  1756  	24,
  1757  	24,
  1758  	24,
  1759  	24,
  1760  	24,
  1761  	24,
  1762  	24,
  1763  	24,
  1764  	24,
  1765  	24,
  1766  	24,
  1767  	24,
  1768  	24,
  1769  	24,
  1770  	24,
  1771  	24,
  1772  	24,
  1773  	24,
  1774  	24,
  1775  	24,
  1776  	24,
  1777  	24,
  1778  	24,
  1779  	24,
  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  	32,
  1818  	32,
  1819  	32,
  1820  	32,
  1821  	32,
  1822  	32,
  1823  	32,
  1824  	32,
  1825  	32,
  1826  	32,
  1827  	32,
  1828  	32,
  1829  	32,
  1830  	32,
  1831  	32,
  1832  	32,
  1833  	32,
  1834  	32,
  1835  	32,
  1836  	32,
  1837  	32,
  1838  	32,
  1839  	32,
  1840  	32,
  1841  	32,
  1842  	32,
  1843  	32,
  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  	40,
  1866  	40,
  1867  	40,
  1868  	40,
  1869  	40,
  1870  	40,
  1871  	40,
  1872  	40,
  1873  	40,
  1874  	40,
  1875  	40,
  1876  	40,
  1877  	40,
  1878  	40,
  1879  	40,
  1880  	40,
  1881  	40,
  1882  	40,
  1883  	40,
  1884  	40,
  1885  	40,
  1886  	40,
  1887  	40,
  1888  	40,
  1889  	40,
  1890  	40,
  1891  	40,
  1892  	48,
  1893  	48,
  1894  	48,
  1895  	48,
  1896  	48,
  1897  	48,
  1898  	48,
  1899  	48,
  1900  	48,
  1901  	48,
  1902  	48,
  1903  	48,
  1904  	48,
  1905  	48,
  1906  	48,
  1907  	56,
  1908  
  1909  	/* CONTEXT_SIGNED, second last byte. */
  1910  	0,
  1911  	1,
  1912  	1,
  1913  	1,
  1914  	1,
  1915  	1,
  1916  	1,
  1917  	1,
  1918  	1,
  1919  	1,
  1920  	1,
  1921  	1,
  1922  	1,
  1923  	1,
  1924  	1,
  1925  	1,
  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  	2,
  1947  	2,
  1948  	2,
  1949  	2,
  1950  	2,
  1951  	2,
  1952  	2,
  1953  	2,
  1954  	2,
  1955  	2,
  1956  	2,
  1957  	2,
  1958  	2,
  1959  	2,
  1960  	2,
  1961  	2,
  1962  	2,
  1963  	2,
  1964  	2,
  1965  	2,
  1966  	2,
  1967  	2,
  1968  	2,
  1969  	2,
  1970  	2,
  1971  	2,
  1972  	2,
  1973  	2,
  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  	3,
  2011  	3,
  2012  	3,
  2013  	3,
  2014  	3,
  2015  	3,
  2016  	3,
  2017  	3,
  2018  	3,
  2019  	3,
  2020  	3,
  2021  	3,
  2022  	3,
  2023  	3,
  2024  	3,
  2025  	3,
  2026  	3,
  2027  	3,
  2028  	3,
  2029  	3,
  2030  	3,
  2031  	3,
  2032  	3,
  2033  	3,
  2034  	3,
  2035  	3,
  2036  	3,
  2037  	3,
  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  	4,
  2075  	4,
  2076  	4,
  2077  	4,
  2078  	4,
  2079  	4,
  2080  	4,
  2081  	4,
  2082  	4,
  2083  	4,
  2084  	4,
  2085  	4,
  2086  	4,
  2087  	4,
  2088  	4,
  2089  	4,
  2090  	4,
  2091  	4,
  2092  	4,
  2093  	4,
  2094  	4,
  2095  	4,
  2096  	4,
  2097  	4,
  2098  	4,
  2099  	4,
  2100  	4,
  2101  	4,
  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  	5,
  2123  	5,
  2124  	5,
  2125  	5,
  2126  	5,
  2127  	5,
  2128  	5,
  2129  	5,
  2130  	5,
  2131  	5,
  2132  	5,
  2133  	5,
  2134  	5,
  2135  	5,
  2136  	5,
  2137  	5,
  2138  	5,
  2139  	5,
  2140  	5,
  2141  	5,
  2142  	5,
  2143  	5,
  2144  	5,
  2145  	5,
  2146  	5,
  2147  	5,
  2148  	5,
  2149  	5,
  2150  	6,
  2151  	6,
  2152  	6,
  2153  	6,
  2154  	6,
  2155  	6,
  2156  	6,
  2157  	6,
  2158  	6,
  2159  	6,
  2160  	6,
  2161  	6,
  2162  	6,
  2163  	6,
  2164  	6,
  2165  	7,
  2166  }
  2167  
  2168  type contextLUT []byte
  2169  
  2170  func getContextLUT(mode int) contextLUT {
  2171  	return kContextLookup[mode<<9:]
  2172  }
  2173  
  2174  func getContext(p1 byte, p2 byte, lut contextLUT) byte {
  2175  	return lut[p1] | lut[256+int(p2)]
  2176  }