xref: /aosp_15_r20/external/zlib/inftrees.h (revision 86ee64e75fa5f8bce2c8c356138035642429cd05)
1*86ee64e7SAndroid Build Coastguard Worker /* inftrees.h -- header to use inftrees.c
2*86ee64e7SAndroid Build Coastguard Worker  * Copyright (C) 1995-2005, 2010 Mark Adler
3*86ee64e7SAndroid Build Coastguard Worker  * For conditions of distribution and use, see copyright notice in zlib.h
4*86ee64e7SAndroid Build Coastguard Worker  */
5*86ee64e7SAndroid Build Coastguard Worker 
6*86ee64e7SAndroid Build Coastguard Worker /* WARNING: this file should *not* be used by applications. It is
7*86ee64e7SAndroid Build Coastguard Worker    part of the implementation of the compression library and is
8*86ee64e7SAndroid Build Coastguard Worker    subject to change. Applications should only use zlib.h.
9*86ee64e7SAndroid Build Coastguard Worker  */
10*86ee64e7SAndroid Build Coastguard Worker 
11*86ee64e7SAndroid Build Coastguard Worker /* Structure for decoding tables.  Each entry provides either the
12*86ee64e7SAndroid Build Coastguard Worker    information needed to do the operation requested by the code that
13*86ee64e7SAndroid Build Coastguard Worker    indexed that table entry, or it provides a pointer to another
14*86ee64e7SAndroid Build Coastguard Worker    table that indexes more bits of the code.  op indicates whether
15*86ee64e7SAndroid Build Coastguard Worker    the entry is a pointer to another table, a literal, a length or
16*86ee64e7SAndroid Build Coastguard Worker    distance, an end-of-block, or an invalid code.  For a table
17*86ee64e7SAndroid Build Coastguard Worker    pointer, the low four bits of op is the number of index bits of
18*86ee64e7SAndroid Build Coastguard Worker    that table.  For a length or distance, the low four bits of op
19*86ee64e7SAndroid Build Coastguard Worker    is the number of extra bits to get after the code.  bits is
20*86ee64e7SAndroid Build Coastguard Worker    the number of bits in this code or part of the code to drop off
21*86ee64e7SAndroid Build Coastguard Worker    of the bit buffer.  val is the actual byte to output in the case
22*86ee64e7SAndroid Build Coastguard Worker    of a literal, the base length or distance, or the offset from
23*86ee64e7SAndroid Build Coastguard Worker    the current table to the next table.  Each entry is four bytes. */
24*86ee64e7SAndroid Build Coastguard Worker typedef struct {
25*86ee64e7SAndroid Build Coastguard Worker     unsigned char op;           /* operation, extra bits, table bits */
26*86ee64e7SAndroid Build Coastguard Worker     unsigned char bits;         /* bits in this part of the code */
27*86ee64e7SAndroid Build Coastguard Worker     unsigned short val;         /* offset in table or code value */
28*86ee64e7SAndroid Build Coastguard Worker } code;
29*86ee64e7SAndroid Build Coastguard Worker 
30*86ee64e7SAndroid Build Coastguard Worker /* op values as set by inflate_table():
31*86ee64e7SAndroid Build Coastguard Worker     00000000 - literal
32*86ee64e7SAndroid Build Coastguard Worker     0000tttt - table link, tttt != 0 is the number of table index bits
33*86ee64e7SAndroid Build Coastguard Worker     0001eeee - length or distance, eeee is the number of extra bits
34*86ee64e7SAndroid Build Coastguard Worker     01100000 - end of block
35*86ee64e7SAndroid Build Coastguard Worker     01000000 - invalid code
36*86ee64e7SAndroid Build Coastguard Worker  */
37*86ee64e7SAndroid Build Coastguard Worker 
38*86ee64e7SAndroid Build Coastguard Worker /* Maximum size of the dynamic table.  The maximum number of code structures is
39*86ee64e7SAndroid Build Coastguard Worker    1924, which is the sum of 1332 for literal/length codes and 592 for distance
40*86ee64e7SAndroid Build Coastguard Worker    codes.  These values were found by exhaustive searches using the program
41*86ee64e7SAndroid Build Coastguard Worker    examples/enough.c found in the zlib distribution.  The arguments to that
42*86ee64e7SAndroid Build Coastguard Worker    program are the number of symbols, the initial root table size, and the
43*86ee64e7SAndroid Build Coastguard Worker    maximum bit length of a code.  "enough 286 10 15" for literal/length codes
44*86ee64e7SAndroid Build Coastguard Worker    returns returns 1332, and "enough 30 9 15" for distance codes returns 592.
45*86ee64e7SAndroid Build Coastguard Worker    The initial root table size (10 or 9) is found in the fifth argument of the
46*86ee64e7SAndroid Build Coastguard Worker    inflate_table() calls in inflate.c and infback.c.  If the root table size is
47*86ee64e7SAndroid Build Coastguard Worker    changed, then these maximum sizes would be need to be recalculated and
48*86ee64e7SAndroid Build Coastguard Worker    updated. */
49*86ee64e7SAndroid Build Coastguard Worker #define ENOUGH_LENS 1332
50*86ee64e7SAndroid Build Coastguard Worker #define ENOUGH_DISTS 592
51*86ee64e7SAndroid Build Coastguard Worker #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
52*86ee64e7SAndroid Build Coastguard Worker 
53*86ee64e7SAndroid Build Coastguard Worker /* Type of code to build for inflate_table() */
54*86ee64e7SAndroid Build Coastguard Worker typedef enum {
55*86ee64e7SAndroid Build Coastguard Worker     CODES,
56*86ee64e7SAndroid Build Coastguard Worker     LENS,
57*86ee64e7SAndroid Build Coastguard Worker     DISTS
58*86ee64e7SAndroid Build Coastguard Worker } codetype;
59*86ee64e7SAndroid Build Coastguard Worker 
60*86ee64e7SAndroid Build Coastguard Worker int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens,
61*86ee64e7SAndroid Build Coastguard Worker                                 unsigned codes, code FAR * FAR *table,
62*86ee64e7SAndroid Build Coastguard Worker                                 unsigned FAR *bits, unsigned short FAR *work);
63