1unit bzip2comn; 2 3interface 4 5const 6 max_groups = 6; 7 max_alpha_size = 258; 8 max_code_len = 23; 9 group_size = 50; 10 iter_count = 4; 11 max_selectors = 2+(900000 div group_size); 12 13 mtfa_size = 4096; 14 mtfl_size = 16; 15 16type 17 TCardinal_array = array [0..899999] of Cardinal; 18 PCardinal_array = ^TCardinal_array; 19 20 PCardinal = ^Cardinal; 21 Thuffarray = array[0..max_alpha_size] of Cardinal; 22 Phuffarray = ^Thuffarray; 23 24{A bzip2 stream starts with this:} 25const bzip2_stream_magic='BZh'; 26 27{Error codes for stream errorinfo.} 28const 29 bzip2_bad_header_magic = 1; 30 bzip2_bad_block_magic = 2; 31 bzip2_endoffile = 3; 32 bzip2_data_error = 4; 33 34procedure hb_create_decode_tables(var limit,base,perm:array of cardinal; 35 var length:array of byte; 36 minlen,maxlen:byte;alphasize:cardinal); 37 38 39implementation 40 41procedure hb_create_decode_tables(var limit,base,perm:array of cardinal; 42 var length:array of byte; 43 minlen,maxlen:byte;alphasize:cardinal); 44 45var pp,i,j,vec:cardinal; 46 47begin 48 pp:=0; 49 for i:=minlen to maxlen do 50 for j:=0 to alphasize-1 do 51 if length[j]=i then 52 begin 53 perm[pp]:=j; 54 inc(pp); 55 end; 56 for i:=0 to max_code_len-1 do 57 begin 58 base[i]:=0; 59 limit[i]:=0; 60 end; 61 for i:=0 to alphasize-1 do 62 inc(base[length[i]+1]); 63 for i:=1 to max_code_len-1 do 64 inc(base[i],base[i-1]); 65 vec:=0; 66 for i:=minlen to maxlen do 67 begin 68 inc(vec,base[i+1]-base[i]); 69 limit[i]:=vec-1; 70 vec:=vec shl 1; 71 end; 72 for i:=minlen+1 to maxlen do 73 base[i]:=((limit[i-1]+1) shl 1)-base[i]; 74end; 75 76end.