Ruby: ext/zlib/zlib-1.2.13/trees.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Functions | Variables
trees.c File Reference
`#include "deflate.h"`
`#include "trees.h"`

Go to the source code of this file.

## Data Structures
struct | static_tree_desc_s

## Macros
#define | MAX_BL_BITS 7
#define | END_BLOCK 256
#define | REP_3_6 16
#define | REPZ_3_10 17
#define | REPZ_11_138 18
#define | DIST_CODE_LEN 512 /* see definition of array dist_code below */
#define | send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
#define | put_short(s, w)
#define | send_bits(s, value, length)
#define | SMALLEST 1
#define | pqremove(s, tree, top)
#define | smaller(tree, n, m, depth)

## Functions
void tr_static_init | OF ((void))
void init_block | OF ((deflate_state *s))
void pqdownheap | OF ((deflate_state *s, ct_data *tree, int k))
void gen_bitlen | OF ((deflate_state *s, tree_desc *desc))
void gen_codes | OF ((ct_data *tree, int max_code, ushf *bl_count))
void scan_tree | OF ((deflate_state *s, ct_data *tree, int max_code))
void send_all_trees | OF ((deflate_state *s, int lcodes, int dcodes, int blcodes))
void compress_block | OF ((deflate_state *s, const ct_data *ltree, const ct_data *dtree))
unsigned bi_reverse | OF ((unsigned code, int len))
void | tr_static_init ()
void ZLIB_INTERNAL | _tr_init (deflate_state *s)
void | init_block (deflate_state *s)
void | pqdownheap (deflate_state *s, ct_data *tree, int k)
void | gen_bitlen (deflate_state *s, tree_desc *desc)
void | gen_codes (ct_data *tree, int max_code, ushf *bl_count)
void | build_tree (deflate_state *s, tree_desc *desc)
void | scan_tree (deflate_state *s, ct_data *tree, int max_code)
void | send_tree (deflate_state *s, ct_data *tree, int max_code)
int | build_bl_tree (deflate_state *s)
void | send_all_trees (deflate_state *s, int lcodes, int dcodes, int blcodes)
void ZLIB_INTERNAL | _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int last)
void ZLIB_INTERNAL | _tr_flush_bits (deflate_state *s)
void ZLIB_INTERNAL | _tr_align (deflate_state *s)
void ZLIB_INTERNAL | _tr_flush_block (deflate_state *s, charf *buf, ulg stored_len, int last)
int ZLIB_INTERNAL | _tr_tally (deflate_state *s, unsigned dist, unsigned lc)
void | compress_block (deflate_state *s, const ct_data *ltree, const ct_data *dtree)
int | detect_data_type (deflate_state *s)
unsigned | bi_reverse (unsigned code, int len)
void | bi_flush (deflate_state *s)
void | bi_windup (deflate_state *s)

## Variables
const int | extra_lbits [LENGTH_CODES] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}
const int | extra_dbits [D_CODES] = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}
const int | extra_blbits [BL_CODES] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}
const uch | bl_order [BL_CODES] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}
const static_tree_desc | static_l_desc
const static_tree_desc | static_d_desc
const static_tree_desc | static_bl_desc

## Macro Definition Documentation

## ◆ DIST_CODE_LEN

#define DIST_CODE_LEN 512 /* see definition of array dist_code below */

Definition at line 81 of file trees.c.

## ◆ END_BLOCK

#define END_BLOCK 256

Definition at line 50 of file trees.c.

## ◆ MAX_BL_BITS

#define MAX_BL_BITS 7

Definition at line 47 of file trees.c.

## ◆ pqremove

#define pqremove | ( |  | s,
|  |  | tree,
|  |  | top
| ) |  |

Value:
{\
top = s->heap[SMALLEST]; \
s->heap[SMALLEST] = s->heap[s->heap_len--]; \
pqdownheap(s, tree, SMALLEST); \
}
top
unsigned int top
Definition: nkf.c:4323
SMALLEST
#define SMALLEST
Definition: trees.c:422

Definition at line 430 of file trees.c.

## ◆ put_short

#define put_short | ( |  | s,
|  |  | w
| ) |  |

Value:
{ \
put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \
}
ush
unsigned short ush
Definition: zutil.h:41
uch
unsigned char uch
Definition: zutil.h:39

Definition at line 174 of file trees.c.

## ◆ REP_3_6

#define REP_3_6 16

Definition at line 53 of file trees.c.

## ◆ REPZ_11_138

#define REPZ_11_138 18

Definition at line 59 of file trees.c.

## ◆ REPZ_3_10

#define REPZ_3_10 17

Definition at line 56 of file trees.c.

## ◆ send_bits

#define send_bits | ( |  | s,
|  |  | value,
|  |  | length
| ) |  |

Value:
{ int len = length;\
if (s->bi_valid > (int)Buf_size - len) {\
int val = (int)value;\
s->bi_buf |= (ush)val << s->bi_valid;\
put_short(s, s->bi_buf);\
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
s->bi_valid += len - Buf_size;\
} else {\
s->bi_buf |= (ush)(value) << s->bi_valid;\
s->bi_valid += len;\
}\
}
Buf_size
#define Buf_size
Definition: deflate.h:51
len
uint8_t len
Definition: escape.c:17
int
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
put_short
#define put_short(s, w)
Definition: trees.c:174

Definition at line 211 of file trees.c.

## ◆ send_code

#define send_code | ( |  | s,
|  |  | c,
|  |  | tree
| ) |  | send_bits(s, tree[c].Code, tree[c].Len)

Definition at line 161 of file trees.c.

## ◆ smaller

#define smaller | ( |  | tree,
|  |  | n,
|  |  | m,
|  |  | depth
| ) |  |

Value:
(tree[n].Freq < tree[m].Freq || \
(tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))

Definition at line 441 of file trees.c.

## ◆ SMALLEST

#define SMALLEST 1

Definition at line 422 of file trees.c.

## Function Documentation

## ◆ _tr_align()

void ZLIB_INTERNAL _tr_align | ( | deflate_state * | s | ) |

Definition at line 897 of file trees.c.

References bi_flush(), END_BLOCK, send_bits, send_code, static_ltree, and STATIC_TREES.

Referenced by deflate().

## ◆ _tr_flush_bits()

void ZLIB_INTERNAL _tr_flush_bits | ( | deflate_state * | s | ) |

Definition at line 887 of file trees.c.

References bi_flush().

Referenced by deflatePrime(), and flush_pending().

## ◆ _tr_flush_block()

void ZLIB_INTERNAL _tr_flush_block | ( | deflate_state * | s,
|  | charf * | buf,
|  | ulg | stored_len,
|  | int | last
| ) |  |

Definition at line 912 of file trees.c.

References _tr_stored_block(), Assert, bi_windup(), build_bl_tree(), build_tree(), compress_block(), detect_data_type(), DYN_TREES, init_block(), last, send_all_trees(), send_bits, static_dtree, static_ltree, STATIC_TREES, Tracev, Z_FIXED, and Z_UNKNOWN.

## ◆ _tr_init()

void ZLIB_INTERNAL _tr_init | ( | deflate_state * | s | ) |

Definition at line 379 of file trees.c.

References init_block(), L, static_bl_desc, static_d_desc, static_l_desc, and tr_static_init().

Referenced by deflateResetKeep().

## ◆ _tr_stored_block()

void ZLIB_INTERNAL _tr_stored_block | ( | deflate_state * | s,
|  | charf * | buf,
|  | ulg | stored_len,
|  | int | last
| ) |  |

Definition at line 863 of file trees.c.

References bi_windup(), last, put_short, send_bits, STORED_BLOCK, and zmemcpy.

Referenced by _tr_flush_block(), deflate(), and deflate_stored().

## ◆ _tr_tally()

int ZLIB_INTERNAL _tr_tally | ( | deflate_state * | s,
|  | unsigned | dist,
|  | unsigned | lc
| ) |  |

Definition at line 1014 of file trees.c.

References _length_code, Assert, d_code, D_CODES, LITERALS, MAX_DIST, MAX_MATCH, MIN_MATCH, and internal_state::sym_buf.

## ◆ bi_flush()

void bi_flush | ( | deflate_state * | s | ) |

Definition at line 1151 of file trees.c.

References put_byte, and put_short.

Referenced by _tr_align(), and _tr_flush_bits().

## ◆ bi_reverse()

unsigned bi_reverse | ( | unsigned | code,
|  | int | len
| ) |  |

Definition at line 1136 of file trees.c.

References len.

Referenced by gen_codes(), and tr_static_init().

## ◆ bi_windup()

void bi_windup | ( | deflate_state * | s | ) |

Definition at line 1168 of file trees.c.

References put_byte, and put_short.

Referenced by _tr_flush_block(), and _tr_stored_block().

## ◆ build_bl_tree()

int build_bl_tree | ( | deflate_state * | s | ) |

Definition at line 799 of file trees.c.

References BL_CODES, bl_order, build_tree(), scan_tree(), and Tracev.

Referenced by _tr_flush_block().

## ◆ build_tree()

void build_tree | ( | deflate_state * | s,
|  | tree_desc * | desc
| ) |  |

Definition at line 615 of file trees.c.

References tree_desc_s::dyn_tree, static_tree_desc_s::elems, Freq, gen_bitlen(), gen_codes(), HEAP_SIZE, tree_desc_s::max_code, pqdownheap(), pqremove, SMALLEST, tree_desc_s::stat_desc, and static_tree_desc_s::static_tree.

Referenced by _tr_flush_block(), and build_bl_tree().

## ◆ compress_block()

void compress_block | ( | deflate_state * | s,
|  | const ct_data * | ltree,
|  | const ct_data * | dtree
| ) |  |

Definition at line 1042 of file trees.c.

References _length_code, Assert, base_dist, base_length, d_code, D_CODES, END_BLOCK, extra_dbits, extra_lbits, LITERALS, send_bits, send_code, and Tracecv.

Referenced by _tr_flush_block().

## ◆ detect_data_type()

int detect_data_type | ( | deflate_state * | s | ) |

Definition at line 1102 of file trees.c.

References LITERALS, Z_BINARY, and Z_TEXT.

Referenced by _tr_flush_block().

## ◆ gen_bitlen()

void gen_bitlen | ( | deflate_state * | s,
|  | tree_desc * | desc
| ) |  |

Definition at line 486 of file trees.c.

References bits(), tree_desc_s::dyn_tree, static_tree_desc_s::extra_base, static_tree_desc_s::extra_bits, f, HEAP_SIZE, Len, MAX_BITS, tree_desc_s::max_code, static_tree_desc_s::max_length, tree_desc_s::stat_desc, static_tree_desc_s::static_tree, and Tracev.

Referenced by build_tree().

## ◆ gen_codes()

void gen_codes | ( | ct_data * | tree,
|  | int | max_code,
|  | ushf * | bl_count
| ) |  |

Definition at line 572 of file trees.c.

References Assert, bi_reverse(), bits(), Code, len, MAX_BITS, static_ltree, Tracecv, and Tracev.

Referenced by build_tree(), and tr_static_init().

## ◆ init_block()

void init_block | ( | deflate_state * | s | ) |

Definition at line 407 of file trees.c.

References BL_CODES, D_CODES, internal_state::dyn_ltree, END_BLOCK, L, and L_CODES.

Referenced by _tr_flush_block(), and _tr_init().

## ◆ OF() [1/9]

void gen_codes OF | ( | (ct_data *tree, int max_code, ushf *bl_count) |  | ) |

## ◆ OF() [2/9]

void init_block OF | ( | (deflate_state *s) |  | ) |

## ◆ OF() [3/9]

void compress_block OF | ( | (deflate_state *s, const ct_data *ltree, const ct_data *dtree) |  | ) |

## ◆ OF() [4/9]

void pqdownheap OF | ( | (deflate_state *s, ct_data *tree, int k) |  | ) |

## ◆ OF() [5/9]

void scan_tree OF | ( | (deflate_state *s, ct_data *tree, int max_code) |  | ) |

## ◆ OF() [6/9]

void send_all_trees OF | ( | (deflate_state *s, int lcodes, int dcodes, int blcodes) |  | ) |

## ◆ OF() [7/9]

void gen_bitlen OF | ( | (deflate_state *s, tree_desc *desc) |  | ) |

## ◆ OF() [8/9]

unsigned bi_reverse OF | ( | (unsigned code, int len) |  | ) |

## ◆ OF() [9/9]

void tr_static_init OF | ( | (void) |  | ) |

## ◆ pqdownheap()

void pqdownheap | ( | deflate_state * | s,
|  | ct_data * | tree,
|  | int | k
| ) |  |

Definition at line 451 of file trees.c.

References smaller.

Referenced by build_tree().

## ◆ scan_tree()

void scan_tree | ( | deflate_state * | s,
|  | ct_data * | tree,
|  | int | max_code
| ) |  |

Definition at line 703 of file trees.c.

References count, REP_3_6, REPZ_11_138, and REPZ_3_10.

Referenced by build_bl_tree().

## ◆ send_all_trees()

void send_all_trees | ( | deflate_state * | s,
|  | int | lcodes,
|  | int | dcodes,
|  | int | blcodes
| ) |  |

Definition at line 834 of file trees.c.

References Assert, BL_CODES, bl_order, D_CODES, L_CODES, send_bits, send_tree(), and Tracev.

Referenced by _tr_flush_block().

## ◆ send_tree()

void send_tree | ( | deflate_state * | s,
|  | ct_data * | tree,
|  | int | max_code
| ) |  |

Definition at line 748 of file trees.c.

References Assert, count, REP_3_6, REPZ_11_138, REPZ_3_10, send_bits, and send_code.

Referenced by send_all_trees().

## ◆ tr_static_init()

void tr_static_init | ( |  | ) |

Definition at line 232 of file trees.c.

References _dist_code, _length_code, Assert, base_dist, base_length, bi_reverse(), bits(), D_CODES, static_tree_desc_s::extra_bits, extra_blbits, extra_dbits, extra_lbits, gen_codes(), L_CODES, LENGTH_CODES, MAX_BITS, static_bl_desc, static_d_desc, static_dtree, static_l_desc, static_ltree, and static_tree_desc_s::static_tree.

Referenced by _tr_init().

## Variable Documentation

## ◆ bl_order

const uch bl_order[BL_CODES] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}

Definition at line 71 of file trees.c.

Referenced by build_bl_tree(), and send_all_trees().

## ◆ extra_blbits

const int extra_blbits[BL_CODES] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}

Definition at line 68 of file trees.c.

Referenced by tr_static_init().

## ◆ extra_dbits

const int extra_dbits[D_CODES] = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}

Definition at line 65 of file trees.c.

Referenced by compress_block(), and tr_static_init().

## ◆ extra_lbits

const int extra_lbits[LENGTH_CODES] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}

Definition at line 62 of file trees.c.

Referenced by compress_block(), and tr_static_init().

## ◆ static_bl_desc

const static_tree_desc static_bl_desc

Initial value:
=
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}
BL_CODES
#define BL_CODES
Definition: deflate.h:42
ct_data_s
Definition: deflate.h:68
extra_blbits
const int extra_blbits[BL_CODES]
Definition: trees.c:69
MAX_BL_BITS
#define MAX_BL_BITS
Definition: trees.c:47

Definition at line 131 of file trees.c.

Referenced by _tr_init(), and tr_static_init().

## ◆ static_d_desc

const static_tree_desc static_d_desc

Initial value:
=
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}
MAX_BITS
#define MAX_BITS
Definition: deflate.h:48
D_CODES
#define D_CODES
Definition: deflate.h:39
extra_dbits
const int extra_dbits[D_CODES]
Definition: trees.c:66
static_dtree
const ct_data static_dtree[D_CODES]
Definition: trees.h:64

Definition at line 128 of file trees.c.

Referenced by _tr_init(), and tr_static_init().

## ◆ static_l_desc

const static_tree_desc static_l_desc

Initial value:
=
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}
L_CODES
#define L_CODES
Definition: deflate.h:36
LITERALS
#define LITERALS
Definition: deflate.h:33
extra_lbits
const int extra_lbits[LENGTH_CODES]
Definition: trees.c:63
static_ltree
const ct_data static_ltree[L_CODES+2]
Definition: trees.h:3

Definition at line 125 of file trees.c.

Referenced by _tr_init(), and tr_static_init().