text stringlengths 0 234 |
|---|
Optimal_Format_Bits := |
Count_Type'Min |
(Count_Type'Min (Stored_Format_Bits, Fixed_Format_Bits), |
Count_Type'Min |
(Count_Type'Min (Dynamic_Format_Bits, Dynamic_Format_Bits_2), |
Recycled_Format_Bits)); |
-- Selection of the block format with smallest size |
if Fixed_Format_Bits = Optimal_Format_Bits then |
Send_Fixed_Block; |
elsif Dynamic_Format_Bits = Optimal_Format_Bits then |
Send_Dynamic_Block (New_Descr); |
elsif Dynamic_Format_Bits_2 = Optimal_Format_Bits then |
Send_Dynamic_Block (New_Descr_2); |
elsif Recycled_Format_Bits = Optimal_Format_Bits then |
Put_Lz_Buffer (Lzb); |
else -- We have stored_format_bits = optimal_format_bits |
Expand_Lz_Buffer (Lzb, Last_Block); |
end if; |
end Send_As_Block; |
subtype Full_Range_Lz_Buffer_Type is Lz_Buffer_Type (Lz_Buffer_Index_Type); |
type P_Full_Range_Lz_Buffer_Type is access Full_Range_Lz_Buffer_Type; |
procedure Dispose is new Ada.Unchecked_Deallocation |
(Full_Range_Lz_Buffer_Type, |
P_Full_Range_Lz_Buffer_Type); |
-- This is the main, big, fat, circular buffer containing LZ codes, |
-- each LZ code being a literal or a DL code. |
-- Heap allocation is needed because default stack is too small on some targets. |
Lz_Buffer : P_Full_Range_Lz_Buffer_Type; |
Lz_Buffer_Index : Lz_Buffer_Index_Type := 0; |
Past_Lz_Data : Boolean := False; |
-- When True: some LZ_buffer_size data before lz_buffer_index (modulo!) are real, past data |
--------------------------------------------------------------------------------- |
-- Scanning and sampling: the really sexy part of the Taillaule algorithm... -- |
--------------------------------------------------------------------------------- |
-- We examine similarities in the LZ data flow at different step sizes. |
-- If the optimal Huffman encoding for this portion is very different, we choose to |
-- cut current block and start a new one. The shorter the step, the higher the threshold |
-- for starting a dynamic block, since the compression header is taking some room each time. |
-- *Tuned* (a bit...) |
Min_Step : constant := 750; |
type Step_Threshold_Metric is record |
Slider_Step : Lz_Buffer_Index_Type; -- Should be a multiple of Min_Step |
Cutting_Threshold : Positive; |
Metric : Distance_Type; |
end record; |
-- *Tuned* thresholds |
-- NB: the enwik8, then silesia, then others tests are tough for lowering any! |
Step_Choice : constant array (Positive range <>) of Step_Threshold_Metric := |
((8 * Min_Step, 420, L1_Tweaked), -- Deflate_1, Deflate_2, Deflate_3 (enwik8) |
(4 * Min_Step, 430, L1_Tweaked), -- Deflate_2, Deflate_3 (silesia) |
(Min_Step, 2050, L1_Tweaked)); -- Deflate_3 (DB test) |
Max_Choice : constant array (Taillaule_Deflation_Method) of Positive := |
(Deflate_1 => 1, |
Deflate_2 => 2, |
Deflate_3 => Step_Choice'Last); |
Slider_Size : constant := 4096; |
Half_Slider_Size : constant := Slider_Size / 2; |
Slider_Max : constant := Slider_Size - 1; |
-- Phases (A) and (B) are done in a single function: we get Huffman |
-- descriptors that should be good for encoding a given sequence of LZ atoms. |
function Build_Descriptors (Lzb : Lz_Buffer_Type) return Deflate_Huff_Descriptors is |
Stats_Lit_Len : Stats_Lit_Len_Type; |
Stats_Dis : Stats_Dis_Type; |
begin |
Get_Statistics (Lzb, Stats_Lit_Len, Stats_Dis); |
return Build_Descriptors (Stats_Lit_Len, Stats_Dis); |
end Build_Descriptors; |
procedure Scan_And_Send_From_Main_Buffer |
(From, To : Lz_Buffer_Index_Type; |
Last_Flush : Boolean) |
is |
-- The following descriptors are *not* used for compressing, but for detecting similarities. |
Initial_Hd, Sliding_Hd : Deflate_Huff_Descriptors; |
Start, Slide_Mid, Send_From : Lz_Buffer_Index_Type; |
Sliding_Hd_Computed : Boolean; |
begin |
if To - From < Slider_Max then |
Send_As_Block (Lz_Buffer (From .. To), Last_Flush); |
return; |
end if; |
-- For further comments: n := LZ_buffer_size |
if Past_Lz_Data then -- We have n / 2 previous data before 'from'. |
Start := From - Lz_Buffer_Index_Type (Half_Slider_Size); |
else |
Start := From; -- Cannot have past data |
end if; |
-- Looped over, (mod n). Slider data are in two chunks in main buffer |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.