Unit trees

Classes

Functions

_tr_align - =========================================================================== Send one empty static block to give enough lookahead for inflate.
_tr_flush_block - =========================================================================== Determine the best encoding for the current block: dynamic trees, static trees or store, and output the encoded block to the zip file.
_tr_init - Insert new strings in the hash table only if the match length is not greater than this length.
_tr_stored_block - =========================================================================== Send a stored block
_tr_tally - =========================================================================== Save the match info and tally the frequency counts.

Types

ct_data
ct_data_ptr
deflate_state
deflate_state_ptr
dtree_ptr
dtree_type
htree_ptr
htree_type
IPos
ltree_ptr
ltree_type
Pos
Posf
pPosf
pzPosfArray
static_tree_desc
static_tree_desc_ptr
tree_desc
tree_desc_ptr
tree_ptr
tree_type
zPosfArray

Constants

BL_CODES
BUSY_STATE
D_CODES
FINISH_STATE
HEAP_SIZE
INIT_STATE
LENGTH_CODES
LITERALS
L_CODES
MAX_BITS

Variables


Functions


procedure _tr_align(var s : deflate_state);

=========================================================================== Send one empty static block to give enough lookahead for inflate. This takes 10 bits, of which 7 may remain in the bit buffer. The current inflate code requires 9 bits of lookahead. If the last two codes for the previous block (real code plus EOB) were coded on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode the last real code. In this case we send two empty static blocks instead of one. (There are no problems if the previous block is stored or fixed.) To simplify the code, we assume the worst case of last real code encoded on one bit only.

function _tr_flush_block (var s : deflate_state; buf : pcharf; stored_len : ulg; eof : boolean) : ulg;

=========================================================================== Determine the best encoding for the current block: dynamic trees, static trees or store, and output the encoded block to the zip file. This function returns the total compressed length for the file so far.

procedure _tr_init (var s : deflate_state);

Insert new strings in the hash table only if the match length is not greater than this length. This saves time but degrades compression. max_insert_length is used only for compression levels <= 3.

Index within the heap array of least frequent node in the Huffman tree } { =========================================================================== Initialize the tree data structures for a new zlib stream.


procedure _tr_stored_block(var s : deflate_state; buf : pcharf; stored_len : ulg; eof : boolean);

=========================================================================== Send a stored block

function _tr_tally (var s : deflate_state; dist : unsigned; lc : unsigned) : boolean;

=========================================================================== Save the match info and tally the frequency counts. Return true if the current block must be flushed.

Types


ct_data = record
end;

ct_data_ptr = ^ct_data
Stream status } { Data structure describing a single value and its code string.
deflate_state = record
strm : z_streamp;
status : int;
pending_buf : pzByteArray;
pending_buf_size : ulg;
pending_out : pBytef;
pending : int;
noheader : int;
data_type : Byte;
method : Byte;
last_flush : int;
w_size : uInt;
w_bits : uInt;
w_mask : uInt;
window : pzByteArray;
window_size : ulg;
prev : pzPosfArray;
head : pzPosfArray;
ins_h : uInt;
hash_size : uInt;
hash_bits : uInt;
hash_mask : uInt;
hash_shift : uInt;
block_start : long;
match_length : uInt;
prev_match : IPos;
match_available : boolean;
strstart : uInt;
match_start : uInt;
lookahead : uInt;
prev_length : uInt;
max_chain_length : uInt;
level : int;
strategy : int;
good_match : uInt;
nice_match : int;
dyn_ltree : ltree_type;
dyn_dtree : dtree_type;
bl_tree : htree_type;
l_desc : tree_desc;
d_desc : tree_desc;
bl_desc : tree_desc;
bl_count : array[0..MAX_BITS+1-1] of ush;
heap : array[0..2*L_CODES+1-1] of int;
heap_len : int;
heap_max : int;
depth : array[0..2*L_CODES+1-1] of uch;
l_buf : puchfArray;
lit_bufsize : uInt;
last_lit : uInt;
d_buf : pushfArray;
opt_len : ulg;
static_len : ulg;
compressed_len : ulg;
matches : uInt;
last_eob_len : int;
bi_buf : ush;
bi_valid : int;
end;

deflate_state_ptr = ^deflate_state
A Pos is an index in the character window. We use short instead of int to save space in the various tables. IPos is used only for parameter passing.
dtree_ptr = ^dtree_type

dtree_type = array[0..2*D_CODES+1-1] of ct_data;
literal and length tree
htree_ptr = ^htree_type

htree_type = array[0..2*BL_CODES+1-1] of ct_data;
distance tree
IPos = uInt
FAR
ltree_ptr = ^ltree_type

ltree_type = array[0..HEAP_SIZE-1] of ct_data;
Freq = fc.freq Code = fc.code Dad = dl.dad Len = dl.len
Pos = ush
the corresponding static tree
Posf = Pos

pPosf = ^Posf

pzPosfArray = ^zPosfArray

static_tree_desc = record
static_tree : tree_ptr;
extra_bits : pzIntfArray;
extra_base : int;
elems : int;
max_length : int;
end;

static_tree_desc_ptr = ^static_tree_desc

tree_desc = record
dyn_tree : tree_ptr;
max_code : int;
stat_desc : static_tree_desc_ptr;
end;

tree_desc_ptr = ^tree_desc
max bit length for the codes
tree_ptr = ^tree_type

tree_type = array[0..(MaxInt div SizeOf(ct_data))-1] of ct_data;
Huffman tree for bit lengths } { generic tree type
zPosfArray = array[0..(MaxInt div SizeOf(Posf))-1] of Posf;

Constants

BL_CODES = 19

number of distance codes

BUSY_STATE = 113

D_CODES = 30

number of Literal or Length codes, including the END_BLOCK code

FINISH_STATE = 666

HEAP_SIZE = (2*L_CODES+1)

number of codes used to transfer the bit lengths

INIT_STATE = 42

All codes must not exceed MAX_BITS bits

LENGTH_CODES = 29

=========================================================================== Internal compression state.

LITERALS = 256

number of length codes, not counting the special END_BLOCK code

L_CODES = (LITERALS+1+LENGTH_CODES)

number of literal bytes 0..255

MAX_BITS = 15

maximum heap size

Variables